diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php index 3fa36c23..9d55017a 100644 --- a/src/PhpWord/Element/AbstractElement.php +++ b/src/PhpWord/Element/AbstractElement.php @@ -9,15 +9,13 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\Element; -use PhpOffice\PhpWord\Element\Footnote as FootnoteElement; use PhpOffice\PhpWord\Endnotes; -use PhpOffice\PhpWord\Exception\InvalidObjectException; use PhpOffice\PhpWord\Footnotes; use PhpOffice\PhpWord\Media; -use PhpOffice\PhpWord\Shared\String; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\TOC; +use PhpOffice\PhpWord\Exception\InvalidObjectException; +use PhpOffice\PhpWord\Shared\String; /** * Container abstract class @@ -323,13 +321,13 @@ abstract class AbstractElement * Add footnote element * * @param mixed $paragraphStyle - * @return FootnoteElement + * @return Footnote */ public function addFootnote($paragraphStyle = null) { $this->checkValidity('footnote'); - $footnote = new FootnoteElement($paragraphStyle); + $footnote = new Footnote($paragraphStyle); $rId = Footnotes::addElement($footnote); $footnote->setDocPart('footnote', $this->getDocPartId()); diff --git a/src/PhpWord/Element/Row.php b/src/PhpWord/Element/Row.php index 6897b445..dc4b8a44 100644 --- a/src/PhpWord/Element/Row.php +++ b/src/PhpWord/Element/Row.php @@ -13,6 +13,8 @@ use PhpOffice\PhpWord\Style\Row as RowStyle; /** * Table row element + * + * @since 0.8.0 */ class Row extends AbstractElement { diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index 34b2122d..c28daf7b 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -20,7 +20,7 @@ use PhpOffice\PhpWord\Element\Section; /** * Reader for Word2007 * - * @since 0.10.0 + * @since 0.8.0 * @todo title, list, watermark, checkbox, toc * @todo Partly done: image, object */ diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 4558736b..1ded43c1 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -10,7 +10,9 @@ namespace PhpOffice\PhpWord; /** - * Settings + * PHPWord settings class + * + * @since 0.8.0 */ class Settings { diff --git a/src/PhpWord/Style/Row.php b/src/PhpWord/Style/Row.php index 698adea4..e2a07b85 100644 --- a/src/PhpWord/Style/Row.php +++ b/src/PhpWord/Style/Row.php @@ -11,6 +11,8 @@ namespace PhpOffice\PhpWord\Style; /** * Table row style + * + * @since 0.8.0 */ class Row extends AbstractStyle { diff --git a/src/PhpWord/Template.php b/src/PhpWord/Template.php index bcc6edf3..fd5e9af6 100644 --- a/src/PhpWord/Template.php +++ b/src/PhpWord/Template.php @@ -298,6 +298,7 @@ class Template * Save XML to defined name * * @param string $strFilename + * @since 0.8.0 */ public function saveAs($strFilename) { diff --git a/src/PhpWord/Writer/HTML.php b/src/PhpWord/Writer/HTML.php index 869af1c8..aee3f27a 100644 --- a/src/PhpWord/Writer/HTML.php +++ b/src/PhpWord/Writer/HTML.php @@ -9,6 +9,10 @@ namespace PhpOffice\PhpWord\Writer; +use PhpOffice\PhpWord\Endnotes; +use PhpOffice\PhpWord\Footnotes; +use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Element\Endnote; use PhpOffice\PhpWord\Element\Footnote; use PhpOffice\PhpWord\Element\Image; @@ -22,11 +26,7 @@ use PhpOffice\PhpWord\Element\Text; use PhpOffice\PhpWord\Element\TextBreak; use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\Element\Title; -use PhpOffice\PhpWord\Endnotes; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\Footnotes; -use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -703,12 +703,14 @@ class HTML extends AbstractWriter implements WriterInterface */ private function getBase64ImageData(Image $element) { - $imageData = null; - $imageBinary = null; $source = $element->getSource(); $imageType = $element->getImageType(); + $imageData = null; + $imageBinary = null; + $actualSource = null; - // Get actual source from archive image + // Get actual source from archive image or other source + // Return null if not found if ($element->getSourceType() == Image::SOURCE_ARCHIVE) { $source = substr($source, 6); list($zipFilename, $imageFilename) = explode('#', $source); @@ -723,6 +725,9 @@ class HTML extends AbstractWriter implements WriterInterface } else { $actualSource = $source; } + if (is_null($actualSource)) { + return null; + } // Read image binary data and convert into Base64 if ($element->getSourceType() == Image::SOURCE_GD) { diff --git a/src/PhpWord/Writer/ODText.php b/src/PhpWord/Writer/ODText.php index 6fe47d1f..be1fe459 100755 --- a/src/PhpWord/Writer/ODText.php +++ b/src/PhpWord/Writer/ODText.php @@ -19,6 +19,8 @@ use PhpOffice\PhpWord\Writer\ODText\Styles; /** * ODText writer + * + * @since 0.7.0 */ class ODText extends AbstractWriter implements WriterInterface { diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php index f23b9be2..2452ca7f 100755 --- a/src/PhpWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -28,6 +28,8 @@ use PhpOffice\PhpWord\TOC; /** * RTF writer + * + * @since 0.7.0 */ class RTF extends AbstractWriter implements WriterInterface { diff --git a/src/PhpWord/Writer/Word2007/DocProps.php b/src/PhpWord/Writer/Word2007/DocProps.php index 08a568b9..28102e18 100644 --- a/src/PhpWord/Writer/Word2007/DocProps.php +++ b/src/PhpWord/Writer/Word2007/DocProps.php @@ -10,6 +10,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Exception\Exception; /** * Word2007 document properties part writer @@ -46,7 +47,7 @@ class DocProps extends AbstractWriterPart * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ - public function writeDocPropsCore(PhpWord $phpWord) + public function writeDocPropsCore(PhpWord $phpWord = null) { if (is_null($phpWord)) { throw new Exception("No PhpWord assigned."); diff --git a/src/PhpWord/Writer/Word2007/Document.php b/src/PhpWord/Writer/Word2007/Document.php index 754ec10c..645e5cf2 100644 --- a/src/PhpWord/Writer/Word2007/Document.php +++ b/src/PhpWord/Writer/Word2007/Document.php @@ -9,13 +9,13 @@ namespace PhpOffice\PhpWord\Writer\Word2007; +use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\TOC; use PhpOffice\PhpWord\Element\PageBreak; use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Font; -use PhpOffice\PhpWord\TOC; /** * Word2007 document part writer diff --git a/src/PhpWord/Writer/Word2007/Settings.php b/src/PhpWord/Writer/Word2007/Settings.php index d4640945..918229c1 100644 --- a/src/PhpWord/Writer/Word2007/Settings.php +++ b/src/PhpWord/Writer/Word2007/Settings.php @@ -110,7 +110,7 @@ class Settings extends AbstractWriterPart * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $settingKey - * @param array $settingValue + * @param array|string $settingValue */ protected function writeSetting($xmlWriter, $settingKey, $settingValue) { diff --git a/src/PhpWord/Writer/Word2007/Styles.php b/src/PhpWord/Writer/Word2007/Styles.php index 00c950cd..cea85e46 100644 --- a/src/PhpWord/Writer/Word2007/Styles.php +++ b/src/PhpWord/Writer/Word2007/Styles.php @@ -10,11 +10,12 @@ namespace PhpOffice\PhpWord\Writer\Word2007; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Table; -use PhpOffice\PhpWord\Style; /** * Word2007 styles part writer diff --git a/tests/PhpWord/Tests/Writer/Word2007/DocPropsTest.php b/tests/PhpWord/Tests/Writer/Word2007/DocPropsTest.php new file mode 100644 index 00000000..e4a7d03e --- /dev/null +++ b/tests/PhpWord/Tests/Writer/Word2007/DocPropsTest.php @@ -0,0 +1,44 @@ +writeDocPropsApp(); + } + + /** + * Test write docProps/core.xml with no PhpWord + * + * @expectedException \PhpOffice\PhpWord\Exception\Exception + * @expectedExceptionMessage No PhpWord assigned. + */ + public function testWriteDocPropsCoreNoPhpWord() + { + $object = new DocProps(); + $object->writeDocPropsCore(); + } +} diff --git a/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php index fa11638e..6b783dea 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php @@ -11,6 +11,7 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Tests\TestHelperDOCX; +use PhpOffice\PhpWord\Writer\Word2007\Document; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Document @@ -27,6 +28,18 @@ class DocumentTest extends \PHPUnit_Framework_TestCase TestHelperDOCX::clear(); } + /** + * Test write word/document.xm with no PhpWord + * + * @expectedException \PhpOffice\PhpWord\Exception\Exception + * @expectedExceptionMessage No PhpWord assigned. + */ + public function testWriteDocumentNoPhpWord() + { + $object = new Document(); + $object->writeDocument(); + } + /** * Write end section page numbering */ diff --git a/tests/PhpWord/Tests/Writer/Word2007/NumberingTest.php b/tests/PhpWord/Tests/Writer/Word2007/NumberingTest.php new file mode 100644 index 00000000..c6a6f7a7 --- /dev/null +++ b/tests/PhpWord/Tests/Writer/Word2007/NumberingTest.php @@ -0,0 +1,68 @@ +addNumberingStyle( + 'numStyle', + array( + 'type' => 'multilevel', + 'levels' => array( + array( + 'start' => 1, + 'format' => 'decimal', + 'restart' => 1, + 'suffix' => 'space', + 'text' => '%1.', + 'align' => 'left', + 'left' => 360, + 'hanging' => 360, + 'tabPos' => 360, + 'font' => 'Arial', + 'hint' => 'default', + ), + ) + ) + ); + + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + + $this->assertTrue($doc->elementExists('/w:numbering/w:abstractNum', $xmlFile)); + } +} diff --git a/tests/PhpWord/Tests/Writer/Word2007/StylesTest.php b/tests/PhpWord/Tests/Writer/Word2007/StylesTest.php index 70ebe7cf..0d333601 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/StylesTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/StylesTest.php @@ -9,6 +9,7 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Writer\Word2007\Styles; use PhpOffice\PhpWord\Tests\TestHelperDOCX; /** @@ -27,6 +28,18 @@ class StylesTest extends \PHPUnit_Framework_TestCase TestHelperDOCX::clear(); } + /** + * Test construct with no PhpWord + * + * @expectedException \PhpOffice\PhpWord\Exception\Exception + * @expectedExceptionMessage No PhpWord assigned. + */ + public function testConstructNoPhpWord() + { + $object = new Styles(); + $object->writeStyles(); + } + /** * Test write styles */