Skip to content

Commit 9b793e5

Browse files
committed
Unit Tests on Section directory
1 parent db08572 commit 9b793e5

29 files changed

+1332
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ phpunit.xml
99
composer.lock
1010
composer.phar
1111
vendor
12+
/report
1213
/.settings
1314
/.buildpath
1415
/.project

Classes/PHPWord/Section/Footer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public function setRelationId($rId)
196196

197197
/**
198198
* Get all Footer Elements
199+
* @return array
199200
*/
200201
public function getElements()
201202
{

Classes/PHPWord/Section/Footnote.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PHPWord_Section_Footnote {
6262
public function __construct($styleParagraph = null) {
6363
$this->_elementCollection = array();
6464

65-
// Set paragraph style
65+
// Set paragraph style
6666
if(is_array($styleParagraph)) {
6767
$this->_styleParagraph = new PHPWord_Style_Paragraph();
6868

@@ -113,7 +113,7 @@ public function addLink($linkSrc, $linkName = null, $styleFont = null) {
113113
/**
114114
* Get Footnote content
115115
*
116-
* @return string
116+
* @return array
117117
*/
118118
public function getElements() {
119119
return $this->_elementCollection;

Classes/PHPWord/Section/PageBreak.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ class PHPWord_Section_PageBreak
3636
*/
3737
public function __construct()
3838
{
39-
// nothing
4039
}
4140
}

Classes/PHPWord/Section/Settings.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ class PHPWord_Section_Settings
150150
*/
151151
private $_borderBottomColor;
152152

153-
154153
/**
155154
* Page Numbering Start
156155
*
@@ -653,7 +652,7 @@ public function setFooterHeight($pValue = '') {
653652
/**
654653
* Set Section Columns Count
655654
*
656-
* @param in $pValue
655+
* @param int $pValue
657656
*/
658657
public function setColsNum($pValue = '') {
659658
$this->_colsNum = $pValue;

Classes/PHPWord/Section/TextBreak.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ class PHPWord_Section_TextBreak
3636
*/
3737
public function __construct()
3838
{
39-
// nothing
4039
}
4140
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace PHPWord\Tests;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord_Section_Footer_PreserveText;
6+
7+
class PHPWord_Section_Footer_PreserveTextTest extends \PHPUnit_Framework_TestCase {
8+
public function testConstruct(){
9+
$oPreserveText = new PHPWord_Section_Footer_PreserveText();
10+
11+
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $oPreserveText);
12+
$this->assertEquals($oPreserveText->getText(), null);
13+
$this->assertEquals($oPreserveText->getFontStyle(), null);
14+
$this->assertEquals($oPreserveText->getParagraphStyle(), null);
15+
}
16+
17+
public function testConstructWithString(){
18+
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', 'styleFont', 'styleParagraph');
19+
$this->assertEquals($oPreserveText->getText(), 'text');
20+
$this->assertEquals($oPreserveText->getFontStyle(), 'styleFont');
21+
$this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph');
22+
}
23+
24+
public function testConstructWithArray(){
25+
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', array('align'=>'center'), array('marginLeft'=>600, 'marginRight'=>600, 'marginTop'=>600, 'marginBottom'=>600));
26+
$this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle());
27+
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle());
28+
}
29+
}
30+

Tests/PHPWord/Section/FooterTest.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
namespace PHPWord\Tests;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord_Section_Footer;
6+
7+
class PHPWord_Section_FooterTest extends \PHPUnit_Framework_TestCase {
8+
9+
public function testConstruct(){
10+
$iVal = rand(1, 1000);
11+
$oFooter = new PHPWord_Section_Footer($iVal);
12+
13+
$this->assertInstanceOf('PHPWord_Section_Footer', $oFooter);
14+
$this->assertEquals($oFooter->getFooterCount(), $iVal);
15+
}
16+
17+
public function testRelationID(){
18+
$oFooter = new PHPWord_Section_Footer(0);
19+
20+
$iVal = rand(1, 1000);
21+
$oFooter->setRelationId($iVal);
22+
$this->assertEquals($oFooter->getRelationId(), $iVal);
23+
}
24+
25+
public function testAddText(){
26+
$oFooter = new PHPWord_Section_Footer(1);
27+
$element = $oFooter->addText('text');
28+
29+
$this->assertCount(1, $oFooter->getElements());
30+
$this->assertInstanceOf('PHPWord_Section_Text', $element);
31+
32+
}
33+
34+
public function testAddTextNotUTF8(){
35+
$oFooter = new PHPWord_Section_Footer(1);
36+
$element = $oFooter->addText(utf8_decode('ééé'));
37+
38+
$this->assertCount(1, $oFooter->getElements());
39+
$this->assertInstanceOf('PHPWord_Section_Text', $element);
40+
$this->assertEquals($element->getText(), 'ééé');
41+
}
42+
43+
public function testAddTextBreak(){
44+
$oFooter = new PHPWord_Section_Footer(1);
45+
$iVal = rand(1, 1000);
46+
$oFooter->addTextBreak($iVal);
47+
48+
$this->assertCount($iVal, $oFooter->getElements());
49+
}
50+
51+
public function testCreateTextRun(){
52+
$oFooter = new PHPWord_Section_Footer(1);
53+
$element = $oFooter->createTextRun();
54+
55+
$this->assertCount(1, $oFooter->getElements());
56+
$this->assertInstanceOf('PHPWord_Section_TextRun', $element);
57+
}
58+
59+
public function testAddTable(){
60+
$oFooter = new PHPWord_Section_Footer(1);
61+
$element = $oFooter->addTable();
62+
63+
$this->assertCount(1, $oFooter->getElements());
64+
$this->assertInstanceOf('PHPWord_Section_Table', $element);
65+
}
66+
67+
public function testAddImage(){
68+
$src = \join(
69+
\DIRECTORY_SEPARATOR,
70+
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
71+
);
72+
$oFooter = new PHPWord_Section_Footer(1);
73+
$element = $oFooter->addImage($src);
74+
75+
$this->assertCount(1, $oFooter->getElements());
76+
$this->assertInstanceOf('PHPWord_Section_Image', $element);
77+
}
78+
79+
public function testAddMemoryImage(){
80+
$oFooter = new PHPWord_Section_Footer(1);
81+
$element = $oFooter->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
82+
83+
$this->assertCount(1, $oFooter->getElements());
84+
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
85+
}
86+
87+
public function testAddPreserveText(){
88+
$oFooter = new PHPWord_Section_Footer(1);
89+
$element = $oFooter->addPreserveText('text');
90+
91+
$this->assertCount(1, $oFooter->getElements());
92+
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
93+
}
94+
95+
public function testAddPreserveTextNotUTF8(){
96+
$oFooter = new PHPWord_Section_Footer(1);
97+
$element = $oFooter->addPreserveText(utf8_decode('ééé'));
98+
99+
$this->assertCount(1, $oFooter->getElements());
100+
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
101+
$this->assertEquals($element->getText(), 'ééé');
102+
}
103+
104+
public function testGetElements(){
105+
$oFooter = new PHPWord_Section_Footer(1);
106+
107+
$this->assertInternalType('array', $oFooter->getElements());
108+
}
109+
}
110+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
namespace PHPWord\Tests;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord_Section_Footnote;
6+
7+
class PHPWord_Section_FootnoteTest extends \PHPUnit_Framework_TestCase {
8+
9+
public function testConstruct(){
10+
$oFootnote = new PHPWord_Section_Footnote();
11+
12+
$this->assertInstanceOf('PHPWord_Section_Footnote', $oFootnote);
13+
$this->assertCount(0, $oFootnote->getElements());
14+
$this->assertEquals($oFootnote->getParagraphStyle(), null);
15+
}
16+
17+
public function testConstructString(){
18+
$oFootnote = new PHPWord_Section_Footnote('pStyle');
19+
20+
$this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle');
21+
}
22+
23+
public function testConstructArray(){
24+
$oFootnote = new PHPWord_Section_Footnote(array('spacing' => 100));
25+
26+
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oFootnote->getParagraphStyle());
27+
}
28+
29+
public function testAddText(){
30+
$oFootnote = new PHPWord_Section_Footnote();
31+
$element = $oFootnote->addText('text');
32+
33+
$this->assertCount(1, $oFootnote->getElements());
34+
$this->assertInstanceOf('PHPWord_Section_Text', $element);
35+
}
36+
37+
public function testAddLink(){
38+
$oFootnote = new PHPWord_Section_Footnote();
39+
$element = $oFootnote->addLink('http://www.google.fr');
40+
41+
$this->assertCount(1, $oFootnote->getElements());
42+
$this->assertInstanceOf('PHPWord_Section_Link', $element);
43+
}
44+
45+
public function testReferenceId(){
46+
$oFootnote = new PHPWord_Section_Footnote();
47+
48+
$iVal = rand(1, 1000);
49+
$oFootnote->setReferenceId($iVal);
50+
$this->assertEquals($oFootnote->getReferenceId(), $iVal);
51+
}
52+
53+
public function testGetElements(){
54+
$oFootnote = new PHPWord_Section_Footnote();
55+
$this->assertInternalType('array', $oFootnote->getElements());
56+
}
57+
}
58+

0 commit comments

Comments
 (0)