Code formatting and some more tests
This commit is contained in:
parent
b40218da45
commit
47956b019c
@ -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/');
|
||||
}
|
||||
|
||||
@ -100,6 +100,8 @@ class ListItem extends AbstractStyle
|
||||
|
||||
/**
|
||||
* Set numbering style name
|
||||
*
|
||||
* @param string $value
|
||||
*/
|
||||
public function setNumStyle($value)
|
||||
{
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
54
tests/PhpWord/Tests/Shared/XMLReaderTest.php
Normal file
54
tests/PhpWord/Tests/Shared/XMLReaderTest.php
Normal 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));
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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}";
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user