Skip to content

Commit 92a76d0

Browse files
committed
Merge branch 'develop' into PHPOffice#160-refactoring
2 parents eed86f3 + ecdaeef commit 92a76d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+272
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ before_script:
3838
script:
3939
## PHP_CodeSniffer
4040
- phpcs --standard=PSR2 -n src/
41-
- phpcs --standard=PSR2 -n test/
41+
- phpcs --standard=PSR2 -n tests/
4242
## PHP Copy/Paste Detector
4343
#- php phpcpd.phar --verbose src/
4444
## PHP Mess Detector

README.md

Lines changed: 6 additions & 3 deletions

docs/images/phpword.svg

Lines changed: 50 additions & 0 deletions

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<phpunit backupGlobals="false"
22
backupStaticAttributes="false"
3-
bootstrap="./test/bootstrap.php"
3+
bootstrap="./tests/bootstrap.php"
44
colors="true"
55
convertErrorsToExceptions="true"
66
convertNoticesToExceptions="true"
@@ -10,7 +10,7 @@
1010
syntaxCheck="false">
1111
<testsuites>
1212
<testsuite name="PhpWord Test Suite">
13-
<directory>./test/PhpWord/</directory>
13+
<directory>./tests/PhpWord/</directory>
1414
</testsuite>
1515
</testsuites>
1616
<filter>
File renamed without changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
namespace PhpOffice\PhpWord\Tests\Section;
3+
4+
use PhpOffice\PhpWord\Section\MemoryImage;
5+
6+
class MemoryImageTest extends \PHPUnit_Framework_TestCase
7+
{
8+
public function testPNG()
9+
{
10+
$src = __DIR__ . "/../_files/images/firefox.png";
11+
$oMemoryImage = new MemoryImage($src);
12+
13+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
14+
$this->assertEquals($oMemoryImage->getSource(), $src);
15+
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
16+
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng');
17+
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagepng');
18+
$this->assertEquals($oMemoryImage->getImageExtension(), 'png');
19+
$this->assertEquals($oMemoryImage->getImageType(), 'image/png');
20+
}
21+
22+
public function testGIF()
23+
{
24+
$src = __DIR__ . "/../_files/images/mario.gif";
25+
$oMemoryImage = new MemoryImage($src);
26+
27+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
28+
$this->assertEquals($oMemoryImage->getSource(), $src);
29+
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
30+
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif');
31+
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagegif');
32+
$this->assertEquals($oMemoryImage->getImageExtension(), 'gif');
33+
$this->assertEquals($oMemoryImage->getImageType(), 'image/gif');
34+
}
35+
36+
public function testJPG()
37+
{
38+
$src = __DIR__ . "/../_files/images/earth.jpg";
39+
$oMemoryImage = new MemoryImage($src);
40+
41+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
42+
$this->assertEquals($oMemoryImage->getSource(), $src);
43+
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
44+
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg');
45+
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagejpeg');
46+
$this->assertEquals($oMemoryImage->getImageExtension(), 'jpg');
47+
$this->assertEquals($oMemoryImage->getImageType(), 'image/jpeg');
48+
}
49+
50+
public function testBMP()
51+
{
52+
$oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/duke_nukem.bmp");
53+
54+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
55+
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
56+
$this->assertEquals($oMemoryImage->getImageFunction(), null);
57+
$this->assertEquals($oMemoryImage->getImageExtension(), null);
58+
$this->assertEquals($oMemoryImage->getImageType(), 'image/x-ms-bmp');
59+
}
60+
61+
public function testStyle()
62+
{
63+
$oMemoryImage = new MemoryImage(
64+
__DIR__ . "/../_files/images/earth.jpg",
65+
array('width' => 210, 'height' => 210, 'align' => 'center')
66+
);
67+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
68+
}
69+
70+
public function testRelationID()
71+
{
72+
$oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/earth.jpg");
73+
74+
$iVal = rand(1, 1000);
75+
$oMemoryImage->setRelationId($iVal);
76+
$this->assertEquals($oMemoryImage->getRelationId(), $iVal);
77+
}
78+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
namespace PhpOffice\PhpWord\Tests\Style;
3+
4+
use PhpOffice\PhpWord\Style\TableFull;
5+
6+
/**
7+
* @runTestsInSeparateProcesses
8+
*/
9+
class TableFullTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* Test class construction
13+
*
14+
* There are 3 variables for class constructor:
15+
* - $styleTable: Define table styles
16+
* - $styleFirstRow: Define style for the first row
17+
* - $styleLastRow: Define style for the last row (reserved)
18+
*/
19+
public function testConstruct()
20+
{
21+
$styleTable = array('bgColor' => 'FF0000');
22+
$styleFirstRow = array('borderBottomSize' => 3);
23+
24+
$object = new TableFull($styleTable, $styleFirstRow);
25+
$this->assertEquals('FF0000', $object->getBgColor());
26+
27+
$firstRow = $object->getFirstRow();
28+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TableFull', $firstRow);
29+
$this->assertEquals(3, $firstRow->getBorderBottomSize());
30+
}
31+
32+
/**
33+
* Test setting style with normal value
34+
*/
35+
public function testSetGetNormal()
36+
{
37+
$object = new TableFull();
38+
39+
$attributes = array(
40+
'bgColor' => 'FF0000',
41+
'borderTopSize' => 4,
42+
'borderTopColor' => 'FF0000',
43+
'borderLeftSize' => 4,
44+
'borderLeftColor' => 'FF0000',
45+
'borderRightSize' => 4,
46+
'borderRightColor' => 'FF0000',
47+
'borderBottomSize' => 4,
48+
'borderBottomColor' => 'FF0000',
49+
'borderInsideHSize' => 4,
50+
'borderInsideHColor' => 'FF0000',
51+
'borderInsideVSize' => 4,
52+
'borderInsideVColor' => 'FF0000',
53+
'cellMarginTop' => 240,
54+
'cellMarginLeft' => 240,
55+
'cellMarginRight' => 240,
56+
'cellMarginBottom' => 240,
57+
);
58+
foreach ($attributes as $key => $value) {
59+
$set = "set{$key}";
60+
$get = "get{$key}";
61+
$object->$set($value);
62+
$this->assertEquals($value, $object->$get());
63+
}
64+
}
65+
66+
/**
67+
* Test border color
68+
*
69+
* Set border color and test if each part has the same color
70+
* While looping, push values array to be asserted with getBorderColor
71+
*/
72+
public function testBorderColor()
73+
{
74+
$object = new TableFull();
75+
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
76+
77+
$value = 'FF0000';
78+
$object->setBorderColor($value);
79+
foreach ($parts as $part) {
80+
$get = "getBorder{$part}Color";
81+
$values[] = $value;
82+
$this->assertEquals($value, $object->$get());
83+
}
84+
$this->assertEquals($values, $object->getBorderColor());
85+
}
86+
87+
/**
88+
* Test border size
89+
*
90+
* Set border size and test if each part has the same size
91+
* While looping, push values array to be asserted with getBorderSize
92+
* Value is in eights of a point, i.e. 4 / 8 = .5pt
93+
*/
94+
public function testBorderSize()
95+
{
96+
$object = new TableFull();
97+
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
98+
99+
$value = 4;
100+
$object->setBorderSize($value);
101+
foreach ($parts as $part) {
102+
$get = "getBorder{$part}Size";
103+
$values[] = $value;
104+
$this->assertEquals($value, $object->$get());
105+
}
106+
$this->assertEquals($values, $object->getBorderSize());
107+
}
108+
109+
/**
110+
* Test cell margin
111+
*
112+
* Set cell margin and test if each part has the same margin
113+
* While looping, push values array to be asserted with getCellMargin
114+
* Value is in twips
115+
*/
116+
public function testCellMargin()
117+
{
118+
$object = new TableFull();
119+
$parts = array('Top', 'Left', 'Right', 'Bottom');
120+
121+
$value = 240;
122+
$object->setCellMargin($value);
123+
foreach ($parts as $part) {
124+
$get = "getCellMargin{$part}";
125+
$values[] = $value;
126+
$this->assertEquals($value, $object->$get());
127+
}
128+
$this->assertEquals($values, $object->getCellMargin());
129+
}
130+
}
File renamed without changes.
File renamed without changes.

test/PhpWord/Tests/TemplateTest.php renamed to tests/PhpWord/Tests/TemplateTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpOffice\PhpWord\Template;
66

77
/**
8+
* @covers \PhpOffice\PhpWord\Template
89
* @coversDefaultClass \PhpOffice\PhpWord\Template
910
*/
1011
final class TemplateTest extends \PHPUnit_Framework_TestCase
@@ -115,8 +116,8 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromT
115116
}
116117

117118
/**
118-
* @covers ::setValue
119119
* @covers ::getVariables
120+
* @covers ::setValue
120121
* @covers ::cloneRow
121122
* @covers ::saveAs
122123
*/
@@ -126,13 +127,13 @@ public function testCloneRow()
126127
$expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation');
127128
$docName = 'clone-test-result.docx';
128129

129-
$phpWord = new PhpWord();
130-
$document = $phpWord->loadTemplate($template);
130+
$document = new Template($template);
131131
$actualVar = $document->getVariables();
132+
$document->setValue('tableHeader', utf8_decode('ééé'));
132133
$document->cloneRow('userId', 1);
133134
$document->setValue('userId#1', 'Test');
134135
$document->saveAs($docName);
135-
$docFound = \file_exists($docName);
136+
$docFound = file_exists($docName);
136137
unlink($docName);
137138

138139
$this->assertEquals($expectedVar, $actualVar);
File renamed without changes.

0 commit comments

Comments
 (0)