Unit test enhancements
This commit is contained in:
parent
1977685936
commit
05a4b95255
@ -45,13 +45,6 @@ class CheckBox
|
|||||||
*/
|
*/
|
||||||
private $paragraphStyle;
|
private $paragraphStyle;
|
||||||
|
|
||||||
/**
|
|
||||||
* Cell Element Collection
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $_elementCollection = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Text Element
|
* Create a new Text Element
|
||||||
*
|
*
|
||||||
@ -174,14 +167,4 @@ class CheckBox
|
|||||||
{
|
{
|
||||||
return $this->text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all Elements
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getElements()
|
|
||||||
{
|
|
||||||
return $this->_elementCollection;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1223,11 +1223,6 @@ class Base extends WriterPart
|
|||||||
*/
|
*/
|
||||||
protected function _writeCheckBox(XMLWriter $xmlWriter, CheckBox $checkbox, $withoutP = false, $checkState = false)
|
protected function _writeCheckBox(XMLWriter $xmlWriter, CheckBox $checkbox, $withoutP = false, $checkState = false)
|
||||||
{
|
{
|
||||||
$count = 1;
|
|
||||||
$_elements = $checkbox->getElements();
|
|
||||||
if (count($_elements) > 1) {
|
|
||||||
$count = $count + 1;
|
|
||||||
}
|
|
||||||
$name = htmlspecialchars($checkbox->getName());
|
$name = htmlspecialchars($checkbox->getName());
|
||||||
$name = String::controlCharacterPHP2OOXML($name);
|
$name = String::controlCharacterPHP2OOXML($name);
|
||||||
$text = htmlspecialchars($checkbox->getText());
|
$text = htmlspecialchars($checkbox->getText());
|
||||||
@ -1271,9 +1266,6 @@ class Base extends WriterPart
|
|||||||
$xmlWriter->endElement(); // w:fldChar
|
$xmlWriter->endElement(); // w:fldChar
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
$xmlWriter->startElement('w:bookmarkStart');
|
|
||||||
$xmlWriter->writeAttribute('w:name', $name);
|
|
||||||
$xmlWriter->writeAttribute('w:id', $count);
|
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:instrText');
|
$xmlWriter->startElement('w:instrText');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
@ -1290,10 +1282,6 @@ class Base extends WriterPart
|
|||||||
$xmlWriter->writeAttribute('w:fldCharType', 'end');
|
$xmlWriter->writeAttribute('w:fldCharType', 'end');
|
||||||
$xmlWriter->endElement();// w:fldChar
|
$xmlWriter->endElement();// w:fldChar
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
$xmlWriter->endElement(); // w:bookmarkStart
|
|
||||||
$xmlWriter->startElement('w:bookmarkEnd');
|
|
||||||
$xmlWriter->writeAttribute('w:id', $count);
|
|
||||||
$xmlWriter->endElement();// w:bookmarkEnd
|
|
||||||
|
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
if ($sfIsObject) {
|
if ($sfIsObject) {
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
namespace PhpOffice\PhpWord\Tests\Section;
|
namespace PhpOffice\PhpWord\Tests\Section;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Section\CheckBox;
|
use PhpOffice\PhpWord\Section\CheckBox;
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\CheckBox
|
* Test class for PhpOffice\PhpWord\Section\CheckBox
|
||||||
@ -54,6 +55,16 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font style as object
|
||||||
|
*/
|
||||||
|
public function testFontObject()
|
||||||
|
{
|
||||||
|
$font = new Font();
|
||||||
|
$oCheckBox = new CheckBox('chkBox', 'CheckBox', $font);
|
||||||
|
$this->assertEquals($oCheckBox->getFontStyle(), $font);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get paragraph style
|
* Get paragraph style
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Footer;
|
|||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\Footer
|
* Test class for PhpOffice\PhpWord\Section\Footer
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Footer
|
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class FooterTest extends \PHPUnit_Framework_TestCase
|
class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
@ -28,15 +30,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oFooter->getFooterCount(), $iVal);
|
$this->assertEquals($oFooter->getFooterCount(), $iVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRelationID()
|
/**
|
||||||
{
|
* Add text
|
||||||
$oFooter = new Footer(0);
|
*/
|
||||||
|
|
||||||
$iVal = rand(1, 1000);
|
|
||||||
$oFooter->setRelationId($iVal);
|
|
||||||
$this->assertEquals($oFooter->getRelationId(), $iVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -46,6 +42,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text non-UTF8
|
||||||
|
*/
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -56,6 +55,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), 'ééé');
|
$this->assertEquals($element->getText(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text break
|
||||||
|
*/
|
||||||
public function testAddTextBreak()
|
public function testAddTextBreak()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -65,6 +67,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount($iVal, $oFooter->getElements());
|
$this->assertCount($iVal, $oFooter->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text run
|
||||||
|
*/
|
||||||
public function testCreateTextRun()
|
public function testCreateTextRun()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -74,6 +79,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add table
|
||||||
|
*/
|
||||||
public function testAddTable()
|
public function testAddTable()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -83,16 +91,23 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image
|
||||||
|
*/
|
||||||
public function testAddImage()
|
public function testAddImage()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
$element = $oFooter->addImage($src);
|
$element1 = $oFooter->addImage($src);
|
||||||
|
$element2 = $oFooter->addMemoryImage($src); // @deprecated
|
||||||
|
|
||||||
$this->assertCount(1, $oFooter->getElements());
|
$this->assertCount(2, $oFooter->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image by URL
|
||||||
|
*/
|
||||||
public function testAddImageByUrl()
|
public function testAddImageByUrl()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -104,6 +119,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add preserve text
|
||||||
|
*/
|
||||||
public function testAddPreserveText()
|
public function testAddPreserveText()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -113,6 +131,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add preserve text non-UTF8
|
||||||
|
*/
|
||||||
public function testAddPreserveTextNotUTF8()
|
public function testAddPreserveTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
@ -123,10 +144,25 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), array('ééé'));
|
$this->assertEquals($element->getText(), array('ééé'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get elements
|
||||||
|
*/
|
||||||
public function testGetElements()
|
public function testGetElements()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
|
|
||||||
$this->assertInternalType('array', $oFooter->getElements());
|
$this->assertInternalType('array', $oFooter->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set/get relation Id
|
||||||
|
*/
|
||||||
|
public function testRelationID()
|
||||||
|
{
|
||||||
|
$oFooter = new Footer(0);
|
||||||
|
|
||||||
|
$iVal = rand(1, 1000);
|
||||||
|
$oFooter->setRelationId($iVal);
|
||||||
|
$this->assertEquals($oFooter->getRelationId(), $iVal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,15 +14,12 @@ use PhpOffice\PhpWord\Section\Footnote;
|
|||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\Footnote
|
* Test class for PhpOffice\PhpWord\Section\Footnote
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Footnote
|
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class FootnoteTest extends \PHPUnit_Framework_TestCase
|
class FootnoteTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* New instance without parameter
|
* New instance without parameter
|
||||||
*
|
|
||||||
* @covers ::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
@ -35,8 +32,6 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* New instance with string parameter
|
* New instance with string parameter
|
||||||
*
|
|
||||||
* @covers ::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstructString()
|
public function testConstructString()
|
||||||
{
|
{
|
||||||
@ -47,8 +42,6 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* New instance with array parameter
|
* New instance with array parameter
|
||||||
*
|
|
||||||
* @covers ::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstructArray()
|
public function testConstructArray()
|
||||||
{
|
{
|
||||||
@ -62,8 +55,6 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add text element
|
* Add text element
|
||||||
*
|
|
||||||
* @covers ::addText
|
|
||||||
*/
|
*/
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
@ -76,8 +67,6 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add text break element
|
* Add text break element
|
||||||
*
|
|
||||||
* @covers ::addTextBreak
|
|
||||||
*/
|
*/
|
||||||
public function testAddTextBreak()
|
public function testAddTextBreak()
|
||||||
{
|
{
|
||||||
@ -89,8 +78,6 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add link element
|
* Add link element
|
||||||
*
|
|
||||||
* @covers ::addLink
|
|
||||||
*/
|
*/
|
||||||
public function testAddLink()
|
public function testAddLink()
|
||||||
{
|
{
|
||||||
@ -103,9 +90,6 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set/get reference Id
|
* Set/get reference Id
|
||||||
*
|
|
||||||
* @covers ::setReferenceId
|
|
||||||
* @covers ::getReferenceId
|
|
||||||
*/
|
*/
|
||||||
public function testReferenceId()
|
public function testReferenceId()
|
||||||
{
|
{
|
||||||
@ -118,8 +102,6 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get elements
|
* Get elements
|
||||||
*
|
|
||||||
* @covers ::getElements
|
|
||||||
*/
|
*/
|
||||||
public function testGetElements()
|
public function testGetElements()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Header;
|
|||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\Header
|
* Test class for PhpOffice\PhpWord\Section\Header
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Header
|
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class HeaderTest extends \PHPUnit_Framework_TestCase
|
class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*/
|
||||||
public function testConstructDefault()
|
public function testConstructDefault()
|
||||||
{
|
{
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
@ -29,6 +31,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oHeader->getType(), Header::AUTO);
|
$this->assertEquals($oHeader->getType(), Header::AUTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text
|
||||||
|
*/
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -39,6 +44,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), 'text');
|
$this->assertEquals($element->getText(), 'text');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text non-UTF8
|
||||||
|
*/
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -49,6 +57,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), 'ééé');
|
$this->assertEquals($element->getText(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text break
|
||||||
|
*/
|
||||||
public function testAddTextBreak()
|
public function testAddTextBreak()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -56,6 +67,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text break with params
|
||||||
|
*/
|
||||||
public function testAddTextBreakWithParams()
|
public function testAddTextBreakWithParams()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -64,6 +78,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount($iVal, $oHeader->getElements());
|
$this->assertCount($iVal, $oHeader->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text run
|
||||||
|
*/
|
||||||
public function testCreateTextRun()
|
public function testCreateTextRun()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -72,6 +89,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add table
|
||||||
|
*/
|
||||||
public function testAddTable()
|
public function testAddTable()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -80,16 +100,23 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image
|
||||||
|
*/
|
||||||
public function testAddImage()
|
public function testAddImage()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addImage($src);
|
$element1 = $oHeader->addImage($src);
|
||||||
|
$element2 = $oHeader->addMemoryImage($src); // @deprecated
|
||||||
|
|
||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(2, $oHeader->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image by URL
|
||||||
|
*/
|
||||||
public function testAddImageByUrl()
|
public function testAddImageByUrl()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -101,6 +128,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add preserve text
|
||||||
|
*/
|
||||||
public function testAddPreserveText()
|
public function testAddPreserveText()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -110,6 +140,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add preserve text non-UTF8
|
||||||
|
*/
|
||||||
public function testAddPreserveTextNotUTF8()
|
public function testAddPreserveTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -120,6 +153,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), array('ééé'));
|
$this->assertEquals($element->getText(), array('ééé'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add watermark
|
||||||
|
*/
|
||||||
public function testAddWatermark()
|
public function testAddWatermark()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||||
@ -130,6 +166,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get elements
|
||||||
|
*/
|
||||||
public function testGetElements()
|
public function testGetElements()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -137,6 +176,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInternalType('array', $oHeader->getElements());
|
$this->assertInternalType('array', $oHeader->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set/get relation Id
|
||||||
|
*/
|
||||||
public function testRelationId()
|
public function testRelationId()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -146,6 +188,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oHeader->getRelationId(), $iVal);
|
$this->assertEquals($oHeader->getRelationId(), $iVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset type
|
||||||
|
*/
|
||||||
public function testResetType()
|
public function testResetType()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -155,6 +200,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oHeader->getType(), Header::AUTO);
|
$this->assertEquals($oHeader->getType(), Header::AUTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First page
|
||||||
|
*/
|
||||||
public function testFirstPage()
|
public function testFirstPage()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
@ -163,6 +211,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oHeader->getType(), Header::FIRST);
|
$this->assertEquals($oHeader->getType(), Header::FIRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Even page
|
||||||
|
*/
|
||||||
public function testEvenPage()
|
public function testEvenPage()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
|
|||||||
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Image;
|
|||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\Image
|
* Test class for PhpOffice\PhpWord\Section\Image
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Image
|
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class ImageTest extends \PHPUnit_Framework_TestCase
|
class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/firefox.png";
|
$src = __DIR__ . "/../_files/images/firefox.png";
|
||||||
@ -31,6 +33,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance with style
|
||||||
|
*/
|
||||||
public function testConstructWithStyle()
|
public function testConstructWithStyle()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/firefox.png";
|
$src = __DIR__ . "/../_files/images/firefox.png";
|
||||||
@ -44,7 +49,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::__construct
|
* Valid image types
|
||||||
*/
|
*/
|
||||||
public function testValidImageTypes()
|
public function testValidImageTypes()
|
||||||
{
|
{
|
||||||
@ -57,8 +62,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Image not found
|
||||||
|
*
|
||||||
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
|
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
|
||||||
* @covers ::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testImageNotFound()
|
public function testImageNotFound()
|
||||||
{
|
{
|
||||||
@ -66,14 +72,18 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Invalid image types
|
||||||
|
*
|
||||||
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
|
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
|
||||||
* @covers ::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testInvalidImageTypes()
|
public function testInvalidImageTypes()
|
||||||
{
|
{
|
||||||
new Image(__DIR__ . "/../_files/images/alexz-johnson.pcx");
|
new Image(__DIR__ . "/../_files/images/alexz-johnson.pcx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get style
|
||||||
|
*/
|
||||||
public function testStyle()
|
public function testStyle()
|
||||||
{
|
{
|
||||||
$oImage = new Image(
|
$oImage = new Image(
|
||||||
@ -84,6 +94,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get relation Id
|
||||||
|
*/
|
||||||
public function testRelationID()
|
public function testRelationID()
|
||||||
{
|
{
|
||||||
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
|
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
|
||||||
@ -92,12 +105,19 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oImage->getRelationId(), $iVal);
|
$this->assertEquals($oImage->getRelationId(), $iVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get is watermark
|
||||||
|
*/
|
||||||
public function testWatermark()
|
public function testWatermark()
|
||||||
{
|
{
|
||||||
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
|
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
|
||||||
$oImage->setIsWatermark(true);
|
$oImage->setIsWatermark(true);
|
||||||
$this->assertEquals($oImage->getIsWatermark(), true);
|
$this->assertEquals($oImage->getIsWatermark(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test PNG
|
||||||
|
*/
|
||||||
public function testPNG()
|
public function testPNG()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/firefox.png";
|
$src = __DIR__ . "/../_files/images/firefox.png";
|
||||||
@ -112,6 +132,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oImage->getImageType(), 'image/png');
|
$this->assertEquals($oImage->getImageType(), 'image/png');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test GIF
|
||||||
|
*/
|
||||||
public function testGIF()
|
public function testGIF()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/mario.gif";
|
$src = __DIR__ . "/../_files/images/mario.gif";
|
||||||
@ -126,6 +149,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oImage->getImageType(), 'image/gif');
|
$this->assertEquals($oImage->getImageType(), 'image/gif');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test JPG
|
||||||
|
*/
|
||||||
public function testJPG()
|
public function testJPG()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||||
@ -140,6 +166,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oImage->getImageType(), 'image/jpeg');
|
$this->assertEquals($oImage->getImageType(), 'image/jpeg');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test BMP
|
||||||
|
*/
|
||||||
public function testBMP()
|
public function testBMP()
|
||||||
{
|
{
|
||||||
$oImage = new Image(__DIR__ . "/../_files/images/duke_nukem.bmp");
|
$oImage = new Image(__DIR__ . "/../_files/images/duke_nukem.bmp");
|
||||||
@ -150,4 +179,17 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oImage->getImageExtension(), 'bmp');
|
$this->assertEquals($oImage->getImageExtension(), 'bmp');
|
||||||
$this->assertEquals($oImage->getImageType(), 'image/bmp');
|
$this->assertEquals($oImage->getImageType(), 'image/bmp');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test TIFF
|
||||||
|
*/
|
||||||
|
public function testTIFF()
|
||||||
|
{
|
||||||
|
$oImage = new Image(__DIR__ . "/../_files/images/angela_merkel.tif");
|
||||||
|
|
||||||
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
|
||||||
|
$this->assertEquals($oImage->getImageCreateFunction(), null);
|
||||||
|
$this->assertEquals($oImage->getImageFunction(), null);
|
||||||
|
$this->assertEquals($oImage->getImageType(), 'image/tiff');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Table\Cell;
|
|||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\Table\Cell
|
* Test class for PhpOffice\PhpWord\Section\Table\Cell
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Table\Cell
|
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class CellTest extends \PHPUnit_Framework_TestCase
|
class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
@ -28,6 +30,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oCell->getWidth(), null);
|
$this->assertEquals($oCell->getWidth(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance with array
|
||||||
|
*/
|
||||||
public function testConstructWithStyleArray()
|
public function testConstructWithStyleArray()
|
||||||
{
|
{
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
@ -37,6 +42,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oCell->getWidth(), null);
|
$this->assertEquals($oCell->getWidth(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance with string
|
||||||
|
*/
|
||||||
public function testConstructWithStyleString()
|
public function testConstructWithStyleString()
|
||||||
{
|
{
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
@ -45,6 +53,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oCell->getStyle(), 'cellStyle');
|
$this->assertEquals($oCell->getStyle(), 'cellStyle');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text
|
||||||
|
*/
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
@ -54,6 +65,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add non-UTF8
|
||||||
|
*/
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
@ -64,15 +78,31 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), 'ééé');
|
$this->assertEquals($element->getText(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add link
|
||||||
|
*/
|
||||||
public function testAddLink()
|
public function testAddLink()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
$element = $oCell->addLink('http://www.google.fr', 'Nom');
|
$element = $oCell->addLink(utf8_decode('ééé'), utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add link exception
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function testAddLinkException()
|
||||||
|
{
|
||||||
|
$oCell = new Cell('header', 1);
|
||||||
|
$element = $oCell->addLink('http://google.com', 'Google');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text break
|
||||||
|
*/
|
||||||
public function testAddTextBreak()
|
public function testAddTextBreak()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
@ -81,6 +111,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add list item
|
||||||
|
*/
|
||||||
public function testAddListItem()
|
public function testAddListItem()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
@ -91,6 +124,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getTextObject()->getText(), 'text');
|
$this->assertEquals($element->getTextObject()->getText(), 'text');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add list item non-UTF8
|
||||||
|
*/
|
||||||
public function testAddListItemNotUTF8()
|
public function testAddListItemNotUTF8()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
@ -101,16 +137,23 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getTextObject()->getText(), 'ééé');
|
$this->assertEquals($element->getTextObject()->getText(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image section
|
||||||
|
*/
|
||||||
public function testAddImageSection()
|
public function testAddImageSection()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
$element = $oCell->addImage($src);
|
$element1 = $oCell->addImage($src);
|
||||||
|
$element2 = $oCell->addMemoryImage($src); // @deprecated
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(2, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image header
|
||||||
|
*/
|
||||||
public function testAddImageHeader()
|
public function testAddImageHeader()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
||||||
@ -121,6 +164,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image footer
|
||||||
|
*/
|
||||||
public function testAddImageFooter()
|
public function testAddImageFooter()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
||||||
@ -131,7 +177,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddSectionImageByUrl()
|
/**
|
||||||
|
* Add image section by URL
|
||||||
|
*/
|
||||||
|
public function testAddImageSectionByUrl()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
$element = $oCell->addImage(
|
$element = $oCell->addImage(
|
||||||
@ -142,7 +191,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddHeaderImageByUrl()
|
/**
|
||||||
|
* Add image header by URL
|
||||||
|
*/
|
||||||
|
public function testAddImageHeaderByUrl()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('header', 1);
|
$oCell = new Cell('header', 1);
|
||||||
$element = $oCell->addImage(
|
$element = $oCell->addImage(
|
||||||
@ -153,7 +205,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddFooterImageByUrl()
|
/**
|
||||||
|
* Add image footer by URL
|
||||||
|
*/
|
||||||
|
public function testAddImageFooterByUrl()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('footer', 1);
|
$oCell = new Cell('footer', 1);
|
||||||
$element = $oCell->addImage(
|
$element = $oCell->addImage(
|
||||||
@ -164,6 +219,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add object
|
||||||
|
*/
|
||||||
public function testAddObjectXLS()
|
public function testAddObjectXLS()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../../_files/documents/sheet.xls";
|
$src = __DIR__ . "/../../_files/documents/sheet.xls";
|
||||||
@ -174,6 +232,21 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test add object exception
|
||||||
|
*
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidObjectException
|
||||||
|
*/
|
||||||
|
public function testAddObjectException()
|
||||||
|
{
|
||||||
|
$src = __DIR__ . "/_files/xsl/passthrough.xsl";
|
||||||
|
$oCell = new Cell('section', 1);
|
||||||
|
$element = $oCell->addObject($src);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add preserve text
|
||||||
|
*/
|
||||||
public function testAddPreserveText()
|
public function testAddPreserveText()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('header', 1);
|
$oCell = new Cell('header', 1);
|
||||||
@ -183,6 +256,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add preserve text non-UTF8
|
||||||
|
*/
|
||||||
public function testAddPreserveTextNotUTF8()
|
public function testAddPreserveTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('header', 1);
|
$oCell = new Cell('header', 1);
|
||||||
@ -193,6 +269,20 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), array('ééé'));
|
$this->assertEquals($element->getText(), array('ééé'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add preserve text exception
|
||||||
|
*
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function testAddPreserveTextException()
|
||||||
|
{
|
||||||
|
$oCell = new Cell('section', 1);
|
||||||
|
$element = $oCell->addPreserveText('text');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text run
|
||||||
|
*/
|
||||||
public function testCreateTextRun()
|
public function testCreateTextRun()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
@ -202,16 +292,21 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add check box
|
||||||
|
*/
|
||||||
public function testAddCheckBox()
|
public function testAddCheckBox()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
$element = $oCell->addCheckBox('check1', 'text');
|
$element = $oCell->addCheckBox(utf8_decode('ééé'), utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\CheckBox', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\CheckBox', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get elements
|
||||||
|
*/
|
||||||
public function testGetElements()
|
public function testGetElements()
|
||||||
{
|
{
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
|
|||||||
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\TextRun;
|
|||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\TextRun
|
* Test class for PhpOffice\PhpWord\Section\TextRun
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\TextRun
|
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class TextRunTest extends \PHPUnit_Framework_TestCase
|
class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*/
|
||||||
public function testConstructNull()
|
public function testConstructNull()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
@ -28,6 +30,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oTextRun->getParagraphStyle(), null);
|
$this->assertEquals($oTextRun->getParagraphStyle(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance with string
|
||||||
|
*/
|
||||||
public function testConstructString()
|
public function testConstructString()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun('pStyle');
|
$oTextRun = new TextRun('pStyle');
|
||||||
@ -37,6 +42,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle');
|
$this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance with array
|
||||||
|
*/
|
||||||
public function testConstructArray()
|
public function testConstructArray()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun(array('spacing' => 100));
|
$oTextRun = new TextRun(array('spacing' => 100));
|
||||||
@ -46,6 +54,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oTextRun->getParagraphStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oTextRun->getParagraphStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text
|
||||||
|
*/
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
@ -56,6 +67,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), 'text');
|
$this->assertEquals($element->getText(), 'text');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text non-UTF8
|
||||||
|
*/
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
@ -66,6 +80,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getText(), 'ééé');
|
$this->assertEquals($element->getText(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add link
|
||||||
|
*/
|
||||||
public function testAddLink()
|
public function testAddLink()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
@ -76,6 +93,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
|
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add link with name
|
||||||
|
*/
|
||||||
public function testAddLinkWithName()
|
public function testAddLinkWithName()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
@ -87,6 +107,20 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($element->getLinkName(), 'ééé');
|
$this->assertEquals($element->getLinkName(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text break
|
||||||
|
*/
|
||||||
|
public function testAddTextBreak()
|
||||||
|
{
|
||||||
|
$oTextRun = new TextRun();
|
||||||
|
$element = $oTextRun->addTextBreak(2);
|
||||||
|
|
||||||
|
$this->assertCount(2, $oTextRun->getElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add image
|
||||||
|
*/
|
||||||
public function testAddImage()
|
public function testAddImage()
|
||||||
{
|
{
|
||||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||||
@ -98,6 +132,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(1, $oTextRun->getElements());
|
$this->assertCount(1, $oTextRun->getElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add footnote
|
||||||
|
*/
|
||||||
public function testCreateFootnote()
|
public function testCreateFootnote()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
|
|||||||
@ -10,15 +10,18 @@
|
|||||||
namespace PhpOffice\PhpWord\Tests\Section;
|
namespace PhpOffice\PhpWord\Tests\Section;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Section\Text;
|
use PhpOffice\PhpWord\Section\Text;
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Section\Text
|
* Test class for PhpOffice\PhpWord\Section\Text
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Text
|
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class TextTest extends \PHPUnit_Framework_TestCase
|
class TextTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$oText = new Text();
|
$oText = new Text();
|
||||||
@ -29,6 +32,9 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get text
|
||||||
|
*/
|
||||||
public function testText()
|
public function testText()
|
||||||
{
|
{
|
||||||
$oText = new Text('text');
|
$oText = new Text('text');
|
||||||
@ -36,6 +42,9 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($oText->getText(), 'text');
|
$this->assertEquals($oText->getText(), 'text');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get font style
|
||||||
|
*/
|
||||||
public function testFont()
|
public function testFont()
|
||||||
{
|
{
|
||||||
$oText = new Text('text', 'fontStyle');
|
$oText = new Text('text', 'fontStyle');
|
||||||
@ -45,6 +54,19 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get font style as object
|
||||||
|
*/
|
||||||
|
public function testFontObject()
|
||||||
|
{
|
||||||
|
$font = new Font();
|
||||||
|
$oText = new Text('text', $font);
|
||||||
|
$this->assertEquals($oText->getFontStyle(), $font);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get paragraph style
|
||||||
|
*/
|
||||||
public function testParagraph()
|
public function testParagraph()
|
||||||
{
|
{
|
||||||
$oText = new Text('text', 'fontStyle', 'paragraphStyle');
|
$oText = new Text('text', 'fontStyle', 'paragraphStyle');
|
||||||
|
|||||||
@ -88,7 +88,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$section->addTitle(utf8_decode('ä'), 1);
|
$section->addTitle(utf8_decode('ä'), 1);
|
||||||
$section->createTextRun();
|
$section->createTextRun();
|
||||||
$section->createFootnote();
|
$section->createFootnote();
|
||||||
$section->addCheckBox('check1', utf8_decode('ä'));
|
$section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä'));
|
||||||
$section->addTOC();
|
$section->addTOC();
|
||||||
|
|
||||||
$elementCollection = $section->getElements();
|
$elementCollection = $section->getElements();
|
||||||
|
|||||||
@ -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\Style\Font;
|
||||||
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +34,11 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
$section->getSettings()->setPageNumberingStart(2);
|
$settings = $section->getSettings();
|
||||||
|
$settings->setLandscape();
|
||||||
|
$settings->setPageNumberingStart(2);
|
||||||
|
$settings->setBorderSize(240);
|
||||||
|
$settings->setBreakType('nextPage');
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType');
|
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType');
|
||||||
@ -85,4 +90,39 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||||||
$element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject');
|
$element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject');
|
||||||
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write element with some styles
|
||||||
|
*/
|
||||||
|
public function testElementStyles()
|
||||||
|
{
|
||||||
|
$objectSrc = __DIR__ . "/../../_files/documents/sheet.xls";
|
||||||
|
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->addParagraphStyle('pStyle', array('align' => 'center'));
|
||||||
|
$phpWord->addFontStyle('fStyle', array('size' => '20'));
|
||||||
|
$phpWord->addTitleStyle(1, array('color' => '333333', 'bold' => true));
|
||||||
|
$fontStyle = new Font('text', array('align' => 'center'));
|
||||||
|
$section = $phpWord->createSection();
|
||||||
|
$section->addListItem('List Item', 0, null, null, 'pStyle');
|
||||||
|
$section->addObject($objectSrc, array('align' => 'center'));
|
||||||
|
$section->addTOC($fontStyle);
|
||||||
|
$section->addTitle('Title 1', 1);
|
||||||
|
$section->addTOC('fStyle');
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
// List item
|
||||||
|
$element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId');
|
||||||
|
$this->assertEquals(3, $element->getAttribute('w:val'));
|
||||||
|
|
||||||
|
// Object
|
||||||
|
$element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject');
|
||||||
|
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
||||||
|
|
||||||
|
// TOC
|
||||||
|
$element = $doc->getElement('/w:document/w:body/w:p[3]/w:pPr/w:tabs/w:tab');
|
||||||
|
$this->assertEquals('right', $element->getAttribute('w:val'));
|
||||||
|
$this->assertEquals('dot', $element->getAttribute('w:leader'));
|
||||||
|
$this->assertEquals(9062, $element->getAttribute('w:pos'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,11 +30,15 @@ class FootnotesTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testWriteFootnotes()
|
public function testWriteFootnotes()
|
||||||
{
|
{
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
$section->addText('Text');
|
$section->addText('Text');
|
||||||
$footnote = $section->createFootnote();
|
$footnote1 = $section->createFootnote('pStyle');
|
||||||
$footnote->addText('Footnote');
|
$footnote1->addText('Footnote');
|
||||||
$footnote->addLink('http://google.com');
|
$footnote1->addTextBreak();
|
||||||
|
$footnote1->addLink('http://google.com');
|
||||||
|
$footnote2 = $section->createFootnote(array('align' => 'left'));
|
||||||
|
$footnote2->addText('Footnote');
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
$this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference"));
|
$this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference"));
|
||||||
|
|||||||
@ -99,6 +99,8 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
$section->addText('Test');
|
$section->addText('Test');
|
||||||
|
$footnote = $section->createFootnote();
|
||||||
|
$footnote->addText('Test');
|
||||||
|
|
||||||
$writer = new Word2007($phpWord);
|
$writer = new Word2007($phpWord);
|
||||||
$writer->setUseDiskCaching(true);
|
$writer->setUseDiskCaching(true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user