From 991016a48b73d566dce6bc6982c81a2378bbe1fb Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sat, 24 May 2014 00:11:06 +0700 Subject: [PATCH] Additional writer test --- src/PhpWord/Shared/String.php | 4 ++-- src/PhpWord/Writer/ODText/Part/Content.php | 10 ++++++---- tests/PhpWord/Tests/Writer/HTMLTest.php | 4 ++-- tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php | 8 +++++--- tests/PhpWord/Tests/Writer/ODText/StyleTest.php | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/PhpWord/Shared/String.php b/src/PhpWord/Shared/String.php index 99b8cca3..1e4504cc 100644 --- a/src/PhpWord/Shared/String.php +++ b/src/PhpWord/Shared/String.php @@ -86,7 +86,7 @@ class String } /** - * Returns unicode array from UTF8 text + * Returns unicode from UTF8 text * * The function is splitted to reduce cyclomatic complexity * @@ -100,7 +100,7 @@ class String } /** - * Returns unicode from UTF8 text + * Returns unicode array from UTF8 text * * @param string $text UTF8 text * @return array diff --git a/src/PhpWord/Writer/ODText/Part/Content.php b/src/PhpWord/Writer/ODText/Part/Content.php index 900edfdd..f16937a0 100644 --- a/src/PhpWord/Writer/ODText/Part/Content.php +++ b/src/PhpWord/Writer/ODText/Part/Content.php @@ -115,12 +115,14 @@ class Content extends AbstractPart $xmlWriter->startElement('office:automatic-styles'); $this->writeTextStyles($xmlWriter); - foreach ($this->autoStyles as $element => $style) { + foreach ($this->autoStyles as $element => $styles) { $writerClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . $element; + foreach ($styles as $style) { - /** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */ - $styleWriter = new $writerClass($xmlWriter, $style); - $styleWriter->write(); + /** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */ + $styleWriter = new $writerClass($xmlWriter, $style); + $styleWriter->write(); + } } $xmlWriter->endElement(); // office:automatic-styles diff --git a/tests/PhpWord/Tests/Writer/HTMLTest.php b/tests/PhpWord/Tests/Writer/HTMLTest.php index 34e9d2bd..0a59b3df 100644 --- a/tests/PhpWord/Tests/Writer/HTMLTest.php +++ b/tests/PhpWord/Tests/Writer/HTMLTest.php @@ -92,8 +92,8 @@ class HTMLTest extends \PHPUnit_Framework_TestCase $textrun = $section->addTextRun('Paragraph'); $textrun->addLink('http://test.com'); $textrun->addImage($localImage); - $textrun->addFootnote(); - $textrun->addEndnote(); + $textrun->addFootnote()->addText('Footnote'); + $textrun->addEndnote()->addText('Endnote'); $section = $phpWord->addSection(); diff --git a/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php b/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php index 03f0cfeb..42c95bcb 100644 --- a/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php +++ b/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php @@ -51,7 +51,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); - $section = $phpWord->addSection(); + $section = $phpWord->addSection(array('colsNum' => 2)); $section->addText($expected); $section->addText('Test font style', 'Font'); $section->addText('Test paragraph style', null, 'Paragraph'); @@ -60,14 +60,14 @@ class ContentTest extends \PHPUnit_Framework_TestCase $section->addTextBreak(); $section->addPageBreak(); $section->addListItem('Test list item'); - $section->addImage($imageSrc); + $section->addImage($imageSrc, array('width' => 50)); $section->addObject($objectSrc); $section->addTOC(); $textrun = $section->addTextRun(); $textrun->addText('Test text run'); - $table = $section->addTable(); + $table = $section->addTable(array('width' => 50)); $cell = $table->addRow()->addCell(); $cell = $table->addRow()->addCell(); $cell->addText('Test'); @@ -82,6 +82,8 @@ class ContentTest extends \PHPUnit_Framework_TestCase $footer = $section->addFooter(); $footer->addPreserveText('{PAGE}'); + $table = $section->addTable('tblStyle')->addRow()->addCell(); + $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); $element = "/office:document-content/office:body/office:text/text:section/text:p"; diff --git a/tests/PhpWord/Tests/Writer/ODText/StyleTest.php b/tests/PhpWord/Tests/Writer/ODText/StyleTest.php index 387accfc..cd5ea0eb 100644 --- a/tests/PhpWord/Tests/Writer/ODText/StyleTest.php +++ b/tests/PhpWord/Tests/Writer/ODText/StyleTest.php @@ -28,7 +28,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase */ public function testEmptyStyles() { - $styles = array('Font', 'Paragraph'); + $styles = array('Font', 'Paragraph', 'Image', 'Section', 'Table'); foreach ($styles as $style) { $objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . $style; $xmlWriter = new XMLWriter();