PHPWord/test/PhpWord/TOCTest.php

69 lines
1.9 KiB
PHP
Raw Normal View History

2014-03-12 16:24:36 +07:00
<?php
namespace PhpWord\Tests;
2014-03-12 16:24:36 +07:00
use PhpOffice\PhpWord\TOC;
2014-03-12 16:24:36 +07:00
/**
* @coversDefaultClass \PhpOffice\PhpWord\TOC
2014-03-13 01:58:00 +07:00
* @runTestsInSeparateProcesses
2014-03-12 16:24:36 +07:00
*/
class TOCTest extends \PHPUnit_Framework_TestCase
2014-03-12 16:24:36 +07:00
{
/**
* @covers ::__construct
* @covers ::getStyleTOC
* @covers ::getStyleFont
2014-03-12 16:24:36 +07:00
*/
public function testConstruct()
{
$expected = array(
'tabPos' => 9062,
'tabLeader' => \PhpOffice\PhpWord\Style\TOC::TABLEADER_DOT,
'indent' => 200,
2014-03-12 16:24:36 +07:00
);
$object = new TOC(array('size' => 11), array('tabPos' => $expected['tabPos']));
2014-03-12 16:24:36 +07:00
$tocStyle = $object->getStyleTOC();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TOC', $tocStyle);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $object->getStyleFont());
2014-03-12 16:24:36 +07:00
foreach ($expected as $key => $value) {
$method = "get{$key}";
$this->assertEquals($value, $tocStyle->$method());
}
}
/**
* @covers ::addTitle
* @covers ::getTitles
2014-03-12 16:24:36 +07:00
*/
public function testAddAndGetTitle()
{
// Prepare variables
$titleCount = 3;
$anchor = '_Toc' . (252634154 + $titleCount);
2014-03-13 01:58:00 +07:00
$bookmark = $titleCount - 1;
2014-03-12 16:24:36 +07:00
$titles = array(
'Heading 1' => 1,
'Heading 2' => 2,
'Heading 3' => 3,
);
// @covers ::addTitle
2014-03-12 16:24:36 +07:00
foreach ($titles as $text => $depth) {
$response = TOC::addTitle($text, $depth);
2014-03-12 16:24:36 +07:00
}
$this->assertEquals($anchor, $response[0]);
$this->assertEquals($bookmark, $response[1]);
// @covers ::getTitles
2014-03-12 16:24:36 +07:00
$i = 0;
$savedTitles = TOC::getTitles();
2014-03-12 16:24:36 +07:00
foreach ($titles as $text => $depth) {
$this->assertEquals($text, $savedTitles[$i]['text']);
$this->assertEquals($depth, $savedTitles[$i]['depth']);
$i++;
}
}
}