PHPWord/tests/PhpWord/Tests/TOCTest.php

54 lines
1.3 KiB
PHP
Raw Normal View History

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
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Tests;
2014-03-12 16:24:36 +07: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
*/
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++;
}
TOC::resetTitles();
2014-04-06 11:52:16 +07:00
$this->assertEquals(0, count($toc->getTitles()));
}
2014-03-12 16:24:36 +07:00
}