QA: Additional tests for Word2007 writer
This commit is contained in:
parent
306c354b2c
commit
4db75c37a9
@ -9,15 +9,13 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Element\Element;
|
|
||||||
use PhpOffice\PhpWord\Element\Footnote as FootnoteElement;
|
|
||||||
use PhpOffice\PhpWord\Endnotes;
|
use PhpOffice\PhpWord\Endnotes;
|
||||||
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
|
||||||
use PhpOffice\PhpWord\Footnotes;
|
use PhpOffice\PhpWord\Footnotes;
|
||||||
use PhpOffice\PhpWord\Media;
|
use PhpOffice\PhpWord\Media;
|
||||||
use PhpOffice\PhpWord\Shared\String;
|
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
use PhpOffice\PhpWord\TOC;
|
use PhpOffice\PhpWord\TOC;
|
||||||
|
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
||||||
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container abstract class
|
* Container abstract class
|
||||||
@ -323,13 +321,13 @@ abstract class AbstractElement
|
|||||||
* Add footnote element
|
* Add footnote element
|
||||||
*
|
*
|
||||||
* @param mixed $paragraphStyle
|
* @param mixed $paragraphStyle
|
||||||
* @return FootnoteElement
|
* @return Footnote
|
||||||
*/
|
*/
|
||||||
public function addFootnote($paragraphStyle = null)
|
public function addFootnote($paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->checkValidity('footnote');
|
$this->checkValidity('footnote');
|
||||||
|
|
||||||
$footnote = new FootnoteElement($paragraphStyle);
|
$footnote = new Footnote($paragraphStyle);
|
||||||
$rId = Footnotes::addElement($footnote);
|
$rId = Footnotes::addElement($footnote);
|
||||||
|
|
||||||
$footnote->setDocPart('footnote', $this->getDocPartId());
|
$footnote->setDocPart('footnote', $this->getDocPartId());
|
||||||
|
|||||||
@ -13,6 +13,8 @@ use PhpOffice\PhpWord\Style\Row as RowStyle;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Table row element
|
* Table row element
|
||||||
|
*
|
||||||
|
* @since 0.8.0
|
||||||
*/
|
*/
|
||||||
class Row extends AbstractElement
|
class Row extends AbstractElement
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,7 +20,7 @@ use PhpOffice\PhpWord\Element\Section;
|
|||||||
/**
|
/**
|
||||||
* Reader for Word2007
|
* Reader for Word2007
|
||||||
*
|
*
|
||||||
* @since 0.10.0
|
* @since 0.8.0
|
||||||
* @todo title, list, watermark, checkbox, toc
|
* @todo title, list, watermark, checkbox, toc
|
||||||
* @todo Partly done: image, object
|
* @todo Partly done: image, object
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -10,7 +10,9 @@
|
|||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings
|
* PHPWord settings class
|
||||||
|
*
|
||||||
|
* @since 0.8.0
|
||||||
*/
|
*/
|
||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,6 +11,8 @@ namespace PhpOffice\PhpWord\Style;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Table row style
|
* Table row style
|
||||||
|
*
|
||||||
|
* @since 0.8.0
|
||||||
*/
|
*/
|
||||||
class Row extends AbstractStyle
|
class Row extends AbstractStyle
|
||||||
{
|
{
|
||||||
|
|||||||
@ -298,6 +298,7 @@ class Template
|
|||||||
* Save XML to defined name
|
* Save XML to defined name
|
||||||
*
|
*
|
||||||
* @param string $strFilename
|
* @param string $strFilename
|
||||||
|
* @since 0.8.0
|
||||||
*/
|
*/
|
||||||
public function saveAs($strFilename)
|
public function saveAs($strFilename)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer;
|
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\Endnote;
|
||||||
use PhpOffice\PhpWord\Element\Footnote;
|
use PhpOffice\PhpWord\Element\Footnote;
|
||||||
use PhpOffice\PhpWord\Element\Image;
|
use PhpOffice\PhpWord\Element\Image;
|
||||||
@ -22,11 +26,7 @@ use PhpOffice\PhpWord\Element\Text;
|
|||||||
use PhpOffice\PhpWord\Element\TextBreak;
|
use PhpOffice\PhpWord\Element\TextBreak;
|
||||||
use PhpOffice\PhpWord\Element\TextRun;
|
use PhpOffice\PhpWord\Element\TextRun;
|
||||||
use PhpOffice\PhpWord\Element\Title;
|
use PhpOffice\PhpWord\Element\Title;
|
||||||
use PhpOffice\PhpWord\Endnotes;
|
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
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\Font;
|
||||||
use PhpOffice\PhpWord\Style\Paragraph;
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
@ -703,12 +703,14 @@ class HTML extends AbstractWriter implements WriterInterface
|
|||||||
*/
|
*/
|
||||||
private function getBase64ImageData(Image $element)
|
private function getBase64ImageData(Image $element)
|
||||||
{
|
{
|
||||||
$imageData = null;
|
|
||||||
$imageBinary = null;
|
|
||||||
$source = $element->getSource();
|
$source = $element->getSource();
|
||||||
$imageType = $element->getImageType();
|
$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) {
|
if ($element->getSourceType() == Image::SOURCE_ARCHIVE) {
|
||||||
$source = substr($source, 6);
|
$source = substr($source, 6);
|
||||||
list($zipFilename, $imageFilename) = explode('#', $source);
|
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||||
@ -723,6 +725,9 @@ class HTML extends AbstractWriter implements WriterInterface
|
|||||||
} else {
|
} else {
|
||||||
$actualSource = $source;
|
$actualSource = $source;
|
||||||
}
|
}
|
||||||
|
if (is_null($actualSource)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Read image binary data and convert into Base64
|
// Read image binary data and convert into Base64
|
||||||
if ($element->getSourceType() == Image::SOURCE_GD) {
|
if ($element->getSourceType() == Image::SOURCE_GD) {
|
||||||
|
|||||||
@ -19,6 +19,8 @@ use PhpOffice\PhpWord\Writer\ODText\Styles;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ODText writer
|
* ODText writer
|
||||||
|
*
|
||||||
|
* @since 0.7.0
|
||||||
*/
|
*/
|
||||||
class ODText extends AbstractWriter implements WriterInterface
|
class ODText extends AbstractWriter implements WriterInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,6 +28,8 @@ use PhpOffice\PhpWord\TOC;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* RTF writer
|
* RTF writer
|
||||||
|
*
|
||||||
|
* @since 0.7.0
|
||||||
*/
|
*/
|
||||||
class RTF extends AbstractWriter implements WriterInterface
|
class RTF extends AbstractWriter implements WriterInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
namespace PhpOffice\PhpWord\Writer\Word2007;
|
namespace PhpOffice\PhpWord\Writer\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Word2007 document properties part writer
|
* Word2007 document properties part writer
|
||||||
@ -46,7 +47,7 @@ class DocProps extends AbstractWriterPart
|
|||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||||
*/
|
*/
|
||||||
public function writeDocPropsCore(PhpWord $phpWord)
|
public function writeDocPropsCore(PhpWord $phpWord = null)
|
||||||
{
|
{
|
||||||
if (is_null($phpWord)) {
|
if (is_null($phpWord)) {
|
||||||
throw new Exception("No PhpWord assigned.");
|
throw new Exception("No PhpWord assigned.");
|
||||||
|
|||||||
@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007;
|
namespace PhpOffice\PhpWord\Writer\Word2007;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\TOC;
|
||||||
use PhpOffice\PhpWord\Element\PageBreak;
|
use PhpOffice\PhpWord\Element\PageBreak;
|
||||||
use PhpOffice\PhpWord\Element\Section;
|
use PhpOffice\PhpWord\Element\Section;
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
|
||||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
use PhpOffice\PhpWord\Style\Font;
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpOffice\PhpWord\TOC;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Word2007 document part writer
|
* Word2007 document part writer
|
||||||
|
|||||||
@ -110,7 +110,7 @@ class Settings extends AbstractWriterPart
|
|||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||||
* @param string $settingKey
|
* @param string $settingKey
|
||||||
* @param array $settingValue
|
* @param array|string $settingValue
|
||||||
*/
|
*/
|
||||||
protected function writeSetting($xmlWriter, $settingKey, $settingValue)
|
protected function writeSetting($xmlWriter, $settingKey, $settingValue)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -10,11 +10,12 @@
|
|||||||
namespace PhpOffice\PhpWord\Writer\Word2007;
|
namespace PhpOffice\PhpWord\Writer\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Style;
|
||||||
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
use PhpOffice\PhpWord\Style\Font;
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpOffice\PhpWord\Style\Paragraph;
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
use PhpOffice\PhpWord\Style\Table;
|
use PhpOffice\PhpWord\Style\Table;
|
||||||
use PhpOffice\PhpWord\Style;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Word2007 styles part writer
|
* Word2007 styles part writer
|
||||||
|
|||||||
44
tests/PhpWord/Tests/Writer/Word2007/DocPropsTest.php
Normal file
44
tests/PhpWord/Tests/Writer/Word2007/DocPropsTest.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2014 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Writer\Word2007\DocProps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\Word2007\DocProps
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\DocProps
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class DocPropsTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test write docProps/app.xml with no PhpWord
|
||||||
|
*
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exception\Exception
|
||||||
|
* @expectedExceptionMessage No PhpWord assigned.
|
||||||
|
*/
|
||||||
|
public function testWriteDocPropsAppNoPhpWord()
|
||||||
|
{
|
||||||
|
$object = new DocProps();
|
||||||
|
$object->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,7 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
|||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Style\Font;
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||||
|
use PhpOffice\PhpWord\Writer\Word2007\Document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for 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();
|
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
|
* Write end section page numbering
|
||||||
*/
|
*/
|
||||||
|
|||||||
68
tests/PhpWord/Tests/Writer/Word2007/NumberingTest.php
Normal file
68
tests/PhpWord/Tests/Writer/Word2007/NumberingTest.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2014 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Style\Numbering as NumberingStyle;
|
||||||
|
use PhpOffice\PhpWord\Style\NumberingLevel;
|
||||||
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||||
|
use PhpOffice\PhpWord\Writer\Word2007\Numbering;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\Word2007\Numbering
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Numbering
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @since 0.10.0
|
||||||
|
*/
|
||||||
|
class NumberingTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Executed before each method of the class
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
TestHelperDOCX::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write footnotes
|
||||||
|
*/
|
||||||
|
public function testWriteNumbering()
|
||||||
|
{
|
||||||
|
$xmlFile = 'word/numbering.xml';
|
||||||
|
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@
|
|||||||
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Writer\Word2007\Styles;
|
||||||
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,6 +28,18 @@ class StylesTest extends \PHPUnit_Framework_TestCase
|
|||||||
TestHelperDOCX::clear();
|
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
|
* Test write styles
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user