Code formatting and some more tests

This commit is contained in:
Ivan Lanin 2014-04-12 10:23:31 +07:00
parent b40218da45
commit 47956b019c
9 changed files with 124 additions and 51 deletions

View File

@ -128,7 +128,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
if ($zip->open($filename) === true) { if ($zip->open($filename) === true) {
for ($i = 0; $i < $zip->numFiles; $i++) { for ($i = 0; $i < $zip->numFiles; $i++) {
$xmlFile = $zip->getNameIndex($i); $xmlFile = $zip->getNameIndex($i);
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath) { if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath && (substr($xmlFile, -1)) != '/') {
$docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile)); $docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
$this->rels[$docPart] = $this->getRels($filename, $xmlFile, 'word/'); $this->rels[$docPart] = $this->getRels($filename, $xmlFile, 'word/');
} }

View File

@ -100,6 +100,8 @@ class ListItem extends AbstractStyle
/** /**
* Set numbering style name * Set numbering style name
*
* @param string $value
*/ */
public function setNumStyle($value) public function setNumStyle($value)
{ {

View File

@ -16,13 +16,21 @@ namespace PhpOffice\PhpWord\Tests\Element;
*/ */
class AbstractElementTest extends \PHPUnit_Framework_TestCase class AbstractElementTest extends \PHPUnit_Framework_TestCase
{ {
public function testElementIndex(){ /**
* Test set/get element index
*/
public function testElementIndex()
{
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
$ival = rand(0, 100); $ival = rand(0, 100);
$stub->setElementIndex($ival); $stub->setElementIndex($ival);
$this->assertEquals($stub->getElementIndex(), $ival); $this->assertEquals($stub->getElementIndex(), $ival);
} }
public function testElementId(){ /**
* Test set/get element unique Id
*/
public function testElementId()
{
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
$stub->setElementId(); $stub->setElementId();
$this->assertEquals(strlen($stub->getElementId()), 6); $this->assertEquals(strlen($stub->getElementId()), 6);

View File

@ -94,6 +94,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
/**
* Test set wrapping style
*/
public function testStyleWrappingStyle() public function testStyleWrappingStyle()
{ {

View File

@ -48,11 +48,11 @@ class TableTest extends \PHPUnit_Framework_TestCase
*/ */
public function testStyleArray() public function testStyleArray()
{ {
$oTable = new Table( $oTable = new Table('section', 1, array(
'section', 'borderSize' => 6,
1, 'borderColor' => '006699',
array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80) 'cellMargin' => 80
); ));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle());
} }

View File

@ -0,0 +1,54 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Tests\Shared;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Test class for PhpOffice\PhpWord\Shared\XMLReader
*
* @runTestsInSeparateProcesses
* @since 0.10.0
*/
class XMLReaderTest extends \PHPUnit_Framework_TestCase
{
/**
* Test get DOMDocument from ZipArchive returns false
*/
public function testGetDomFromZipReturnsFalse()
{
$filename = __DIR__ . "/../_files/documents/reader.docx.zip";
$object = new XMLReader();
$this->assertFalse($object->getDomFromZip($filename, 'yadayadaya'));
}
/**
* Test get elements returns empty
*/
public function testGetElementsReturnsEmpty()
{
$object = new XMLReader();
$this->assertEquals(array(), $object->getElements('w:document'));
}
/**
* Test get element returns null
*/
public function testGetElementReturnsNull()
{
$filename = __DIR__ . "/../_files/documents/reader.docx.zip";
$object = new XMLReader();
$object->getDomFromZip($filename, '[Content_Types].xml');
$element = $object->getElements('*')->item(0);
$this->assertNull($object->getElement('yadayadaya', $element));
}
}

View File

@ -37,6 +37,9 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase
unlink($zipFile); unlink($zipFile);
} }
/**
* Test find if a given name exists in the archive
*/
public function testLocate() public function testLocate()
{ {
$existingFile = __DIR__ . "/../_files/documents/sheet.xls"; $existingFile = __DIR__ . "/../_files/documents/sheet.xls";
@ -52,6 +55,9 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase
unlink($zipFile); unlink($zipFile);
} }
/**
* Test returns the name of an entry using its index
*/
public function testNameIndex() public function testNameIndex()
{ {
$existingFile = __DIR__ . "/../_files/documents/sheet.xls"; $existingFile = __DIR__ . "/../_files/documents/sheet.xls";

View File

@ -32,7 +32,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
'align' => 'left', 'align' => 'left',
'marginTop' => 240, 'marginTop' => 240,
'marginLeft' => 240, 'marginLeft' => 240,
'wrappingStyle' => 'inline', 'wrappingStyle' => 'inline'
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
$set = "set{$key}"; $set = "set{$key}";
@ -54,7 +54,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
'height' => 200, 'height' => 200,
'align' => 'left', 'align' => 'left',
'marginTop' => 240, 'marginTop' => 240,
'marginLeft' => 240, 'marginLeft' => 240
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
$get = "get{$key}"; $get = "get{$key}";