diff --git a/CHANGELOG.md b/CHANGELOG.md index 03400d46..6a932eda 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ This release marked heavy refactorings on internal code structure with the creat ### Bugfixes - Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170 +- Documentation : Error in a fonction - @theBeerNut GH-195 ### Deprecated @@ -63,6 +64,7 @@ This release marked heavy refactorings on internal code structure with the creat - Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187 - Writer: New 'ODText\Base` class - @ivanlanin GH-187 - General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin +- General: Add some unit tests for Shared & Element (100%!) - @Progi1984 ## 0.9.1 - 27 Mar 2014 diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php index d8519aca..21d13cfe 100644 --- a/src/PhpWord/Shared/ZipArchive.php +++ b/src/PhpWord/Shared/ZipArchive.php @@ -218,8 +218,7 @@ class ZipArchive public function getNameIndex($index) { $list = $this->zip->listContent(); - $listCount = count($list); - if ($index <= $listCount) { + if (isset($list[$index])) { return $list[$index]['filename']; } else { return false; diff --git a/tests/PhpWord/Tests/Element/AbstractElementTest.php b/tests/PhpWord/Tests/Element/AbstractElementTest.php new file mode 100644 index 00000000..786248d5 --- /dev/null +++ b/tests/PhpWord/Tests/Element/AbstractElementTest.php @@ -0,0 +1,30 @@ +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); + } +} diff --git a/tests/PhpWord/Tests/Element/ImageTest.php b/tests/PhpWord/Tests/Element/ImageTest.php index 5b9aaa45..3520c376 100644 --- a/tests/PhpWord/Tests/Element/ImageTest.php +++ b/tests/PhpWord/Tests/Element/ImageTest.php @@ -94,6 +94,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); } + public function testStyleWrappingStyle() + { + + } + /** * Get relation Id */ @@ -202,4 +207,14 @@ class ImageTest extends \PHPUnit_Framework_TestCase { $object = new Image('test.php'); } + + /** + * Test PCX Image and Memory + * + * @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException + */ + public function testPcxImage() + { + $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 0d3a74b9..53ec54be 100644 --- a/tests/PhpWord/Tests/Element/TableTest.php +++ b/tests/PhpWord/Tests/Element/TableTest.php @@ -84,9 +84,23 @@ 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); + } + + /** + * Add cell + */ + 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); } } diff --git a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php b/tests/PhpWord/Tests/Shared/ZipArchiveTest.php index ba47ade1..5094d5a1 100644 --- a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php +++ b/tests/PhpWord/Tests/Shared/ZipArchiveTest.php @@ -32,7 +32,38 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase $this->assertTrue($object->locateName('xls/new.xls')); $this->assertEquals('Test', $object->getFromName('content/string.txt')); + $this->assertEquals('Test', $object->getFromName('/content/string.txt')); unlink($zipFile); } + + 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'); + + $this->assertEquals(1, $object->locateName('content/string.txt')); + $this->assertFalse($object->locateName('blablabla')); + + unlink($zipFile); + } + + 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'); + + $this->assertFalse($object->getNameIndex(-1)); + $this->assertEquals('content/string.txt', $object->getNameIndex(1)); + + unlink($zipFile); + } }