Skip to content

Commit 306c354

Browse files
committed
ODText Writer: Additional unit tests
1 parent 94e1661 commit 306c354

File tree

6 files changed

+115
-4
lines changed

6 files changed

+115
-4
lines changed

src/PhpWord/Writer/ODText/Content.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PhpOffice\PhpWord\Writer\ODText;
1111

12+
use PhpOffice\PhpWord\Exception\Exception;
1213
use PhpOffice\PhpWord\Element\Image;
1314
use PhpOffice\PhpWord\Element\Link;
1415
use PhpOffice\PhpWord\Element\ListItem;

src/PhpWord/Writer/ODText/Meta.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PhpOffice\PhpWord\Writer\ODText;
1111

12+
use PhpOffice\PhpWord\Exception\Exception;
1213
use PhpOffice\PhpWord\PhpWord;
1314

1415
/**

src/PhpWord/Writer/ODText/Styles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PhpOffice\PhpWord\Writer\ODText;
1111

12+
use PhpOffice\PhpWord\Exception\Exception;
1213
use PhpOffice\PhpWord\PhpWord;
1314
use PhpOffice\PhpWord\Style\Font;
1415
use PhpOffice\PhpWord\Style\Paragraph;

tests/PhpWord/Tests/Writer/ODText/ContentTest.php

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
1010

1111
use PhpOffice\PhpWord\PhpWord;
12+
use PhpOffice\PhpWord\Writer\ODText\Content;
1213
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
1314

1415
/**
@@ -28,8 +29,19 @@ public function tearDown()
2829
}
2930

3031
/**
31-
* covers ::writeContent
32-
* covers <private>
32+
* Test construct with no PhpWord
33+
*
34+
* @expectedException \PhpOffice\PhpWord\Exception\Exception
35+
* @expectedExceptionMessage No PhpWord assigned.
36+
*/
37+
public function testConstructNoPhpWord()
38+
{
39+
$object = new Content();
40+
$object->writeContent();
41+
}
42+
43+
/**
44+
* Test write content
3345
*/
3446
public function testWriteContent()
3547
{
@@ -38,27 +50,59 @@ public function testWriteContent()
3850
$expected = 'Expected';
3951

4052
$phpWord = new PhpWord();
53+
4154
$phpWord->setDefaultFontName('Verdana');
4255
$phpWord->addFontStyle('Font', array('size' => 11));
4356
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
57+
4458
$section = $phpWord->addSection();
4559
$section->addText($expected);
4660
$section->addText('Test font style', 'Font');
4761
$section->addText('Test paragraph style', null, 'Paragraph');
48-
$section->addTextBreak();
4962
$section->addLink('http://test.com', 'Test link');
5063
$section->addTitle('Test title', 1);
64+
$section->addTextBreak();
5165
$section->addPageBreak();
52-
$section->addTable();
5366
$section->addListItem('Test list item');
5467
$section->addImage($imageSrc);
5568
$section->addObject($objectSrc);
5669
$section->addTOC();
70+
5771
$textrun = $section->addTextRun();
5872
$textrun->addText('Test text run');
73+
74+
$table = $section->addTable();
75+
$cell = $table->addRow()->addCell();
76+
$cell = $table->addRow()->addCell();
77+
$cell->addText('Test');
78+
$cell->addLink('http://test.com', 'Test link');
79+
$cell->addTextBreak();
80+
$cell->addListItem('Test list item');
81+
$cell->addImage($imageSrc);
82+
$cell->addObject($objectSrc);
83+
$textrun = $cell->addTextRun();
84+
$textrun->addText('Test text run');
85+
86+
$footer = $section->addFooter();
87+
$footer->addPreserveText('{PAGE}');
88+
5989
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
6090

6191
$element = "/office:document-content/office:body/office:text/text:p";
6292
$this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
6393
}
94+
95+
/**
96+
* Test no paragraph style
97+
*/
98+
public function testWriteNoStyle()
99+
{
100+
$phpWord = new PhpWord();
101+
$phpWord->addFontStyle('Font', array('size' => 11));
102+
103+
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
104+
105+
$element = "/office:document-content/office:automatic-styles/style:style";
106+
$this->assertTrue($doc->elementExists($element, 'content.xml'));
107+
}
64108
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* PHPWord
4+
*
5+
* @link https://github.com/PHPOffice/PHPWord
6+
* @copyright 2014 PHPWord
7+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
8+
*/
9+
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
10+
11+
use PhpOffice\PhpWord\Writer\ODText\Meta;
12+
13+
/**
14+
* Test class for PhpOffice\PhpWord\Writer\ODText\Meta
15+
*
16+
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Meta
17+
* @runTestsInSeparateProcesses
18+
*/
19+
class MetaTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* Test construct with no PhpWord
23+
*
24+
* @expectedException \PhpOffice\PhpWord\Exception\Exception
25+
* @expectedExceptionMessage No PhpWord assigned.
26+
*/
27+
public function testConstructNoPhpWord()
28+
{
29+
$object = new Meta();
30+
$object->writeMeta();
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* PHPWord
4+
*
5+
* @link https://github.com/PHPOffice/PHPWord
6+
* @copyright 2014 PHPWord
7+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
8+
*/
9+
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
10+
11+
use PhpOffice\PhpWord\Writer\ODText\Styles;
12+
13+
/**
14+
* Test class for PhpOffice\PhpWord\Writer\ODText\Styles
15+
*
16+
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Styles
17+
* @runTestsInSeparateProcesses
18+
*/
19+
class StylesTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* Test construct with no PhpWord
23+
*
24+
* @expectedException \PhpOffice\PhpWord\Exception\Exception
25+
* @expectedExceptionMessage No PhpWord assigned.
26+
*/
27+
public function testConstructNoPhpWord()
28+
{
29+
$object = new Styles();
30+
$object->writeStyles();
31+
}
32+
}

0 commit comments

Comments
 (0)