Skip to content

Commit bf13fef

Browse files
committed
Merge pull request #98 from ivanlanin/develop
Basic unit tests for PHPWord\Style completed
2 parents 79ba793 + 6697057 commit bf13fef

File tree

13 files changed

+480
-10
lines changed

13 files changed

+480
-10
lines changed

Classes/PHPWord/Section/Settings.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public function getPageNumberingStart()
617617
* @return int
618618
*/
619619
public function getHeaderHeight() {
620-
return $this->headerHeight;
620+
return $this->headerHeight;
621621
}
622622

623623
/**
@@ -626,8 +626,11 @@ public function getHeaderHeight() {
626626
* @param int $pValue
627627
*/
628628
public function setHeaderHeight($pValue = '') {
629-
$this->headerHeight = $pValue;
630-
return $this;
629+
if (!is_numeric($pValue)) {
630+
$pValue = 720;
631+
}
632+
$this->headerHeight = $pValue;
633+
return $this;
631634
}
632635

633636
/**
@@ -636,7 +639,7 @@ public function setHeaderHeight($pValue = '') {
636639
* @return int
637640
*/
638641
public function getFooterHeight() {
639-
return $this->footerHeight;
642+
return $this->footerHeight;
640643
}
641644

642645
/**
@@ -645,8 +648,11 @@ public function getFooterHeight() {
645648
* @param int $pValue
646649
*/
647650
public function setFooterHeight($pValue = '') {
648-
$this->footerHeight = $pValue;
649-
return $this;
651+
if (!is_numeric($pValue)) {
652+
$pValue = 720;
653+
}
654+
$this->footerHeight = $pValue;
655+
return $this;
650656
}
651657

652658
/**
@@ -655,6 +661,9 @@ public function setFooterHeight($pValue = '') {
655661
* @param int $pValue
656662
*/
657663
public function setColsNum($pValue = '') {
664+
if (!is_numeric($pValue)) {
665+
$pValue = 1;
666+
}
658667
$this->_colsNum = $pValue;
659668
return $this;
660669
}
@@ -674,6 +683,9 @@ public function getColsNum() {
674683
* @param int $pValue
675684
*/
676685
public function setColsSpace($pValue = '') {
686+
if (!is_numeric($pValue)) {
687+
$pValue = 720;
688+
}
677689
$this->_colsSpace = $pValue;
678690
return $this;
679691
}

Classes/PHPWord/Style/TOC.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getTabPos()
8585
*/
8686
public function setTabPos($pValue)
8787
{
88-
$this->_tabLeader = $pValue;
88+
$this->_tabPos = $pValue;
8989
}
9090

9191
/**

Classes/PHPWord/Style/TableFull.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function setBgColor($pValue = null)
247247
/**
248248
* Set TLRBVH Border Size
249249
*
250-
* @param int $pValue
250+
* @param int $pValue Border size in eighths of a point (1/8 point)
251251
*/
252252
public function setBorderSize($pValue = null)
253253
{
@@ -466,6 +466,11 @@ public function getCellMarginBottom()
466466
return $this->_cellMarginBottom;
467467
}
468468

469+
/**
470+
* Set TLRB cell margin
471+
*
472+
* @param int $pValue Margin in twips
473+
*/
469474
public function setCellMargin($pValue = null)
470475
{
471476
$this->_cellMarginTop = $pValue;

Tests/PHPWord/Section/SettingsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function testColumnsSpace()
217217
$this->assertEquals($iVal, $oSettings->getColsSpace());
218218

219219
$this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace());
220-
$this->assertEquals(1, $oSettings->getColsSpace());
220+
$this->assertEquals(720, $oSettings->getColsSpace());
221221
}
222222

223223
public function testBreakType()

Tests/PHPWord/Style/CellTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
class CellTest extends \PHPUnit_Framework_TestCase
1414
{
15+
1516
/**
1617
* Test setting style with normal value
1718
*/
@@ -34,7 +35,6 @@ public function testSetGetNormal()
3435
'gridSpan' => 2,
3536
'vMerge' => 2,
3637
);
37-
//'defaultBorderColor' => null,
3838
foreach ($attributes as $key => $value) {
3939
$set = "set{$key}";
4040
$get = "get{$key}";

Tests/PHPWord/Style/ImageTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
namespace PHPWord\Tests\Style;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord_Style_Image;
6+
7+
/**
8+
* Class ImageTest
9+
*
10+
* @package PHPWord\Tests
11+
* @runTestsInSeparateProcesses
12+
*/
13+
class ImageTest extends \PHPUnit_Framework_TestCase
14+
{
15+
16+
/**
17+
* Test setting style with normal value
18+
*/
19+
public function testSetGetNormal()
20+
{
21+
$object = new PHPWord_Style_Image();
22+
23+
$properties = array(
24+
'width' => 200,
25+
'height' => 200,
26+
'align' => 'left',
27+
'marginTop' => 240,
28+
'marginLeft' => 240,
29+
'wrappingStyle' => 'inline',
30+
);
31+
foreach ($properties as $key => $value) {
32+
$set = "set{$key}";
33+
$get = "get{$key}";
34+
$object->$set($value);
35+
$this->assertEquals($value, $object->$get());
36+
}
37+
}
38+
39+
/**
40+
* Test setStyleValue method
41+
*/
42+
public function testSetStyleValue()
43+
{
44+
$object = new PHPWord_Style_Image();
45+
46+
$properties = array(
47+
'width' => 200,
48+
'height' => 200,
49+
'align' => 'left',
50+
'marginTop' => 240,
51+
'marginLeft' => 240,
52+
);
53+
foreach ($properties as $key => $value) {
54+
$get = "get{$key}";
55+
$object->setStyleValue("_{$key}", $value);
56+
$this->assertEquals($value, $object->$get());
57+
}
58+
}
59+
60+
/**
61+
* Test setWrappingStyle exception
62+
*
63+
* @expectedException InvalidArgumentException
64+
*/
65+
public function testSetWrappingStyleException()
66+
{
67+
$object = new PHPWord_Style_Image();
68+
$object->setWrappingStyle('foo');
69+
}
70+
71+
}

Tests/PHPWord/Style/ListItemTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
namespace PHPWord\Tests\Style;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord_Style_ListItem;
6+
7+
/**
8+
* Class ListItemTest
9+
*
10+
* @package PHPWord\Tests
11+
* @runTestsInSeparateProcesses
12+
*/
13+
class ListItemTest extends \PHPUnit_Framework_TestCase
14+
{
15+
16+
/**
17+
* Test construct
18+
*/
19+
public function testConstruct()
20+
{
21+
$object = new PHPWord_Style_ListItem();
22+
23+
$value = PHPWord_Style_ListItem::TYPE_BULLET_FILLED;
24+
$this->assertEquals($value, $object->getListType());
25+
}
26+
27+
/**
28+
* Test set style value
29+
*/
30+
public function testSetStyleValue()
31+
{
32+
$object = new PHPWord_Style_ListItem();
33+
34+
$value = PHPWord_Style_ListItem::TYPE_ALPHANUM;
35+
$object->setStyleValue('_listType', $value);
36+
$this->assertEquals($value, $object->getListType());
37+
}
38+
39+
/**
40+
* Test list type
41+
*/
42+
public function testListType()
43+
{
44+
$object = new PHPWord_Style_ListItem();
45+
46+
$value = PHPWord_Style_ListItem::TYPE_ALPHANUM;
47+
$object->setListType($value);
48+
$this->assertEquals($value, $object->getListType());
49+
}
50+
51+
}

Tests/PHPWord/Style/ParagraphTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,15 @@ public function testLineHeight()
123123
$this->assertEquals(720, $lineHeight);
124124
$this->assertEquals('auto', $lineRule);
125125
}
126+
127+
/**
128+
* Test setLineHeight validation
129+
*/
130+
public function testLineHeightValidation()
131+
{
132+
$object = new PHPWord_Style_Paragraph();
133+
$object->setLineHeight('12.5pt');
134+
$this->assertEquals(12.5, $object->getLineHeight());
135+
}
136+
126137
}

Tests/PHPWord/Style/RowTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace PHPWord\Tests\Style;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord_Style_Row;
6+
7+
/**
8+
* Class RowTest
9+
*
10+
* @package PHPWord\Tests
11+
* @runTestsInSeparateProcesses
12+
*/
13+
class RowTest extends \PHPUnit_Framework_TestCase
14+
{
15+
16+
/**
17+
* Test properties with normal value
18+
*/
19+
public function testProperties()
20+
{
21+
$object = new PHPWord_Style_Row();
22+
23+
$properties = array(
24+
'tblHeader' => true,
25+
'cantSplit' => false,
26+
);
27+
foreach ($properties as $key => $value) {
28+
// set/get
29+
$set = "set{$key}";
30+
$get = "get{$key}";
31+
$expected = $value ? 1 : 0;
32+
$object->$set($value);
33+
$this->assertEquals($expected, $object->$get());
34+
35+
// setStyleValue
36+
$value = !$value;
37+
$expected = $value ? 1 : 0;
38+
$object->setStyleValue("_{$key}", $value);
39+
$this->assertEquals($expected, $object->$get());
40+
}
41+
}
42+
43+
}

Tests/PHPWord/Style/TOCTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace PHPWord\Tests\Style;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord_Style_TOC;
6+
7+
/**
8+
* Class TOCTest
9+
*
10+
* @package PHPWord\Tests
11+
* @runTestsInSeparateProcesses
12+
*/
13+
class TOCTest extends \PHPUnit_Framework_TestCase
14+
{
15+
16+
/**
17+
* Test properties with normal value
18+
*/
19+
public function testProperties()
20+
{
21+
$object = new PHPWord_Style_TOC();
22+
23+
$properties = array(
24+
'tabPos' => 9062,
25+
'tabLeader' => PHPWord_Style_TOC::TABLEADER_DOT,
26+
'indent' => 200,
27+
);
28+
foreach ($properties as $key => $value) {
29+
// set/get
30+
$set = "set{$key}";
31+
$get = "get{$key}";
32+
$object->$set($value);
33+
$this->assertEquals($value, $object->$get());
34+
35+
// setStyleValue
36+
$object->setStyleValue("_{$key}", null);
37+
$this->assertEquals(null, $object->$get());
38+
}
39+
}
40+
41+
}

0 commit comments

Comments
 (0)