diff --git a/src/PhpWord/Writer/ODText/Content.php b/src/PhpWord/Writer/ODText/Content.php index c618b042..89c39c31 100644 --- a/src/PhpWord/Writer/ODText/Content.php +++ b/src/PhpWord/Writer/ODText/Content.php @@ -9,6 +9,7 @@ namespace PhpOffice\PhpWord\Writer\ODText; +use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Element\Image; use PhpOffice\PhpWord\Element\Link; use PhpOffice\PhpWord\Element\ListItem; diff --git a/src/PhpWord/Writer/ODText/Meta.php b/src/PhpWord/Writer/ODText/Meta.php index f83e9edc..3e04234c 100644 --- a/src/PhpWord/Writer/ODText/Meta.php +++ b/src/PhpWord/Writer/ODText/Meta.php @@ -9,6 +9,7 @@ namespace PhpOffice\PhpWord\Writer\ODText; +use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; /** diff --git a/src/PhpWord/Writer/ODText/Styles.php b/src/PhpWord/Writer/ODText/Styles.php index 0f953ff1..8ca18760 100644 --- a/src/PhpWord/Writer/ODText/Styles.php +++ b/src/PhpWord/Writer/ODText/Styles.php @@ -9,6 +9,7 @@ namespace PhpOffice\PhpWord\Writer\ODText; +use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; diff --git a/tests/PhpWord/Tests/Writer/ODText/ContentTest.php b/tests/PhpWord/Tests/Writer/ODText/ContentTest.php index 4808de9e..e4f67102 100644 --- a/tests/PhpWord/Tests/Writer/ODText/ContentTest.php +++ b/tests/PhpWord/Tests/Writer/ODText/ContentTest.php @@ -9,6 +9,7 @@ namespace PhpOffice\PhpWord\Tests\Writer\ODText; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Writer\ODText\Content; use PhpOffice\PhpWord\Tests\TestHelperDOCX; /** @@ -28,8 +29,19 @@ class ContentTest extends \PHPUnit_Framework_TestCase } /** - * covers ::writeContent - * covers + * Test construct with no PhpWord + * + * @expectedException \PhpOffice\PhpWord\Exception\Exception + * @expectedExceptionMessage No PhpWord assigned. + */ + public function testConstructNoPhpWord() + { + $object = new Content(); + $object->writeContent(); + } + + /** + * Test write content */ public function testWriteContent() { @@ -38,27 +50,59 @@ class ContentTest extends \PHPUnit_Framework_TestCase $expected = 'Expected'; $phpWord = new PhpWord(); + $phpWord->setDefaultFontName('Verdana'); $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $section = $phpWord->addSection(); $section->addText($expected); $section->addText('Test font style', 'Font'); $section->addText('Test paragraph style', null, 'Paragraph'); - $section->addTextBreak(); $section->addLink('http://test.com', 'Test link'); $section->addTitle('Test title', 1); + $section->addTextBreak(); $section->addPageBreak(); - $section->addTable(); $section->addListItem('Test list item'); $section->addImage($imageSrc); $section->addObject($objectSrc); $section->addTOC(); + $textrun = $section->addTextRun(); $textrun->addText('Test text run'); + + $table = $section->addTable(); + $cell = $table->addRow()->addCell(); + $cell = $table->addRow()->addCell(); + $cell->addText('Test'); + $cell->addLink('http://test.com', 'Test link'); + $cell->addTextBreak(); + $cell->addListItem('Test list item'); + $cell->addImage($imageSrc); + $cell->addObject($objectSrc); + $textrun = $cell->addTextRun(); + $textrun->addText('Test text run'); + + $footer = $section->addFooter(); + $footer->addPreserveText('{PAGE}'); + $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); $element = "/office:document-content/office:body/office:text/text:p"; $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue); } + + /** + * Test no paragraph style + */ + public function testWriteNoStyle() + { + $phpWord = new PhpWord(); + $phpWord->addFontStyle('Font', array('size' => 11)); + + $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); + + $element = "/office:document-content/office:automatic-styles/style:style"; + $this->assertTrue($doc->elementExists($element, 'content.xml')); + } } diff --git a/tests/PhpWord/Tests/Writer/ODText/MetaTest.php b/tests/PhpWord/Tests/Writer/ODText/MetaTest.php new file mode 100644 index 00000000..9be32411 --- /dev/null +++ b/tests/PhpWord/Tests/Writer/ODText/MetaTest.php @@ -0,0 +1,32 @@ +writeMeta(); + } +} diff --git a/tests/PhpWord/Tests/Writer/ODText/StylesTest.php b/tests/PhpWord/Tests/Writer/ODText/StylesTest.php new file mode 100644 index 00000000..aa2ce0fa --- /dev/null +++ b/tests/PhpWord/Tests/Writer/ODText/StylesTest.php @@ -0,0 +1,32 @@ +writeStyles(); + } +}