Skip to content

Commit 79a87a1

Browse files
committed
ADDED : Basic unit tests
1 parent 4ffa261 commit 79a87a1

File tree

3 files changed

+45
-54
lines changed

3 files changed

+45
-54
lines changed

Tests/PHPWord/Writer/Word2007/BaseTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,42 @@ public function testWriteImage_Position()
4141
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
4242
$this->assertRegExp('/position:absolute;/', $style);
4343
}
44+
45+
public function testWriteParagraphStyle_Align()
46+
{
47+
$PHPWord = new PHPWord();
48+
$section = $PHPWord->createSection();
49+
50+
$section->addText('This is my text', null, array('align' => 'right'));
51+
52+
$doc = TestHelperDOCX::getDocument($PHPWord);
53+
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:jc');
54+
55+
$this->assertEquals('right', $element->getAttribute('w:val'));
56+
}
57+
58+
public function testWriteCellStyle_CellGridSpan()
59+
{
60+
$PHPWord = new PHPWord();
61+
$section = $PHPWord->createSection();
62+
63+
$table = $section->addTable();
64+
65+
$table->addRow();
66+
$cell = $table->addCell(200);
67+
$cell->getStyle()->setGridSpan(5);
68+
69+
$table->addRow();
70+
$table->addCell(40);
71+
$table->addCell(40);
72+
$table->addCell(40);
73+
$table->addCell(40);
74+
$table->addCell(40);
75+
76+
$doc = TestHelperDOCX::getDocument($PHPWord);
77+
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
78+
79+
$this->assertEquals(5, $element->getAttribute('w:val'));
80+
}
4481
}
4582

Tests/PHPWord/Writer/Word2007/DocumentTest.php

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
use PHPUnit_Framework_TestCase;
55
use PHPWord;
66
use PHPWord_Writer_Word2007;
7-
use PHPWord_Writer_Word2007_Base;
7+
use PHPWord_Writer_Word2007_Document;
88

99
/**
10-
* Class PHPWord_Writer_Word2007_BaseTest
10+
* Class PHPWord_Writer_Word2007_DocumentTest
1111
* @package PHPWord\Tests
1212
* @runTestsInSeparateProcesses
1313
*/
14-
class PHPWord_Writer_Word2007_BaseTest extends \PHPUnit_Framework_TestCase {
14+
class PHPWord_Writer_Word2007_DocumentTest extends \PHPUnit_Framework_TestCase {
1515
/**
1616
* Executed before each method of the class
1717
*/
@@ -20,63 +20,16 @@ public function tearDown()
2020
TestHelperDOCX::clear();
2121
}
2222

23-
public function testWriteImage_Position()
23+
public function testWriteEndSection_PageNumbering()
2424
{
2525
$PHPWord = new PHPWord();
2626
$section = $PHPWord->createSection();
27-
$section->addImage(
28-
PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg',
29-
array(
30-
'marginTop' => -1,
31-
'marginLeft' => -1,
32-
'wrappingStyle' => 'behind'
33-
)
34-
);
27+
$section->getSettings()->setPageNumberingStart(2);
3528

3629
$doc = TestHelperDOCX::getDocument($PHPWord);
37-
$element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape');
30+
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType');
3831

39-
$style = $element->getAttribute('style');
40-
41-
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
42-
$this->assertRegExp('/position:absolute;/', $style);
32+
$this->assertEquals(2, $element->getAttribute('w:start'));
4333
}
44-
45-
public function testWriteParagraphStyle_Align()
46-
{
47-
$PHPWord = new PHPWord();
48-
$section = $PHPWord->createSection();
49-
50-
$section->addText('This is my text', null, array('align' => 'right'));
51-
52-
$doc = TestHelperDOCX::getDocument($PHPWord);
53-
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:jc');
54-
55-
$this->assertEquals('right', $element->getAttribute('w:val'));
56-
}
57-
58-
public function testWriteCellStyle_CellGridSpan()
59-
{
60-
$PHPWord = new PHPWord();
61-
$section = $PHPWord->createSection();
62-
63-
$table = $section->addTable();
64-
65-
$table->addRow();
66-
$cell = $table->addCell(200);
67-
$cell->getStyle()->setGridSpan(5);
68-
69-
$table->addRow();
70-
$table->addCell(40);
71-
$table->addCell(40);
72-
$table->addCell(40);
73-
$table->addCell(40);
74-
$table->addCell(40);
75-
76-
$doc = TestHelperDOCX::getDocument($PHPWord);
77-
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
78-
79-
$this->assertEquals(5, $element->getAttribute('w:val'));
80-
}
8134
}
8235

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
**************************************************************************************
2424

2525
Changes in branch for release 0.7.1 :
26+
- QA: (Progi1984) - UnitTests
2627
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
2728
- Bugfix: (gabrielbull) - Fixed bug with cell styling
2829
- Bugfix: (gabrielbull) - Fixed bug list items inside of cells

0 commit comments

Comments
 (0)