diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index 5901046c..9d74e540 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -128,7 +128,7 @@ class Word2007 extends AbstractReader implements ReaderInterface if ($zip->open($filename) === true) { for ($i = 0; $i < $zip->numFiles; $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)); $this->rels[$docPart] = $this->getRels($filename, $xmlFile, 'word/'); } diff --git a/src/PhpWord/Style/ListItem.php b/src/PhpWord/Style/ListItem.php index 3c762920..a4f4933d 100644 --- a/src/PhpWord/Style/ListItem.php +++ b/src/PhpWord/Style/ListItem.php @@ -100,6 +100,8 @@ class ListItem extends AbstractStyle /** * Set numbering style name + * + * @param string $value */ public function setNumStyle($value) { diff --git a/tests/PhpWord/Tests/Element/AbstractElementTest.php b/tests/PhpWord/Tests/Element/AbstractElementTest.php index 786248d5..81080232 100644 --- a/tests/PhpWord/Tests/Element/AbstractElementTest.php +++ b/tests/PhpWord/Tests/Element/AbstractElementTest.php @@ -16,15 +16,23 @@ namespace PhpOffice\PhpWord\Tests\Element; */ class AbstractElementTest extends \PHPUnit_Framework_TestCase { - public function testElementIndex(){ - $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); - $ival = rand(0, 100); - $stub->setElementIndex($ival); - $this->assertEquals($stub->getElementIndex(), $ival); + /** + * Test set/get element index + */ + public function testElementIndex() + { + $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); + $ival = rand(0, 100); + $stub->setElementIndex($ival); + $this->assertEquals($stub->getElementIndex(), $ival); } - public function testElementId(){ - $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); - $stub->setElementId(); - $this->assertEquals(strlen($stub->getElementId()), 6); + /** + * Test set/get element unique Id + */ + public function testElementId() + { + $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); + $stub->setElementId(); + $this->assertEquals(strlen($stub->getElementId()), 6); } } diff --git a/tests/PhpWord/Tests/Element/ImageTest.php b/tests/PhpWord/Tests/Element/ImageTest.php index 3520c376..6ec6743a 100644 --- a/tests/PhpWord/Tests/Element/ImageTest.php +++ b/tests/PhpWord/Tests/Element/ImageTest.php @@ -94,6 +94,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); } + /** + * Test set wrapping style + */ public function testStyleWrappingStyle() { @@ -215,6 +218,6 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testPcxImage() { - $object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP'); + $object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP'); } } diff --git a/tests/PhpWord/Tests/Element/TableTest.php b/tests/PhpWord/Tests/Element/TableTest.php index 53ec54be..3fc51f98 100644 --- a/tests/PhpWord/Tests/Element/TableTest.php +++ b/tests/PhpWord/Tests/Element/TableTest.php @@ -48,11 +48,11 @@ class TableTest extends \PHPUnit_Framework_TestCase */ public function testStyleArray() { - $oTable = new Table( - 'section', - 1, - array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80) - ); + $oTable = new Table('section', 1, array( + 'borderSize' => 6, + 'borderColor' => '006699', + 'cellMargin' => 80 + )); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle()); } @@ -63,7 +63,7 @@ class TableTest extends \PHPUnit_Framework_TestCase public function testWidth() { $oTable = new Table('section', 1); - $iVal = rand(1, 1000); + $iVal = rand(1, 1000); $oTable->setWidth($iVal); $this->assertEquals($oTable->getWidth(), $iVal); } @@ -73,7 +73,7 @@ class TableTest extends \PHPUnit_Framework_TestCase */ public function testRow() { - $oTable = new Table('section', 1); + $oTable = new Table('section', 1); $element = $oTable->addRow(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element); $this->assertCount(1, $oTable->getRows()); @@ -84,10 +84,10 @@ class TableTest extends \PHPUnit_Framework_TestCase */ public function testCell() { - $oTable = new Table('section', 1); - $oTable->addRow(); - $element = $oTable->addCell(); - $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element); + $oTable = new Table('section', 1); + $oTable->addRow(); + $element = $oTable->addCell(); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element); } /** @@ -95,12 +95,12 @@ class TableTest extends \PHPUnit_Framework_TestCase */ public function testCountColumns() { - $oTable = new Table('section', 1); - $oTable->addRow(); - $element = $oTable->addCell(); - $this->assertEquals($oTable->countColumns(), 1); - $element = $oTable->addCell(); - $element = $oTable->addCell(); - $this->assertEquals($oTable->countColumns(), 3); + $oTable = new Table('section', 1); + $oTable->addRow(); + $element = $oTable->addCell(); + $this->assertEquals($oTable->countColumns(), 1); + $element = $oTable->addCell(); + $element = $oTable->addCell(); + $this->assertEquals($oTable->countColumns(), 3); } } diff --git a/tests/PhpWord/Tests/Shared/XMLReaderTest.php b/tests/PhpWord/Tests/Shared/XMLReaderTest.php new file mode 100644 index 00000000..759bf580 --- /dev/null +++ b/tests/PhpWord/Tests/Shared/XMLReaderTest.php @@ -0,0 +1,54 @@ +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)); + } +} diff --git a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php b/tests/PhpWord/Tests/Shared/ZipArchiveTest.php index 5094d5a1..40bdde68 100644 --- a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php +++ b/tests/PhpWord/Tests/Shared/ZipArchiveTest.php @@ -24,8 +24,8 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase public function testAdd() { $existingFile = __DIR__ . "/../_files/documents/sheet.xls"; - $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; - $object = new ZipArchive(); + $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; + $object = new ZipArchive(); $object->open($zipFile); $object->addFile($existingFile, 'xls/new.xls'); $object->addFromString('content/string.txt', 'Test'); @@ -37,33 +37,39 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase unlink($zipFile); } + /** + * Test find if a given name exists in the archive + */ public function testLocate() { - $existingFile = __DIR__ . "/../_files/documents/sheet.xls"; - $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; - $object = new ZipArchive(); - $object->open($zipFile); - $object->addFile($existingFile, 'xls/new.xls'); - $object->addFromString('content/string.txt', 'Test'); + $existingFile = __DIR__ . "/../_files/documents/sheet.xls"; + $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; + $object = new ZipArchive(); + $object->open($zipFile); + $object->addFile($existingFile, 'xls/new.xls'); + $object->addFromString('content/string.txt', 'Test'); - $this->assertEquals(1, $object->locateName('content/string.txt')); - $this->assertFalse($object->locateName('blablabla')); + $this->assertEquals(1, $object->locateName('content/string.txt')); + $this->assertFalse($object->locateName('blablabla')); - unlink($zipFile); + unlink($zipFile); } + /** + * Test returns the name of an entry using its index + */ public function testNameIndex() { - $existingFile = __DIR__ . "/../_files/documents/sheet.xls"; - $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; - $object = new ZipArchive(); - $object->open($zipFile); - $object->addFile($existingFile, 'xls/new.xls'); - $object->addFromString('content/string.txt', 'Test'); + $existingFile = __DIR__ . "/../_files/documents/sheet.xls"; + $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; + $object = new ZipArchive(); + $object->open($zipFile); + $object->addFile($existingFile, 'xls/new.xls'); + $object->addFromString('content/string.txt', 'Test'); - $this->assertFalse($object->getNameIndex(-1)); - $this->assertEquals('content/string.txt', $object->getNameIndex(1)); + $this->assertFalse($object->getNameIndex(-1)); + $this->assertEquals('content/string.txt', $object->getNameIndex(1)); - unlink($zipFile); + unlink($zipFile); } } diff --git a/tests/PhpWord/Tests/Style/ImageTest.php b/tests/PhpWord/Tests/Style/ImageTest.php index b35c8cb2..fd74d73c 100644 --- a/tests/PhpWord/Tests/Style/ImageTest.php +++ b/tests/PhpWord/Tests/Style/ImageTest.php @@ -32,7 +32,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase 'align' => 'left', 'marginTop' => 240, 'marginLeft' => 240, - 'wrappingStyle' => 'inline', + 'wrappingStyle' => 'inline' ); foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -54,7 +54,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase 'height' => 200, 'align' => 'left', 'marginTop' => 240, - 'marginLeft' => 240, + 'marginLeft' => 240 ); foreach ($properties as $key => $value) { $get = "get{$key}"; diff --git a/tests/PhpWord/Tests/_files/documents/reader.docx b/tests/PhpWord/Tests/_files/documents/reader.docx index 2143c628..5f37ef4b 100644 Binary files a/tests/PhpWord/Tests/_files/documents/reader.docx and b/tests/PhpWord/Tests/_files/documents/reader.docx differ