2014-03-12 19:26:30 +07:00
|
|
|
<?php
|
|
|
|
|
namespace PHPWord\Tests;
|
|
|
|
|
|
2014-03-19 11:04:48 +04:00
|
|
|
use PhpOffice\PHPWord;
|
|
|
|
|
use PhpOffice\PhpWord\DocumentProperties;
|
|
|
|
|
use PhpOffice\PhpWord\Section;
|
|
|
|
|
use PhpOffice\PhpWord\Style;
|
2014-03-12 19:26:30 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @package PHPWord\Tests
|
|
|
|
|
* @coversDefaultClass PhpOffice\PHPWord
|
2014-03-13 01:58:00 +07:00
|
|
|
* @runTestsInSeparateProcesses
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
2014-03-12 20:13:06 +04:00
|
|
|
class PHPWordTest extends \PHPUnit_Framework_TestCase
|
2014-03-12 19:26:30 +07:00
|
|
|
{
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @var PhpOffice\PHPWord
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
protected $object;
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::__construct
|
|
|
|
|
* @covers ::getProperties
|
|
|
|
|
* @covers ::getDefaultFontName
|
|
|
|
|
* @covers ::getDefaultFontSize
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testConstruct()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
2014-03-19 11:04:48 +04:00
|
|
|
$this->assertEquals(new DocumentProperties(), $object->getProperties());
|
2014-03-12 19:26:30 +07:00
|
|
|
$this->assertEquals(
|
|
|
|
|
PHPWord::DEFAULT_FONT_NAME,
|
|
|
|
|
$object->getDefaultFontName()
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
PHPWord::DEFAULT_FONT_SIZE,
|
|
|
|
|
$object->getDefaultFontSize()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::setProperties
|
|
|
|
|
* @covers ::getProperties
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testSetGetProperties()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
|
|
|
|
$creator = 'PHPWord';
|
|
|
|
|
$properties = $object->getProperties();
|
|
|
|
|
$properties->setCreator($creator);
|
|
|
|
|
$object->setProperties($properties);
|
|
|
|
|
$this->assertEquals($creator, $object->getProperties()->getCreator());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::createSection
|
|
|
|
|
* @covers ::getSections
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testCreateGetSections()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
2014-03-19 11:04:48 +04:00
|
|
|
$this->assertEquals(new Section(1), $object->createSection());
|
2014-03-12 19:26:30 +07:00
|
|
|
$object->createSection();
|
|
|
|
|
$this->assertEquals(2, count($object->getSections()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::setDefaultFontName
|
|
|
|
|
* @covers ::getDefaultFontName
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testSetGetDefaultFontName()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
|
|
|
|
$fontName = 'Times New Roman';
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
PHPWord::DEFAULT_FONT_NAME,
|
|
|
|
|
$object->getDefaultFontName()
|
|
|
|
|
);
|
|
|
|
|
$object->setDefaultFontName($fontName);
|
|
|
|
|
$this->assertEquals($fontName, $object->getDefaultFontName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::setDefaultFontSize
|
|
|
|
|
* @covers ::getDefaultFontSize
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testSetGetDefaultFontSize()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
|
|
|
|
$fontSize = 16;
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
PHPWord::DEFAULT_FONT_SIZE,
|
|
|
|
|
$object->getDefaultFontSize()
|
|
|
|
|
);
|
|
|
|
|
$object->setDefaultFontSize($fontSize);
|
|
|
|
|
$this->assertEquals($fontSize, $object->getDefaultFontSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::setDefaultParagraphStyle
|
|
|
|
|
* @covers ::loadTemplate
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testSetDefaultParagraphStyle()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
|
|
|
|
$object->setDefaultParagraphStyle(array());
|
2014-03-19 11:04:48 +04:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', Style::getStyle('Normal'));
|
2014-03-12 19:26:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::addParagraphStyle
|
|
|
|
|
* @covers ::addFontStyle
|
|
|
|
|
* @covers ::addTableStyle
|
|
|
|
|
* @covers ::addLinkStyle
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testAddStyles()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
2014-03-19 11:04:48 +04:00
|
|
|
$styles = array(
|
|
|
|
|
'Paragraph' => 'Paragraph',
|
|
|
|
|
'Font' => 'Font',
|
|
|
|
|
'Table' => 'TableFull',
|
|
|
|
|
'Link' => 'Font',
|
|
|
|
|
);
|
2014-03-12 19:26:30 +07:00
|
|
|
foreach ($styles as $key => $value) {
|
|
|
|
|
$method = "add{$key}Style";
|
|
|
|
|
$styleId = "{$key} Style";
|
|
|
|
|
$object->$method($styleId, array());
|
2014-03-19 11:04:48 +04:00
|
|
|
$this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$value}", Style::getStyle($styleId));
|
2014-03-12 19:26:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::addTitleStyle
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testAddTitleStyle()
|
|
|
|
|
{
|
|
|
|
|
$object = new PHPWord();
|
|
|
|
|
$titleLevel = 1;
|
|
|
|
|
$titleName = "Heading_{$titleLevel}";
|
|
|
|
|
$object->addTitleStyle($titleLevel, array());
|
2014-03-19 11:04:48 +04:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', Style::getStyle($titleName));
|
2014-03-12 19:26:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::loadTemplate
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testLoadTemplate()
|
|
|
|
|
{
|
|
|
|
|
$file = join(
|
|
|
|
|
DIRECTORY_SEPARATOR,
|
|
|
|
|
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx')
|
|
|
|
|
);
|
|
|
|
|
$object = new PHPWord();
|
2014-03-19 11:04:48 +04:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Template', $object->loadTemplate($file));
|
2014-03-12 19:26:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::loadTemplate
|
|
|
|
|
* @expectedException PhpOffice\PhpWord\Exceptions\Exception
|
2014-03-12 19:26:30 +07:00
|
|
|
*/
|
|
|
|
|
public function testLoadTemplateException()
|
|
|
|
|
{
|
|
|
|
|
$file = join(
|
|
|
|
|
DIRECTORY_SEPARATOR,
|
|
|
|
|
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blanks.docx')
|
|
|
|
|
);
|
|
|
|
|
$object = new PHPWord();
|
|
|
|
|
$object->loadTemplate($file);
|
|
|
|
|
}
|
2014-03-19 11:04:48 +04:00
|
|
|
}
|