Add some unit tests for Shared & Element (100%!) - @Progi1984

This commit is contained in:
Progi1984 2014-04-12 00:59:29 +02:00
parent 59e623bb75
commit b40218da45
6 changed files with 97 additions and 6 deletions

View File

@ -35,6 +35,7 @@ This release marked heavy refactorings on internal code structure with the creat
### Bugfixes ### Bugfixes
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170 - Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
- Documentation : Error in a fonction - @theBeerNut GH-195
### Deprecated ### 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 - Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
- Writer: New 'ODText\Base` 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: 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 ## 0.9.1 - 27 Mar 2014

View File

@ -218,8 +218,7 @@ class ZipArchive
public function getNameIndex($index) public function getNameIndex($index)
{ {
$list = $this->zip->listContent(); $list = $this->zip->listContent();
$listCount = count($list); if (isset($list[$index])) {
if ($index <= $listCount) {
return $list[$index]['filename']; return $list[$index]['filename'];
} else { } else {
return false; return false;

View File

@ -0,0 +1,30 @@
<?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\Element;
/**
* Test class for PhpOffice\PhpWord\Element\Cell
*
* @runTestsInSeparateProcesses
*/
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);
}
public function testElementId(){
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
$stub->setElementId();
$this->assertEquals(strlen($stub->getElementId()), 6);
}
}

View File

@ -94,6 +94,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
public function testStyleWrappingStyle()
{
}
/** /**
* Get relation Id * Get relation Id
*/ */
@ -202,4 +207,14 @@ class ImageTest extends \PHPUnit_Framework_TestCase
{ {
$object = new Image('test.php'); $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');
}
} }

View File

@ -84,9 +84,23 @@ class TableTest extends \PHPUnit_Framework_TestCase
*/ */
public function testCell() public function testCell()
{ {
$oTable = new Table('section', 1); $oTable = new Table('section', 1);
$oTable->addRow(); $oTable->addRow();
$element = $oTable->addCell(); $element = $oTable->addCell();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element); $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);
} }
} }

View File

@ -32,7 +32,38 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($object->locateName('xls/new.xls')); $this->assertTrue($object->locateName('xls/new.xls'));
$this->assertEquals('Test', $object->getFromName('content/string.txt')); $this->assertEquals('Test', $object->getFromName('content/string.txt'));
$this->assertEquals('Test', $object->getFromName('/content/string.txt'));
unlink($zipFile); 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);
}
} }