Skip to content

Commit b11cd40

Browse files
committed
More unit tests
1 parent b3458b9 commit b11cd40

File tree

5 files changed

+109
-50
lines changed

5 files changed

+109
-50
lines changed

Tests/PHPWord/StyleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace PHPWord\Tests;
33

4-
use PHPUnit_Framework_TestCase;
54
use PHPWord_Style;
65

76
/**
@@ -11,7 +10,7 @@
1110
* @covers PHPWord_Style
1211
* @runTestsInSeparateProcesses
1312
*/
14-
class StyleTest extends PHPUnit_Framework_TestCase
13+
class StyleTest extends \PHPUnit_Framework_TestCase
1514
{
1615
/**
1716
* @covers PHPWord_Style::addParagraphStyle

Tests/PHPWord/Writer/Word2007/BaseTest.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public function tearDown()
2121
TestHelperDOCX::clear();
2222
}
2323

24+
/**
25+
* covers ::_writeText
26+
*/
2427
public function testWriteText()
2528
{
2629
$rStyle = 'rStyle';
@@ -40,7 +43,7 @@ public function testWriteText()
4043
}
4144

4245
/**
43-
* Write text run
46+
* covers ::_writeTextRun
4447
*/
4548
public function testWriteTextRun()
4649
{
@@ -67,7 +70,7 @@ public function testWriteTextRun()
6770
}
6871

6972
/**
70-
* Write link
73+
* covers ::_writeLink
7174
*/
7275
public function testWriteLink()
7376
{
@@ -84,7 +87,7 @@ public function testWriteLink()
8487
}
8588

8689
/**
87-
* Write preserve text
90+
* covers ::_writePreserveText
8891
*/
8992
public function testWritePreserveText()
9093
{
@@ -102,7 +105,7 @@ public function testWritePreserveText()
102105
}
103106

104107
/**
105-
* Write paragraph style: Alignment
108+
* covers ::_writeParagraphStyle
106109
*/
107110
public function testWriteParagraphStyleAlign()
108111
{
@@ -118,7 +121,7 @@ public function testWriteParagraphStyleAlign()
118121
}
119122

120123
/**
121-
* Write paragraph style: Pagination
124+
* covers ::_writeParagraphStyle
122125
*/
123126
public function testWriteParagraphStylePagination()
124127
{
@@ -180,7 +183,7 @@ public function testWriteFontStyle()
180183
}
181184

182185
/**
183-
* Write table
186+
* covers ::_writeTableStyle
184187
*/
185188
public function testWriteTableStyle()
186189
{
@@ -238,7 +241,7 @@ public function testWriteTableStyle()
238241
}
239242

240243
/**
241-
* Write cell style
244+
* covers ::_writeCellStyle
242245
*/
243246
public function testWriteCellStyleCellGridSpan()
244247
{
@@ -265,7 +268,7 @@ public function testWriteCellStyleCellGridSpan()
265268
}
266269

267270
/**
268-
* Write image
271+
* covers ::_writeImage
269272
*/
270273
public function testWriteImagePosition()
271274
{
@@ -290,7 +293,27 @@ public function testWriteImagePosition()
290293
}
291294

292295
/**
293-
* Write title
296+
* covers ::_writeWatermark
297+
*/
298+
public function testWriteWatermark()
299+
{
300+
$imageSrc = join(
301+
DIRECTORY_SEPARATOR,
302+
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
303+
);
304+
305+
$PHPWord = new PHPWord();
306+
$section = $PHPWord->createSection();
307+
$header = $section->createHeader();
308+
$header->addWatermark($imageSrc);
309+
$doc = TestHelperDOCX::getDocument($PHPWord);
310+
311+
$element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference");
312+
$this->assertStringStartsWith("rId", $element->getAttribute('r:id'));
313+
}
314+
315+
/**
316+
* covers ::_writeTitle
294317
*/
295318
public function testWriteTitle()
296319
{

Tests/PHPWord/Writer/Word2007/DocumentTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,56 @@ public function testWriteEndSectionPageNumbering()
3232

3333
$this->assertEquals(2, $element->getAttribute('w:start'));
3434
}
35+
36+
/**
37+
* covers ::_writeTOC
38+
* covers ::_writePageBreak
39+
* covers ::_writeListItem
40+
* covers ::_writeTitle
41+
* covers ::_writeObject
42+
*/
43+
public function testElements()
44+
{
45+
$objectSrc = join(
46+
DIRECTORY_SEPARATOR,
47+
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
48+
);
49+
50+
$PHPWord = new PHPWord();
51+
$PHPWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true));
52+
$PHPWord->addTitleStyle(2, array('color'=>'666666'));
53+
$section = $PHPWord->createSection();
54+
$section->addTOC();
55+
$section->addPageBreak();
56+
$section->addTitle('Title 1', 1);
57+
$section->addListItem('List Item 1', 0);
58+
$section->addListItem('List Item 2', 0);
59+
$section->addListItem('List Item 3', 0);
60+
$section = $PHPWord->createSection();
61+
$section->addTitle('Title 2', 2);
62+
$section->addObject($objectSrc);
63+
$doc = TestHelperDOCX::getDocument($PHPWord);
64+
65+
// TOC
66+
$element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:tabs/w:tab');
67+
$this->assertEquals('right', $element->getAttribute('w:val'));
68+
$this->assertEquals('dot', $element->getAttribute('w:leader'));
69+
$this->assertEquals(9062, $element->getAttribute('w:pos'));
70+
71+
// Page break
72+
$element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:br');
73+
$this->assertEquals('page', $element->getAttribute('w:type'));
74+
75+
// Title
76+
$element = $doc->getElement('/w:document/w:body/w:p[5]/w:pPr/w:pStyle');
77+
$this->assertEquals('Heading1', $element->getAttribute('w:val'));
78+
79+
// List item
80+
$element = $doc->getElement('/w:document/w:body/w:p[6]/w:pPr/w:numPr/w:numId');
81+
$this->assertEquals(3, $element->getAttribute('w:val'));
82+
83+
// Object
84+
$element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject');
85+
$this->assertEquals('Embed', $element->getAttribute('Type'));
86+
}
3587
}

Tests/PHPWord/Writer/Word2007/StylesTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,31 @@ public function testWriteStyles()
2626
{
2727
$PHPWord = new PHPWord();
2828

29-
$defaultStyle = array('align' => 'both');
30-
$baseStyle = array('basedOn' => 'Normal');
31-
$newStyle = array('basedOn' => 'Base Style', 'next' => 'Normal');
32-
$PHPWord->setDefaultParagraphStyle($defaultStyle);
33-
$PHPWord->addParagraphStyle('Base Style', $baseStyle);
34-
$PHPWord->addParagraphStyle('New Style', $newStyle);
29+
$pStyle = array('align' => 'both');
30+
$pBase = array('basedOn' => 'Normal');
31+
$pNew = array('basedOn' => 'Base Style', 'next' => 'Normal');
32+
$rStyle = array('size' => 20);
33+
$tStyle = array(
34+
'bgColor' => 'FF0000',
35+
'cellMarginTop' => 120,
36+
'cellMarginBottom' => 120,
37+
'cellMarginLeft' => 120,
38+
'cellMarginRight' => 120,
39+
'borderTopSize' => 120,
40+
'borderBottomSize' => 120,
41+
'borderLeftSize' => 120,
42+
'borderRightSize' => 120,
43+
'borderInsideHSize' => 120,
44+
'borderInsideVSize' => 120,
45+
);
46+
$PHPWord->setDefaultParagraphStyle($pStyle);
47+
$PHPWord->addParagraphStyle('Base Style', $pBase);
48+
$PHPWord->addParagraphStyle('New Style', $pNew);
49+
$PHPWord->addFontStyle('New Style', $rStyle, $pStyle);
50+
$PHPWord->addTableStyle('Table Style', $tStyle, $tStyle);
51+
$PHPWord->addTitleStyle(1, $rStyle, $pStyle);
3552
$doc = TestHelperDOCX::getDocument($PHPWord);
53+
3654
$file = 'word/styles.xml';
3755

3856
// Normal style generated?

samples/Sample_00.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)