Merge branch 'develop' into html
This commit is contained in:
commit
15ca8f294c
|
|
@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
||||||
|
|
||||||
## 0.10.0 - Not yet released
|
## 0.10.0 - Not yet released
|
||||||
|
|
||||||
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML writer is initiated.
|
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML support is enabled.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
|
@ -31,11 +31,13 @@ This release marked heavy refactorings on internal code structure with the creat
|
||||||
- Endnote: Ability to add endnotes - @ivanlanin
|
- Endnote: Ability to add endnotes - @ivanlanin
|
||||||
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
|
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
|
||||||
- ODT Writer: Basic table writing support - @ivanlanin
|
- ODT Writer: Basic table writing support - @ivanlanin
|
||||||
|
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
|
||||||
- HTML Writer: Basic HTML writer initiated - @ivanlanin
|
- HTML Writer: Basic HTML writer initiated - @ivanlanin
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
|
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
|
||||||
|
- Documentation : Error in a fonction - @theBeerNut GH-195
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|
@ -64,6 +66,8 @@ This release marked heavy refactorings on internal code structure with the creat
|
||||||
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
|
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
|
||||||
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
|
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
|
||||||
- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
|
- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
|
||||||
|
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
|
||||||
|
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
|
||||||
|
|
||||||
## 0.9.1 - 27 Mar 2014
|
## 0.9.1 - 27 Mar 2014
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ name. Use the following functions:
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
$properties = $phpWord->getProperties();
|
$properties = $phpWord->getDocumentProperties();
|
||||||
$properties->setCreator('My name');
|
$properties->setCreator('My name');
|
||||||
$properties->setCompany('My factory');
|
$properties->setCompany('My factory');
|
||||||
$properties->setTitle('My title');
|
$properties->setTitle('My title');
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,27 @@ $section = $phpWord->addSection();
|
||||||
$section->addText('Local image without any styles:');
|
$section->addText('Local image without any styles:');
|
||||||
$section->addImage('resources/_mars.jpg');
|
$section->addImage('resources/_mars.jpg');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
//
|
|
||||||
$section->addText('Local image with styles:');
|
$section->addText('Local image with styles:');
|
||||||
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
|
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
|
// Remote image
|
||||||
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
||||||
$section->addText("Remote image from: {$source}");
|
$section->addText("Remote image from: {$source}");
|
||||||
$section->addImage($source);
|
$section->addImage($source);
|
||||||
|
|
||||||
|
//Wrapping style
|
||||||
|
$text = str_repeat('Hello World! ', 15);
|
||||||
|
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
||||||
|
foreach ($wrappingStyles as $wrappingStyle) {
|
||||||
|
$section->addTextBreak(5);
|
||||||
|
$section->addText('Wrapping style ' . $wrappingStyle);
|
||||||
|
$section->addImage('resources/_earth.jpg', array('marginTop' => -1, 'marginLeft' => 1,
|
||||||
|
'width' => 80, 'height' => 80, 'wrappingStyle' => $wrappingStyle));
|
||||||
|
$section->addText($text);
|
||||||
|
}
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
if (!CLI) {
|
if (!CLI) {
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,9 @@ if ($handle = opendir('.')) {
|
||||||
/**
|
/**
|
||||||
* Get results
|
* Get results
|
||||||
*
|
*
|
||||||
* @param array $writers
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
|
* @param array $writers
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function write($phpWord, $filename, $writers)
|
function write($phpWord, $filename, $writers)
|
||||||
|
|
|
||||||
|
|
@ -131,9 +131,18 @@ class Image extends AbstractElement
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
$this->isWatermark = $isWatermark;
|
$this->isWatermark = $isWatermark;
|
||||||
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
||||||
if ($this->style->getWidth() == null && $this->style->getHeight() == null) {
|
$styleWidth = $this->style->getWidth();
|
||||||
$this->style->setWidth($imgData[0]);
|
$styleHeight = $this->style->getHeight();
|
||||||
$this->style->setHeight($imgData[1]);
|
list($actualWidth, $actualHeight) = $imgData;
|
||||||
|
if (!($styleWidth && $styleHeight)) {
|
||||||
|
if ($styleWidth == null && $styleHeight == null) {
|
||||||
|
$this->style->setWidth($actualWidth);
|
||||||
|
$this->style->setHeight($actualHeight);
|
||||||
|
} elseif ($styleWidth) {
|
||||||
|
$this->style->setHeight($actualHeight * ($styleWidth / $actualWidth));
|
||||||
|
} else {
|
||||||
|
$this->style->setWidth($actualWidth * ($styleHeight / $actualHeight));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->setImageFunctions();
|
$this->setImageFunctions();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
||||||
if ($zip->open($filename) === true) {
|
if ($zip->open($filename) === true) {
|
||||||
for ($i = 0; $i < $zip->numFiles; $i++) {
|
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||||
$xmlFile = $zip->getNameIndex($i);
|
$xmlFile = $zip->getNameIndex($i);
|
||||||
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath) {
|
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath && (substr($xmlFile, -1)) != '/') {
|
||||||
$docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
|
$docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
|
||||||
$this->rels[$docPart] = $this->getRels($filename, $xmlFile, 'word/');
|
$this->rels[$docPart] = $this->getRels($filename, $xmlFile, 'word/');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,8 +218,7 @@ class ZipArchive
|
||||||
public function getNameIndex($index)
|
public function getNameIndex($index)
|
||||||
{
|
{
|
||||||
$list = $this->zip->listContent();
|
$list = $this->zip->listContent();
|
||||||
$listCount = count($list);
|
if (isset($list[$index])) {
|
||||||
if ($index <= $listCount) {
|
|
||||||
return $list[$index]['filename'];
|
return $list[$index]['filename'];
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -105,13 +105,12 @@ abstract class AbstractStyle
|
||||||
/**
|
/**
|
||||||
* Set integer value
|
* Set integer value
|
||||||
*
|
*
|
||||||
* @param integer|null $value
|
* @param mixed $value
|
||||||
* @param integer|null $default
|
* @param integer|null $default
|
||||||
* @return integer|null
|
* @return integer|null
|
||||||
*/
|
*/
|
||||||
protected function setIntVal($value, $default = null)
|
protected function setIntVal($value, $default = null)
|
||||||
{
|
{
|
||||||
$value = intval($value);
|
|
||||||
if (!is_int($value)) {
|
if (!is_int($value)) {
|
||||||
$value = $default;
|
$value = $default;
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +127,6 @@ abstract class AbstractStyle
|
||||||
*/
|
*/
|
||||||
protected function setFloatVal($value, $default = null)
|
protected function setFloatVal($value, $default = null)
|
||||||
{
|
{
|
||||||
$value = floatval($value);
|
|
||||||
if (!is_float($value)) {
|
if (!is_float($value)) {
|
||||||
$value = $default;
|
$value = $default;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,8 @@ class ListItem extends AbstractStyle
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set numbering style name
|
* Set numbering style name
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
public function setNumStyle($value)
|
public function setNumStyle($value)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -427,25 +427,22 @@ class Base extends AbstractWriterPart
|
||||||
$marginTop = $style->getMarginTop();
|
$marginTop = $style->getMarginTop();
|
||||||
$marginLeft = $style->getMarginLeft();
|
$marginLeft = $style->getMarginLeft();
|
||||||
$wrappingStyle = $style->getWrappingStyle();
|
$wrappingStyle = $style->getWrappingStyle();
|
||||||
|
$w10wrapType = null;
|
||||||
|
|
||||||
if (!$withoutP) {
|
if (!$withoutP) {
|
||||||
$xmlWriter->startElement('w:p');
|
$xmlWriter->startElement('w:p');
|
||||||
|
|
||||||
if (!is_null($align)) {
|
if (!is_null($align)) {
|
||||||
$xmlWriter->startElement('w:pPr');
|
$xmlWriter->startElement('w:pPr');
|
||||||
$xmlWriter->startElement('w:jc');
|
$xmlWriter->startElement('w:jc');
|
||||||
$xmlWriter->writeAttribute('w:val', $align);
|
$xmlWriter->writeAttribute('w:val', $align);
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement(); // w:jc
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement(); // w:pPr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
|
|
||||||
$xmlWriter->startElement('w:pict');
|
$xmlWriter->startElement('w:pict');
|
||||||
|
|
||||||
$xmlWriter->startElement('v:shape');
|
$xmlWriter->startElement('v:shape');
|
||||||
$xmlWriter->writeAttribute('type', '#_x0000_t75');
|
$xmlWriter->writeAttribute('type', '#_x0000_t75');
|
||||||
|
|
||||||
$imgStyle = '';
|
$imgStyle = '';
|
||||||
if (null !== $width) {
|
if (null !== $width) {
|
||||||
$imgStyle .= 'width:' . $width . 'px;';
|
$imgStyle .= 'width:' . $width . 'px;';
|
||||||
|
|
@ -459,33 +456,38 @@ class Base extends AbstractWriterPart
|
||||||
if (null !== $marginLeft) {
|
if (null !== $marginLeft) {
|
||||||
$imgStyle .= 'margin-left:' . $marginLeft . 'in;';
|
$imgStyle .= 'margin-left:' . $marginLeft . 'in;';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($wrappingStyle) {
|
switch ($wrappingStyle) {
|
||||||
case ImageStyle::WRAPPING_STYLE_BEHIND:
|
case ImageStyle::WRAPPING_STYLE_BEHIND:
|
||||||
$imgStyle .= 'position:absolute;z-index:-251658752;';
|
$imgStyle .= 'position:absolute;z-index:-251658752;';
|
||||||
break;
|
break;
|
||||||
case ImageStyle::WRAPPING_STYLE_SQUARE:
|
case ImageStyle::WRAPPING_STYLE_INFRONT:
|
||||||
$imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
|
$imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
|
||||||
break;
|
break;
|
||||||
case ImageStyle::WRAPPING_STYLE_TIGHT:
|
case ImageStyle::WRAPPING_STYLE_SQUARE:
|
||||||
$imgStyle .= 'position:absolute;z-index:251659264;mso-wrap-edited:f;mso-position-horizontal:absolute;mso-position-vertical:absolute';
|
$imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
|
||||||
|
$w10wrapType = 'square';
|
||||||
break;
|
break;
|
||||||
case ImageStyle::WRAPPING_STYLE_INFRONT:
|
case ImageStyle::WRAPPING_STYLE_TIGHT:
|
||||||
$imgStyle .= 'position:absolute;zz-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
|
$imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
|
||||||
|
$w10wrapType = 'tight';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$xmlWriter->writeAttribute('style', $imgStyle);
|
$xmlWriter->writeAttribute('style', $imgStyle);
|
||||||
|
|
||||||
$xmlWriter->startElement('v:imagedata');
|
$xmlWriter->startElement('v:imagedata');
|
||||||
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
|
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
|
||||||
$xmlWriter->writeAttribute('o:title', '');
|
$xmlWriter->writeAttribute('o:title', '');
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement(); // v:imagedata
|
||||||
$xmlWriter->endElement();
|
|
||||||
|
|
||||||
$xmlWriter->endElement();
|
if (!is_null($w10wrapType)) {
|
||||||
|
$xmlWriter->startElement('w10:wrap');
|
||||||
|
$xmlWriter->writeAttribute('type', $w10wrapType);
|
||||||
|
$xmlWriter->endElement(); // w10:wrap
|
||||||
|
}
|
||||||
|
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement(); // v:shape
|
||||||
|
$xmlWriter->endElement(); // w:pict
|
||||||
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
if (!$withoutP) {
|
if (!$withoutP) {
|
||||||
$xmlWriter->endElement(); // w:p
|
$xmlWriter->endElement(); // w:p
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?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\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Element\AbstractElement
|
||||||
|
*
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class AbstractElementTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test set/get element index
|
||||||
|
*/
|
||||||
|
public function testElementIndex()
|
||||||
|
{
|
||||||
|
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
|
||||||
|
$ival = rand(0, 100);
|
||||||
|
$stub->setElementIndex($ival);
|
||||||
|
$this->assertEquals($stub->getElementIndex(), $ival);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test set/get element unique Id
|
||||||
|
*/
|
||||||
|
public function testElementId()
|
||||||
|
{
|
||||||
|
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
|
||||||
|
$stub->setElementId();
|
||||||
|
$this->assertEquals(strlen($stub->getElementId()), 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -94,6 +94,14 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test set wrapping style
|
||||||
|
*/
|
||||||
|
public function testStyleWrappingStyle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get relation Id
|
* Get relation Id
|
||||||
*/
|
*/
|
||||||
|
|
@ -121,7 +129,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testPNG()
|
public function testPNG()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/firefox.png";
|
$src = __DIR__ . "/../_files/images/firefox.png";
|
||||||
$oImage = new Image($src);
|
$oImage = new Image($src, array('width' => 100));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
|
||||||
$this->assertEquals($oImage->getSource(), $src);
|
$this->assertEquals($oImage->getSource(), $src);
|
||||||
|
|
@ -138,7 +146,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testGIF()
|
public function testGIF()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/mario.gif";
|
$src = __DIR__ . "/../_files/images/mario.gif";
|
||||||
$oImage = new Image($src);
|
$oImage = new Image($src, array('height' => 100));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
|
||||||
$this->assertEquals($oImage->getSource(), $src);
|
$this->assertEquals($oImage->getSource(), $src);
|
||||||
|
|
@ -202,4 +210,14 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$object = new Image('test.php');
|
$object = new Image('test.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test PCX Image and Memory
|
||||||
|
*
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
|
||||||
|
*/
|
||||||
|
public function testPcxImage()
|
||||||
|
{
|
||||||
|
$object = new Image('http://samples.libav.org/image-samples/RACECAR.BMP');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,11 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testStyleArray()
|
public function testStyleArray()
|
||||||
{
|
{
|
||||||
$oTable = new Table(
|
$oTable = new Table('section', 1, array(
|
||||||
'section',
|
'borderSize' => 6,
|
||||||
1,
|
'borderColor' => '006699',
|
||||||
array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)
|
'cellMargin' => 80
|
||||||
);
|
));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle());
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testWidth()
|
public function testWidth()
|
||||||
{
|
{
|
||||||
$oTable = new Table('section', 1);
|
$oTable = new Table('section', 1);
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
$oTable->setWidth($iVal);
|
$oTable->setWidth($iVal);
|
||||||
$this->assertEquals($oTable->getWidth(), $iVal);
|
$this->assertEquals($oTable->getWidth(), $iVal);
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testRow()
|
public function testRow()
|
||||||
{
|
{
|
||||||
$oTable = new Table('section', 1);
|
$oTable = new Table('section', 1);
|
||||||
$element = $oTable->addRow();
|
$element = $oTable->addRow();
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element);
|
||||||
$this->assertCount(1, $oTable->getRows());
|
$this->assertCount(1, $oTable->getRows());
|
||||||
|
|
@ -89,4 +89,18 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
||||||
$element = $oTable->addCell();
|
$element = $oTable->addCell();
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add cell
|
||||||
|
*/
|
||||||
|
public function testCountColumns()
|
||||||
|
{
|
||||||
|
$oTable = new Table('section', 1);
|
||||||
|
$oTable->addRow();
|
||||||
|
$element = $oTable->addCell();
|
||||||
|
$this->assertEquals($oTable->countColumns(), 1);
|
||||||
|
$element = $oTable->addCell();
|
||||||
|
$element = $oTable->addCell();
|
||||||
|
$this->assertEquals($oTable->countColumns(), 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?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\Shared;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Shared\XMLReader
|
||||||
|
*
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @since 0.10.0
|
||||||
|
*/
|
||||||
|
class XMLReaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test get DOMDocument from ZipArchive returns false
|
||||||
|
*/
|
||||||
|
public function testGetDomFromZipReturnsFalse()
|
||||||
|
{
|
||||||
|
$filename = __DIR__ . "/../_files/documents/reader.docx.zip";
|
||||||
|
$object = new XMLReader();
|
||||||
|
$this->assertFalse($object->getDomFromZip($filename, 'yadayadaya'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get elements returns empty
|
||||||
|
*/
|
||||||
|
public function testGetElementsReturnsEmpty()
|
||||||
|
{
|
||||||
|
$object = new XMLReader();
|
||||||
|
$this->assertEquals(array(), $object->getElements('w:document'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get element returns null
|
||||||
|
*/
|
||||||
|
public function testGetElementReturnsNull()
|
||||||
|
{
|
||||||
|
$filename = __DIR__ . "/../_files/documents/reader.docx.zip";
|
||||||
|
|
||||||
|
$object = new XMLReader();
|
||||||
|
$object->getDomFromZip($filename, '[Content_Types].xml');
|
||||||
|
$element = $object->getElements('*')->item(0);
|
||||||
|
|
||||||
|
$this->assertNull($object->getElement('yadayadaya', $element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,14 +24,51 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAdd()
|
public function testAdd()
|
||||||
{
|
{
|
||||||
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
|
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
|
||||||
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
|
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
|
||||||
$object = new ZipArchive();
|
$object = new ZipArchive();
|
||||||
$object->open($zipFile);
|
$object->open($zipFile);
|
||||||
$object->addFile($existingFile, 'xls/new.xls');
|
$object->addFile($existingFile, 'xls/new.xls');
|
||||||
$object->addFromString('content/string.txt', 'Test');
|
$object->addFromString('content/string.txt', 'Test');
|
||||||
|
|
||||||
$this->assertTrue($object->locateName('xls/new.xls'));
|
$this->assertTrue($object->locateName('xls/new.xls'));
|
||||||
$this->assertEquals('Test', $object->getFromName('content/string.txt'));
|
$this->assertEquals('Test', $object->getFromName('content/string.txt'));
|
||||||
|
$this->assertEquals('Test', $object->getFromName('/content/string.txt'));
|
||||||
|
|
||||||
|
unlink($zipFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test find if a given name exists in the archive
|
||||||
|
*/
|
||||||
|
public function testLocate()
|
||||||
|
{
|
||||||
|
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
|
||||||
|
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
|
||||||
|
$object = new ZipArchive();
|
||||||
|
$object->open($zipFile);
|
||||||
|
$object->addFile($existingFile, 'xls/new.xls');
|
||||||
|
$object->addFromString('content/string.txt', 'Test');
|
||||||
|
|
||||||
|
$this->assertEquals(1, $object->locateName('content/string.txt'));
|
||||||
|
$this->assertFalse($object->locateName('blablabla'));
|
||||||
|
|
||||||
|
unlink($zipFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test returns the name of an entry using its index
|
||||||
|
*/
|
||||||
|
public function testNameIndex()
|
||||||
|
{
|
||||||
|
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
|
||||||
|
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
|
||||||
|
$object = new ZipArchive();
|
||||||
|
$object->open($zipFile);
|
||||||
|
$object->addFile($existingFile, 'xls/new.xls');
|
||||||
|
$object->addFromString('content/string.txt', 'Test');
|
||||||
|
|
||||||
|
$this->assertFalse($object->getNameIndex(-1));
|
||||||
|
$this->assertEquals('content/string.txt', $object->getNameIndex(1));
|
||||||
|
|
||||||
unlink($zipFile);
|
unlink($zipFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?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\Style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Style\AbstractStyle
|
||||||
|
*
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class AbstractStyleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test set style by array
|
||||||
|
*/
|
||||||
|
public function testSetStyleByArray()
|
||||||
|
{
|
||||||
|
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
|
||||||
|
$stub->setStyleByArray(array('index' => 1));
|
||||||
|
|
||||||
|
$this->assertEquals(1, $stub->getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test setBoolVal, setIntVal, setFloatVal, setEnumVal with normal value
|
||||||
|
*/
|
||||||
|
public function testSetValNormal()
|
||||||
|
{
|
||||||
|
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
|
||||||
|
|
||||||
|
$this->assertEquals(true, self::callProtectedMethod($stub, 'setBoolVal', array(true, false)));
|
||||||
|
$this->assertEquals(12, self::callProtectedMethod($stub, 'setIntVal', array(12, 200)));
|
||||||
|
$this->assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', array(871.1, 2.1)));
|
||||||
|
$this->assertEquals('a', self::callProtectedMethod($stub, 'setEnumVal', array('a', array('a', 'b'), 'b')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test setBoolVal, setIntVal, setFloatVal, setEnumVal with default value
|
||||||
|
*/
|
||||||
|
public function testSetValDefault()
|
||||||
|
{
|
||||||
|
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
|
||||||
|
|
||||||
|
$this->assertEquals(false, self::callProtectedMethod($stub, 'setBoolVal', array('a', false)));
|
||||||
|
$this->assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', array('foo', 200)));
|
||||||
|
$this->assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', array('foo', 2.1)));
|
||||||
|
$this->assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', array('z', array('a', 'b'), 'b')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to call protected method
|
||||||
|
*/
|
||||||
|
public static function callProtectedMethod($object, $method, array $args = array())
|
||||||
|
{
|
||||||
|
$class = new \ReflectionClass(get_class($object));
|
||||||
|
$method = $class->getMethod($method);
|
||||||
|
$method->setAccessible(true);
|
||||||
|
return $method->invokeArgs($object, $args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
'align' => 'left',
|
'align' => 'left',
|
||||||
'marginTop' => 240,
|
'marginTop' => 240,
|
||||||
'marginLeft' => 240,
|
'marginLeft' => 240,
|
||||||
'wrappingStyle' => 'inline',
|
'wrappingStyle' => 'inline'
|
||||||
);
|
);
|
||||||
foreach ($properties as $key => $value) {
|
foreach ($properties as $key => $value) {
|
||||||
$set = "set{$key}";
|
$set = "set{$key}";
|
||||||
|
|
@ -54,7 +54,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
'height' => 200,
|
'height' => 200,
|
||||||
'align' => 'left',
|
'align' => 'left',
|
||||||
'marginTop' => 240,
|
'marginTop' => 240,
|
||||||
'marginLeft' => 240,
|
'marginLeft' => 240
|
||||||
);
|
);
|
||||||
foreach ($properties as $key => $value) {
|
foreach ($properties as $key => $value) {
|
||||||
$get = "get{$key}";
|
$get = "get{$key}";
|
||||||
|
|
|
||||||
|
|
@ -53,4 +53,16 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
||||||
$object->setListType($value);
|
$object->setListType($value);
|
||||||
$this->assertEquals($value, $object->getListType());
|
$this->assertEquals($value, $object->getListType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test set/get numbering style name
|
||||||
|
*/
|
||||||
|
public function testSetGetNumStyle()
|
||||||
|
{
|
||||||
|
$expected = 'List Name';
|
||||||
|
|
||||||
|
$object = new ListItem();
|
||||||
|
$object->setNumStyle($expected);
|
||||||
|
$this->assertEquals($expected, $object->getNumStyle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::_writeText
|
* Test write text element
|
||||||
*/
|
*/
|
||||||
public function testWriteText()
|
public function testWriteText()
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +49,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::_writeTextRun
|
* Test write textrun element
|
||||||
*/
|
*/
|
||||||
public function testWriteTextRun()
|
public function testWriteTextRun()
|
||||||
{
|
{
|
||||||
|
|
@ -74,7 +74,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::_writeLink
|
* Test write link element
|
||||||
*/
|
*/
|
||||||
public function testWriteLink()
|
public function testWriteLink()
|
||||||
{
|
{
|
||||||
|
|
@ -97,7 +97,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::_writePreserveText
|
* Test write preserve text element
|
||||||
*/
|
*/
|
||||||
public function testWritePreserveText()
|
public function testWritePreserveText()
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +121,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::_writeTextBreak
|
* Test write text break
|
||||||
*/
|
*/
|
||||||
public function testWriteTextBreak()
|
public function testWriteTextBreak()
|
||||||
{
|
{
|
||||||
|
|
@ -146,30 +146,93 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::_writeParagraphStyle
|
* covers ::_writeImage
|
||||||
*/
|
*/
|
||||||
public function testWriteParagraphStyleAlign()
|
public function testWriteImage()
|
||||||
{
|
{
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
$styles = array('align' => 'left', 'width' => 40, 'height' => 40, 'marginTop' => -1, 'marginLeft' => -1);
|
||||||
|
$wraps = array('inline', 'behind', 'infront', 'square', 'tight');
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
foreach ($wraps as $wrap) {
|
||||||
$section->addText('This is my text', null, array('align' => 'right'));
|
$styles['wrappingStyle'] = $wrap;
|
||||||
|
$section->addImage(__DIR__ . "/../../_files/images/earth.jpg", $styles);
|
||||||
|
}
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:jc');
|
|
||||||
|
|
||||||
$this->assertEquals('right', $element->getAttribute('w:val'));
|
// behind
|
||||||
|
$element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape');
|
||||||
|
$style = $element->getAttribute('style');
|
||||||
|
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
|
||||||
|
|
||||||
|
// square
|
||||||
|
$element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap');
|
||||||
|
$this->assertEquals('square', $element->getAttribute('type'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* covers ::_writeWatermark
|
||||||
|
*/
|
||||||
|
public function testWriteWatermark()
|
||||||
|
{
|
||||||
|
$imageSrc = __DIR__ . "/../../_files/images/earth.jpg";
|
||||||
|
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$header = $section->addHeader();
|
||||||
|
$header->addWatermark($imageSrc);
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference");
|
||||||
|
$this->assertStringStartsWith("rId", $element->getAttribute('r:id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* covers ::_writeTitle
|
||||||
|
*/
|
||||||
|
public function testWriteTitle()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
||||||
|
$phpWord->addSection()->addTitle('Test', 1);
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$element = "/w:document/w:body/w:p/w:pPr/w:pStyle";
|
||||||
|
$this->assertEquals('Heading1', $doc->getElementAttribute($element, 'w:val'));
|
||||||
|
$element = "/w:document/w:body/w:p/w:r/w:fldChar";
|
||||||
|
$this->assertEquals('end', $doc->getElementAttribute($element, 'w:fldCharType'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* covers ::_writeCheckbox
|
||||||
|
*/
|
||||||
|
public function testWriteCheckbox()
|
||||||
|
{
|
||||||
|
$rStyle = 'rStyle';
|
||||||
|
$pStyle = 'pStyle';
|
||||||
|
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->addFontStyle($rStyle, array('bold' => true));
|
||||||
|
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$section->addCheckbox('Check1', 'Test', $rStyle, $pStyle);
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name';
|
||||||
|
$this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::_writeParagraphStyle
|
* covers ::_writeParagraphStyle
|
||||||
*/
|
*/
|
||||||
public function testWriteParagraphStylePagination()
|
public function testWriteParagraphStyle()
|
||||||
{
|
{
|
||||||
// Create the doc
|
// Create the doc
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
|
'align' => 'right',
|
||||||
'widowControl' => false,
|
'widowControl' => false,
|
||||||
'keepNext' => true,
|
'keepNext' => true,
|
||||||
'keepLines' => true,
|
'keepLines' => true,
|
||||||
|
|
@ -184,10 +247,13 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($attributes as $key => $value) {
|
foreach ($attributes as $key => $value) {
|
||||||
$i++;
|
$i++;
|
||||||
$path = "/w:document/w:body/w:p[{$i}]/w:pPr/w:{$key}";
|
$nodeName = ($key == 'align') ? 'jc' : $key;
|
||||||
|
$path = "/w:document/w:body/w:p[{$i}]/w:pPr/w:{$nodeName}";
|
||||||
|
if ($key != 'align') {
|
||||||
|
$value = $value ? 1 : 0;
|
||||||
|
}
|
||||||
$element = $doc->getElement($path);
|
$element = $doc->getElement($path);
|
||||||
$expected = $value ? 1 : 0;
|
$this->assertEquals($value, $element->getAttribute('w:val'));
|
||||||
$this->assertEquals($expected, $element->getAttribute('w:val'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,81 +382,4 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertEquals(5, $element->getAttribute('w:val'));
|
$this->assertEquals(5, $element->getAttribute('w:val'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* covers ::_writeImage
|
|
||||||
*/
|
|
||||||
public function testWriteImagePosition()
|
|
||||||
{
|
|
||||||
$phpWord = new PhpWord();
|
|
||||||
$section = $phpWord->addSection();
|
|
||||||
$section->addImage(
|
|
||||||
__DIR__ . "/../../_files/images/earth.jpg",
|
|
||||||
array(
|
|
||||||
'marginTop' => -1,
|
|
||||||
'marginLeft' => -1,
|
|
||||||
'wrappingStyle' => 'behind'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape');
|
|
||||||
|
|
||||||
$style = $element->getAttribute('style');
|
|
||||||
|
|
||||||
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
|
|
||||||
$this->assertRegExp('/position:absolute;/', $style);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* covers ::_writeWatermark
|
|
||||||
*/
|
|
||||||
public function testWriteWatermark()
|
|
||||||
{
|
|
||||||
$imageSrc = __DIR__ . "/../../_files/images/earth.jpg";
|
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
|
||||||
$section = $phpWord->addSection();
|
|
||||||
$header = $section->addHeader();
|
|
||||||
$header->addWatermark($imageSrc);
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
|
||||||
|
|
||||||
$element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference");
|
|
||||||
$this->assertStringStartsWith("rId", $element->getAttribute('r:id'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* covers ::_writeTitle
|
|
||||||
*/
|
|
||||||
public function testWriteTitle()
|
|
||||||
{
|
|
||||||
$phpWord = new PhpWord();
|
|
||||||
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
|
||||||
$phpWord->addSection()->addTitle('Test', 1);
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
|
||||||
|
|
||||||
$element = "/w:document/w:body/w:p/w:pPr/w:pStyle";
|
|
||||||
$this->assertEquals('Heading1', $doc->getElementAttribute($element, 'w:val'));
|
|
||||||
$element = "/w:document/w:body/w:p/w:r/w:fldChar";
|
|
||||||
$this->assertEquals('end', $doc->getElementAttribute($element, 'w:fldCharType'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* covers ::_writeCheckbox
|
|
||||||
*/
|
|
||||||
public function testWriteCheckbox()
|
|
||||||
{
|
|
||||||
$rStyle = 'rStyle';
|
|
||||||
$pStyle = 'pStyle';
|
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
|
||||||
$phpWord->addFontStyle($rStyle, array('bold' => true));
|
|
||||||
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
|
|
||||||
$section = $phpWord->addSection();
|
|
||||||
$section->addCheckbox('Check1', 'Test', $rStyle, $pStyle);
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
|
||||||
|
|
||||||
$element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name';
|
|
||||||
$this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue