Skip to content

Commit 47956b0

Browse files
committed
Code formatting and some more tests
1 parent b40218d commit 47956b0

File tree

9 files changed

+124
-51
lines changed

9 files changed

+124
-51
lines changed

src/PhpWord/Reader/Word2007.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function readRelationships($filename)
128128
if ($zip->open($filename) === true) {
129129
for ($i = 0; $i < $zip->numFiles; $i++) {
130130
$xmlFile = $zip->getNameIndex($i);
131-
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath) {
131+
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath && (substr($xmlFile, -1)) != '/') {
132132
$docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
133133
$this->rels[$docPart] = $this->getRels($filename, $xmlFile, 'word/');
134134
}

src/PhpWord/Style/ListItem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public function getNumStyle()
100100

101101
/**
102102
* Set numbering style name
103+
*
104+
* @param string $value
103105
*/
104106
public function setNumStyle($value)
105107
{

tests/PhpWord/Tests/Element/AbstractElementTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@
1616
*/
1717
class AbstractElementTest extends \PHPUnit_Framework_TestCase
1818
{
19-
public function testElementIndex(){
20-
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
21-
$ival = rand(0, 100);
22-
$stub->setElementIndex($ival);
23-
$this->assertEquals($stub->getElementIndex(), $ival);
19+
/**
20+
* Test set/get element index
21+
*/
22+
public function testElementIndex()
23+
{
24+
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
25+
$ival = rand(0, 100);
26+
$stub->setElementIndex($ival);
27+
$this->assertEquals($stub->getElementIndex(), $ival);
2428
}
25-
public function testElementId(){
26-
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
27-
$stub->setElementId();
28-
$this->assertEquals(strlen($stub->getElementId()), 6);
29+
/**
30+
* Test set/get element unique Id
31+
*/
32+
public function testElementId()
33+
{
34+
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
35+
$stub->setElementId();
36+
$this->assertEquals(strlen($stub->getElementId()), 6);
2937
}
3038
}

tests/PhpWord/Tests/Element/ImageTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public function testStyle()
9494
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
9595
}
9696

97+
/**
98+
* Test set wrapping style
99+
*/
97100
public function testStyleWrappingStyle()
98101
{
99102

@@ -215,6 +218,6 @@ public function testPhpImage()
215218
*/
216219
public function testPcxImage()
217220
{
218-
$object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP');
221+
$object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP');
219222
}
220223
}

tests/PhpWord/Tests/Element/TableTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public function testStyleText()
4848
*/
4949
public function testStyleArray()
5050
{
51-
$oTable = new Table(
52-
'section',
53-
1,
54-
array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)
55-
);
51+
$oTable = new Table('section', 1, array(
52+
'borderSize' => 6,
53+
'borderColor' => '006699',
54+
'cellMargin' => 80
55+
));
5656

5757
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle());
5858
}
@@ -63,7 +63,7 @@ public function testStyleArray()
6363
public function testWidth()
6464
{
6565
$oTable = new Table('section', 1);
66-
$iVal = rand(1, 1000);
66+
$iVal = rand(1, 1000);
6767
$oTable->setWidth($iVal);
6868
$this->assertEquals($oTable->getWidth(), $iVal);
6969
}
@@ -73,7 +73,7 @@ public function testWidth()
7373
*/
7474
public function testRow()
7575
{
76-
$oTable = new Table('section', 1);
76+
$oTable = new Table('section', 1);
7777
$element = $oTable->addRow();
7878
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element);
7979
$this->assertCount(1, $oTable->getRows());
@@ -84,23 +84,23 @@ public function testRow()
8484
*/
8585
public function testCell()
8686
{
87-
$oTable = new Table('section', 1);
88-
$oTable->addRow();
89-
$element = $oTable->addCell();
90-
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element);
87+
$oTable = new Table('section', 1);
88+
$oTable->addRow();
89+
$element = $oTable->addCell();
90+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element);
9191
}
9292

9393
/**
9494
* Add cell
9595
*/
9696
public function testCountColumns()
9797
{
98-
$oTable = new Table('section', 1);
99-
$oTable->addRow();
100-
$element = $oTable->addCell();
101-
$this->assertEquals($oTable->countColumns(), 1);
102-
$element = $oTable->addCell();
103-
$element = $oTable->addCell();
104-
$this->assertEquals($oTable->countColumns(), 3);
98+
$oTable = new Table('section', 1);
99+
$oTable->addRow();
100+
$element = $oTable->addCell();
101+
$this->assertEquals($oTable->countColumns(), 1);
102+
$element = $oTable->addCell();
103+
$element = $oTable->addCell();
104+
$this->assertEquals($oTable->countColumns(), 3);
105105
}
106106
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* PHPWord
4+
*
5+
* @link https://github.com/PHPOffice/PHPWord
6+
* @copyright 2014 PHPWord
7+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
8+
*/
9+
10+
namespace PhpOffice\PhpWord\Tests\Shared;
11+
12+
use PhpOffice\PhpWord\Shared\XMLReader;
13+
14+
/**
15+
* Test class for PhpOffice\PhpWord\Shared\XMLReader
16+
*
17+
* @runTestsInSeparateProcesses
18+
* @since 0.10.0
19+
*/
20+
class XMLReaderTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* Test get DOMDocument from ZipArchive returns false
24+
*/
25+
public function testGetDomFromZipReturnsFalse()
26+
{
27+
$filename = __DIR__ . "/../_files/documents/reader.docx.zip";
28+
$object = new XMLReader();
29+
$this->assertFalse($object->getDomFromZip($filename, 'yadayadaya'));
30+
}
31+
32+
/**
33+
* Test get elements returns empty
34+
*/
35+
public function testGetElementsReturnsEmpty()
36+
{
37+
$object = new XMLReader();
38+
$this->assertEquals(array(), $object->getElements('w:document'));
39+
}
40+
41+
/**
42+
* Test get element returns null
43+
*/
44+
public function testGetElementReturnsNull()
45+
{
46+
$filename = __DIR__ . "/../_files/documents/reader.docx.zip";
47+
48+
$object = new XMLReader();
49+
$object->getDomFromZip($filename, '[Content_Types].xml');
50+
$element = $object->getElements('*')->item(0);
51+
52+
$this->assertNull($object->getElement('yadayadaya', $element));
53+
}
54+
}

tests/PhpWord/Tests/Shared/ZipArchiveTest.php

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase
2424
public function testAdd()
2525
{
2626
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
27-
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
28-
$object = new ZipArchive();
27+
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
28+
$object = new ZipArchive();
2929
$object->open($zipFile);
3030
$object->addFile($existingFile, 'xls/new.xls');
3131
$object->addFromString('content/string.txt', 'Test');
@@ -37,33 +37,39 @@ public function testAdd()
3737
unlink($zipFile);
3838
}
3939

40+
/**
41+
* Test find if a given name exists in the archive
42+
*/
4043
public function testLocate()
4144
{
42-
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
43-
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
44-
$object = new ZipArchive();
45-
$object->open($zipFile);
46-
$object->addFile($existingFile, 'xls/new.xls');
47-
$object->addFromString('content/string.txt', 'Test');
45+
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
46+
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
47+
$object = new ZipArchive();
48+
$object->open($zipFile);
49+
$object->addFile($existingFile, 'xls/new.xls');
50+
$object->addFromString('content/string.txt', 'Test');
4851

49-
$this->assertEquals(1, $object->locateName('content/string.txt'));
50-
$this->assertFalse($object->locateName('blablabla'));
52+
$this->assertEquals(1, $object->locateName('content/string.txt'));
53+
$this->assertFalse($object->locateName('blablabla'));
5154

52-
unlink($zipFile);
55+
unlink($zipFile);
5356
}
5457

58+
/**
59+
* Test returns the name of an entry using its index
60+
*/
5561
public function testNameIndex()
5662
{
57-
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
58-
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
59-
$object = new ZipArchive();
60-
$object->open($zipFile);
61-
$object->addFile($existingFile, 'xls/new.xls');
62-
$object->addFromString('content/string.txt', 'Test');
63+
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
64+
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
65+
$object = new ZipArchive();
66+
$object->open($zipFile);
67+
$object->addFile($existingFile, 'xls/new.xls');
68+
$object->addFromString('content/string.txt', 'Test');
6369

64-
$this->assertFalse($object->getNameIndex(-1));
65-
$this->assertEquals('content/string.txt', $object->getNameIndex(1));
70+
$this->assertFalse($object->getNameIndex(-1));
71+
$this->assertEquals('content/string.txt', $object->getNameIndex(1));
6672

67-
unlink($zipFile);
73+
unlink($zipFile);
6874
}
6975
}

tests/PhpWord/Tests/Style/ImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testSetGetNormal()
3232
'align' => 'left',
3333
'marginTop' => 240,
3434
'marginLeft' => 240,
35-
'wrappingStyle' => 'inline',
35+
'wrappingStyle' => 'inline'
3636
);
3737
foreach ($properties as $key => $value) {
3838
$set = "set{$key}";
@@ -54,7 +54,7 @@ public function testSetStyleValue()
5454
'height' => 200,
5555
'align' => 'left',
5656
'marginTop' => 240,
57-
'marginLeft' => 240,
57+
'marginLeft' => 240
5858
);
5959
foreach ($properties as $key => $value) {
6060
$get = "get{$key}";
Binary file not shown.

0 commit comments

Comments
 (0)