Skip to content

Commit d75c00c

Browse files
committed
Fixed unit tests
1 parent 66c73c0 commit d75c00c

26 files changed

+92
-257
lines changed

test/PhpWord/Tests/MediaTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function testGetFooterMediaElements()
4242
public function testAddSectionMediaElement()
4343
{
4444
$section = new Section(0);
45-
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars_noext_jpg");
46-
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars.jpg");
47-
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mario.gif");
48-
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/firefox.png");
49-
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/duke_nukem.bmp");
50-
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/angela_merkel.tif");
45+
$section->addImage(__DIR__ . "/_files/images/mars_noext_jpg");
46+
$section->addImage(__DIR__ . "/_files/images/mars.jpg");
47+
$section->addImage(__DIR__ . "/_files/images/mario.gif");
48+
$section->addImage(__DIR__ . "/_files/images/firefox.png");
49+
$section->addImage(__DIR__ . "/_files/images/duke_nukem.bmp");
50+
$section->addImage(__DIR__ . "/_files/images/angela_merkel.tif");
5151

5252
$elements = $section->getElements();
5353
$this->assertEquals(6, count($elements));

test/PhpWord/Tests/PhpWordTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ public function testAddTitleStyle()
130130
*/
131131
public function testLoadTemplate()
132132
{
133-
$templateFqfn = \join(
134-
\DIRECTORY_SEPARATOR,
135-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'blank.docx')
136-
);
133+
$templateFqfn = __DIR__ . "/_files/templates/blank.docx";
134+
137135
$phpWord = new PhpWord();
138136
$this->assertInstanceOf(
139137
'PhpOffice\\PhpWord\\Template',

test/PhpWord/Tests/Reader/Word2007Test.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ public function tearDown()
1818
*/
1919
public function testCanRead()
2020
{
21-
$dir = join(
22-
\DIRECTORY_SEPARATOR,
23-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents')
24-
);
21+
$dir = __DIR__ . "/../_files/documents";
2522
$object = new Word2007;
2623
$file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx';
2724
$this->assertTrue($object->canRead($file));
@@ -32,10 +29,7 @@ public function testCanRead()
3229
*/
3330
public function testCanReadFailed()
3431
{
35-
$dir = join(
36-
\DIRECTORY_SEPARATOR,
37-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents')
38-
);
32+
$dir = __DIR__ . "/../_files/documents";
3933
$object = new Word2007;
4034
$file = $dir . \DIRECTORY_SEPARATOR . 'foo.docx';
4135
$this->assertFalse($object->canRead($file));
@@ -47,10 +41,7 @@ public function testCanReadFailed()
4741
*/
4842
public function testLoad()
4943
{
50-
$dir = join(
51-
\DIRECTORY_SEPARATOR,
52-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents')
53-
);
44+
$dir = __DIR__ . "/../_files/documents";
5445
$file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx';
5546
$object = IOFactory::load($file);
5647
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object);

test/PhpWord/Tests/Section/FooterTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function testAddText()
3030

3131
$this->assertCount(1, $oFooter->getElements());
3232
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
33-
3433
}
3534

3635
public function testAddTextNotUTF8()
@@ -72,10 +71,7 @@ public function testAddTable()
7271

7372
public function testAddImage()
7473
{
75-
$src = \join(
76-
\DIRECTORY_SEPARATOR,
77-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
78-
);
74+
$src = __DIR__ . "/../_files/images/earth.jpg";
7975
$oFooter = new Footer(1);
8076
$element = $oFooter->addImage($src);
8177

test/PhpWord/Tests/Section/HeaderTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ public function testAddTable()
6868

6969
public function testAddImage()
7070
{
71-
$src = \join(
72-
\DIRECTORY_SEPARATOR,
73-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
74-
);
71+
$src = __DIR__ . "/../_files/images/earth.jpg";
7572
$oHeader = new Header(1);
7673
$element = $oHeader->addImage($src);
7774

@@ -111,10 +108,7 @@ public function testAddPreserveTextNotUTF8()
111108

112109
public function testAddWatermark()
113110
{
114-
$src = \join(
115-
\DIRECTORY_SEPARATOR,
116-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
117-
);
111+
$src = __DIR__ . "/../_files/images/earth.jpg";
118112
$oHeader = new Header(1);
119113
$element = $oHeader->addWatermark($src);
120114

test/PhpWord/Tests/Section/ImageTest.php

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public function testConstruct()
1212
{
13-
$src = \join(
14-
\DIRECTORY_SEPARATOR,
15-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'firefox.png')
16-
);
13+
$src = __DIR__ . "/../_files/images/firefox.png";
1714
$oImage = new Image($src);
1815

1916
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
@@ -25,10 +22,7 @@ public function testConstruct()
2522

2623
public function testConstructWithStyle()
2724
{
28-
$src = \join(
29-
\DIRECTORY_SEPARATOR,
30-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'firefox.png')
31-
);
25+
$src = __DIR__ . "/../_files/images/firefox.png";
3226
$oImage = new Image(
3327
$src,
3428
array('width' => 210, 'height' => 210, 'align' => 'center',
@@ -43,12 +37,12 @@ public function testConstructWithStyle()
4337
*/
4438
public function testValidImageTypes()
4539
{
46-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars_noext_jpg");
47-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars.jpg");
48-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mario.gif");
49-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/firefox.png");
50-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/duke_nukem.bmp");
51-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/angela_merkel.tif");
40+
new Image(__DIR__ . "/../_files/images/mars_noext_jpg");
41+
new Image(__DIR__ . "/../_files/images/mars.jpg");
42+
new Image(__DIR__ . "/../_files/images/mario.gif");
43+
new Image(__DIR__ . "/../_files/images/firefox.png");
44+
new Image(__DIR__ . "/../_files/images/duke_nukem.bmp");
45+
new Image(__DIR__ . "/../_files/images/angela_merkel.tif");
5246
}
5347

5448
/**
@@ -57,7 +51,7 @@ public function testValidImageTypes()
5751
*/
5852
public function testImageNotFound()
5953
{
60-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/thisisnotarealimage");
54+
new Image(__DIR__ . "/../_files/images/thisisnotarealimage");
6155
}
6256

6357
/**
@@ -66,38 +60,30 @@ public function testImageNotFound()
6660
*/
6761
public function testInvalidImageTypes()
6862
{
69-
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/alexz-johnson.pcx");
63+
new Image(__DIR__ . "/../_files/images/alexz-johnson.pcx");
7064
}
7165

7266
public function testStyle()
7367
{
74-
$oImage = new Image(\join(
75-
\DIRECTORY_SEPARATOR,
76-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
77-
), array('width' => 210, 'height' => 210, 'align' => 'center'));
68+
$oImage = new Image(
69+
__DIR__ . "/../_files/images/earth.jpg",
70+
array('width' => 210, 'height' => 210, 'align' => 'center')
71+
);
7872

7973
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
8074
}
8175

8276
public function testRelationID()
8377
{
84-
$oImage = new Image(\join(
85-
\DIRECTORY_SEPARATOR,
86-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
87-
));
88-
78+
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
8979
$iVal = rand(1, 1000);
9080
$oImage->setRelationId($iVal);
9181
$this->assertEquals($oImage->getRelationId(), $iVal);
9282
}
9383

9484
public function testWatermark()
9585
{
96-
$oImage = new Image(\join(
97-
\DIRECTORY_SEPARATOR,
98-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
99-
));
100-
86+
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
10187
$oImage->setIsWatermark(true);
10288
$this->assertEquals($oImage->getIsWatermark(), true);
10389
}

test/PhpWord/Tests/Section/MemoryImageTest.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
77
{
88
public function testPNG()
99
{
10-
$src = \join(
11-
\DIRECTORY_SEPARATOR,
12-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'firefox.png')
13-
);
10+
$src = __DIR__ . "/../_files/images/firefox.png";
1411
$oMemoryImage = new MemoryImage($src);
1512

1613
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
@@ -24,10 +21,7 @@ public function testPNG()
2421

2522
public function testGIF()
2623
{
27-
$src = \join(
28-
\DIRECTORY_SEPARATOR,
29-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'mario.gif')
30-
);
24+
$src = __DIR__ . "/../_files/images/mario.gif";
3125
$oMemoryImage = new MemoryImage($src);
3226

3327
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
@@ -41,10 +35,7 @@ public function testGIF()
4135

4236
public function testJPG()
4337
{
44-
$src = \join(
45-
\DIRECTORY_SEPARATOR,
46-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
47-
);
38+
$src = __DIR__ . "/../_files/images/earth.jpg";
4839
$oMemoryImage = new MemoryImage($src);
4940

5041
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
@@ -58,10 +49,7 @@ public function testJPG()
5849

5950
public function testBMP()
6051
{
61-
$oMemoryImage = new MemoryImage(\join(
62-
\DIRECTORY_SEPARATOR,
63-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'duke_nukem.bmp')
64-
));
52+
$oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/duke_nukem.bmp");
6553

6654
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
6755
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
@@ -72,20 +60,16 @@ public function testBMP()
7260

7361
public function testStyle()
7462
{
75-
$oMemoryImage = new MemoryImage(\join(
76-
\DIRECTORY_SEPARATOR,
77-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
78-
), array('width' => 210, 'height' => 210, 'align' => 'center'));
79-
63+
$oMemoryImage = new MemoryImage(
64+
__DIR__ . "/../_files/images/earth.jpg",
65+
array('width' => 210, 'height' => 210, 'align' => 'center')
66+
);
8067
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
8168
}
8269

8370
public function testRelationID()
8471
{
85-
$oMemoryImage = new MemoryImage(\join(
86-
\DIRECTORY_SEPARATOR,
87-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
88-
));
72+
$oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/earth.jpg");
8973

9074
$iVal = rand(1, 1000);
9175
$oMemoryImage->setRelationId($iVal);

test/PhpWord/Tests/Section/ObjectTest.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
77
{
88
public function testConstructWithSupportedFiles()
99
{
10-
$src = \join(
11-
\DIRECTORY_SEPARATOR,
12-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
13-
);
10+
$src = __DIR__ . "/../_files/documents/sheet.xls";
1411
$oObject = new Object($src);
1512

1613
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
@@ -20,10 +17,7 @@ public function testConstructWithSupportedFiles()
2017

2118
public function testConstructWithNotSupportedFiles()
2219
{
23-
$src = \join(
24-
\DIRECTORY_SEPARATOR,
25-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'passthrough.xsl')
26-
);
20+
$src = __DIR__ . "/../_files/xsl/passthrough.xsl";
2721
$oObject = new Object($src);
2822

2923
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
@@ -33,10 +27,7 @@ public function testConstructWithNotSupportedFiles()
3327

3428
public function testConstructWithSupportedFilesAndStyle()
3529
{
36-
$src = \join(
37-
\DIRECTORY_SEPARATOR,
38-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
39-
);
30+
$src = __DIR__ . "/../_files/documents/sheet.xls";
4031
$oObject = new Object($src, array('width' => '230px'));
4132

4233
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
@@ -46,10 +37,7 @@ public function testConstructWithSupportedFilesAndStyle()
4637

4738
public function testRelationId()
4839
{
49-
$src = \join(
50-
\DIRECTORY_SEPARATOR,
51-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
52-
);
40+
$src = __DIR__ . "/../_files/documents/sheet.xls";
5341
$oObject = new Object($src);
5442

5543
$iVal = rand(1, 1000);
@@ -59,10 +47,7 @@ public function testRelationId()
5947

6048
public function testImageRelationId()
6149
{
62-
$src = \join(
63-
\DIRECTORY_SEPARATOR,
64-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
65-
);
50+
$src = __DIR__ . "/../_files/documents/sheet.xls";
6651
$oObject = new Object($src);
6752

6853
$iVal = rand(1, 1000);
@@ -72,10 +57,7 @@ public function testImageRelationId()
7257

7358
public function testObjectId()
7459
{
75-
$src = \join(
76-
\DIRECTORY_SEPARATOR,
77-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
78-
);
60+
$src = __DIR__ . "/../_files/documents/sheet.xls";
7961
$oObject = new Object($src);
8062

8163
$iVal = rand(1, 1000);

0 commit comments

Comments
 (0)