2014-02-24 19:17:06 +01:00
|
|
|
<?php
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
|
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
|
|
*/
|
|
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
namespace PhpOffice\PhpWord\Tests\Container;
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Container\Section;
|
2014-03-28 13:50:53 +07:00
|
|
|
use PhpOffice\PhpWord\Style;
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-12 21:55:20 +07:00
|
|
|
/**
|
2014-03-31 01:13:02 +07:00
|
|
|
* Test class for PhpOffice\PhpWord\Container\Section
|
2014-03-27 23:55:06 +07:00
|
|
|
*
|
2014-03-13 01:58:00 +07:00
|
|
|
* @runTestsInSeparateProcesses
|
2014-03-12 21:55:20 +07:00
|
|
|
*/
|
2014-03-09 14:18:49 -04:00
|
|
|
class SectionTest extends \PHPUnit_Framework_TestCase
|
2014-03-02 14:40:58 -05:00
|
|
|
{
|
2014-03-12 21:55:20 +07:00
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Get settings
|
2014-03-12 21:55:20 +07:00
|
|
|
*/
|
2014-03-02 14:40:58 -05:00
|
|
|
public function testGetSettings()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oSection = new Section(0);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->assertAttributeEquals($oSection->getSettings(), 'settings', new Section(0));
|
2014-03-02 14:40:58 -05:00
|
|
|
}
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-12 21:55:20 +07:00
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Get elements
|
2014-03-12 21:55:20 +07:00
|
|
|
*/
|
|
|
|
|
public function testGetElements()
|
2014-03-02 14:40:58 -05:00
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oSection = new Section(0);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->assertAttributeEquals($oSection->getElements(), 'elements', new Section(0));
|
2014-03-02 14:40:58 -05:00
|
|
|
}
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-12 21:55:20 +07:00
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Get footer
|
2014-03-12 21:55:20 +07:00
|
|
|
*/
|
2014-03-02 14:40:58 -05:00
|
|
|
public function testGetFooter()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oSection = new Section(0);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->assertAttributeEquals($oSection->getFooter(), 'footer', new Section(0));
|
2014-03-02 14:40:58 -05:00
|
|
|
}
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-12 21:55:20 +07:00
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Get headers
|
2014-03-12 21:55:20 +07:00
|
|
|
*/
|
2014-03-02 14:40:58 -05:00
|
|
|
public function testGetHeaders()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oSection = new Section(0);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->assertAttributeEquals($oSection->getHeaders(), 'headers', new Section(0));
|
2014-03-02 14:40:58 -05:00
|
|
|
}
|
2014-03-13 01:58:00 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Set settings
|
2014-03-13 01:58:00 +07:00
|
|
|
*/
|
|
|
|
|
public function testSetSettings()
|
|
|
|
|
{
|
|
|
|
|
$expected = 'landscape';
|
2014-03-18 17:26:03 +04:00
|
|
|
$object = new Section(0);
|
2014-03-13 01:58:00 +07:00
|
|
|
$object->setSettings(array('orientation' => $expected));
|
|
|
|
|
$this->assertEquals($expected, $object->getSettings()->getOrientation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Add elements
|
2014-03-13 01:58:00 +07:00
|
|
|
*/
|
|
|
|
|
public function testAddElements()
|
|
|
|
|
{
|
2014-03-31 01:13:02 +07:00
|
|
|
$objectSource = __DIR__ . "/../_files/documents/reader.docx";
|
|
|
|
|
$imageSource = __DIR__ . "/../_files/images/PhpWord.png";
|
2014-03-13 01:58:00 +07:00
|
|
|
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
|
|
|
|
|
|
2014-03-18 17:26:03 +04:00
|
|
|
$section = new Section(0);
|
2014-03-13 01:58:00 +07:00
|
|
|
$section->addText(utf8_decode('ä'));
|
|
|
|
|
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä'));
|
|
|
|
|
$section->addTextBreak();
|
|
|
|
|
$section->addPageBreak();
|
|
|
|
|
$section->addTable();
|
|
|
|
|
$section->addListItem(utf8_decode('ä'));
|
|
|
|
|
$section->addObject($objectSource);
|
|
|
|
|
$section->addImage($imageSource);
|
2014-03-28 13:50:53 +07:00
|
|
|
$section->addMemoryImage($imageUrl);
|
2014-03-13 01:58:00 +07:00
|
|
|
$section->addTitle(utf8_decode('ä'), 1);
|
|
|
|
|
$section->createTextRun();
|
|
|
|
|
$section->createFootnote();
|
2014-03-30 11:09:14 +07:00
|
|
|
$section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä'));
|
2014-03-28 13:50:53 +07:00
|
|
|
$section->addTOC();
|
|
|
|
|
|
|
|
|
|
$elementCollection = $section->getElements();
|
|
|
|
|
$elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
|
|
|
|
|
'Table', 'ListItem', 'Object', 'Image', 'Image',
|
2014-03-30 01:30:25 +07:00
|
|
|
'Title', 'TextRun', 'Footnote', 'CheckBox');
|
2014-03-28 13:50:53 +07:00
|
|
|
$i = 0;
|
|
|
|
|
foreach ($elementTypes as $elementType) {
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$i]);
|
2014-03-28 13:50:53 +07:00
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
$this->assertInstanceOf("PhpOffice\\PhpWord\\TOC", $elementCollection[$i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test add object exception
|
|
|
|
|
*
|
2014-03-31 01:13:02 +07:00
|
|
|
* @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
|
2014-03-28 13:50:53 +07:00
|
|
|
*/
|
|
|
|
|
public function testAddObjectException()
|
|
|
|
|
{
|
|
|
|
|
$source = __DIR__ . "/_files/xsl/passthrough.xsl";
|
|
|
|
|
$section = new Section(0);
|
|
|
|
|
$section->addObject($source);
|
|
|
|
|
}
|
2014-03-13 01:58:00 +07:00
|
|
|
|
2014-03-28 13:50:53 +07:00
|
|
|
/**
|
|
|
|
|
* Add title with predefined style
|
|
|
|
|
*/
|
|
|
|
|
public function testAddTitleWithStyle()
|
|
|
|
|
{
|
|
|
|
|
Style::addTitleStyle(1, array('size' => 14));
|
|
|
|
|
$section = new Section(0);
|
|
|
|
|
$section->addTitle('Test', 1);
|
2014-03-13 01:58:00 +07:00
|
|
|
$elementCollection = $section->getElements();
|
2014-03-28 13:50:53 +07:00
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\Title", $elementCollection[0]);
|
2014-03-13 01:58:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Create header footer
|
2014-03-13 01:58:00 +07:00
|
|
|
*/
|
|
|
|
|
public function testCreateHeaderFooter()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$object = new Section(0);
|
2014-03-13 01:58:00 +07:00
|
|
|
$elements = array('Header', 'Footer');
|
2014-03-28 13:50:53 +07:00
|
|
|
|
2014-03-13 01:58:00 +07:00
|
|
|
foreach ($elements as $element) {
|
|
|
|
|
$method = "create{$element}";
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf("PhpOffice\\PhpWord\\Container\\{$element}", $object->$method());
|
2014-03-13 01:58:00 +07:00
|
|
|
}
|
2014-03-28 13:50:53 +07:00
|
|
|
$this->assertFalse($object->hasDifferentFirstPage());
|
2014-03-13 01:58:00 +07:00
|
|
|
}
|
2014-03-11 21:44:54 +07:00
|
|
|
}
|