2014-03-12 16:24:36 +07:00
|
|
|
<?php
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
2014-05-04 17:55:54 +07:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
|
2014-03-27 23:55:06 +07:00
|
|
|
*/
|
|
|
|
|
|
2014-03-23 11:59:22 -04:00
|
|
|
namespace PhpOffice\PhpWord\Tests;
|
2014-03-12 16:24:36 +07:00
|
|
|
|
2014-03-19 11:04:48 +04:00
|
|
|
use PhpOffice\PhpWord\TOC;
|
2014-03-12 16:24:36 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-03-27 23:55:06 +07:00
|
|
|
* Test class for PhpOffice\PhpWord\TOC
|
|
|
|
|
*
|
2014-03-13 01:58:00 +07:00
|
|
|
* @runTestsInSeparateProcesses
|
2014-03-12 16:24:36 +07:00
|
|
|
*/
|
2014-03-12 20:13:06 +04:00
|
|
|
class TOCTest extends \PHPUnit_Framework_TestCase
|
2014-03-12 16:24:36 +07:00
|
|
|
{
|
2014-03-28 13:50:53 +07:00
|
|
|
/**
|
|
|
|
|
* Add and get title
|
2014-03-12 16:24:36 +07:00
|
|
|
*/
|
|
|
|
|
public function testAddAndGetTitle()
|
|
|
|
|
{
|
|
|
|
|
$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,
|
|
|
|
|
);
|
2014-04-06 01:10:04 +07:00
|
|
|
$toc = new TOC();
|
2014-03-12 16:24:36 +07:00
|
|
|
|
|
|
|
|
foreach ($titles as $text => $depth) {
|
2014-04-06 01:10:04 +07:00
|
|
|
$response = $toc->addTitle($text, $depth);
|
2014-03-12 16:24:36 +07:00
|
|
|
}
|
|
|
|
|
$this->assertEquals($anchor, $response[0]);
|
|
|
|
|
$this->assertEquals($bookmark, $response[1]);
|
|
|
|
|
|
|
|
|
|
$i = 0;
|
2014-04-06 01:10:04 +07:00
|
|
|
$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++;
|
|
|
|
|
}
|
2014-04-05 00:57:50 +07:00
|
|
|
|
2014-04-08 16:09:31 +07:00
|
|
|
TOC::resetTitles();
|
2014-04-06 11:52:16 +07:00
|
|
|
$this->assertEquals(0, count($toc->getTitles()));
|
2014-04-06 00:31:05 +07:00
|
|
|
}
|
2014-03-12 16:24:36 +07:00
|
|
|
}
|