*/ class TocGeneratorTest extends \PHPUnit_Framework_TestCase { public function testInstantiateSucceeds() { $obj = new TocGenerator(); $this->assertInstanceOf('\TOC\TocGenerator', $obj); } // --------------------------------------------------------------- public function testGetMenuTraversesLevelsCorrectly() { $obj = new TocGenerator(); $html = "

A-Header

Foobar

B-Header

C-Header

D-Header

E-Header

F-Header

G-Header

H-Header

Hi
"; $fixture = array_filter(array_map('trim', file(__DIR__ . '/fixtures/testHtmlList.html'))); $actual = array_filter(array_map('trim', explode(PHP_EOL, $obj->getHtmlMenu($html, 1, 6)))); $this->assertEquals($fixture, $actual); } // --------------------------------------------------------------- public function testGetMenuMatchesOnlyElementsWithIDs() { $html = "

A-Header

Foobar

B-Header

C-Header

"; $obj = new TocGenerator(); $menu = $obj->getMenu($html, 1); $this->assertCount(2, $menu); $this->assertEquals('A-Header', $menu->getFirstChild()->getLabel()); $this->assertEquals('B-Header', $menu->getLastChild()->getLabel()); } // --------------------------------------------------------------- public function testGetMenuUsesTitleForDisplayTextWhenAvailableAndPlainTextWhenNot() { $obj = new TocGenerator(); $html = '

A Header

'; $html .= '

B Header

'; $html .= '

C Header

'; $menu = $obj->getMenu($html, 1, 3); $arr = TOCTestUtils::flattenMenuItems($menu); $this->assertEquals('Foo Bar!', $arr[0]->getLabel()); $this->assertEquals('B Header', $arr[1]->getLabel()); $this->assertEquals('Baz Biz~', $arr[2]->getLabel()); } // --------------------------------------------------------------- public function testGetMenuGetsOnlyHeaderLevelsSpecified() { $obj = new TocGenerator(); $html = '

A Header

'; $html .= '

B Header

'; $html .= '

C Header

'; $html .= '

D Header

'; $html .= '
E Header
'; $html .= '
F Header
'; $this->assertCount(1, TOCTestUtils::flattenMenuItems($obj->getMenu($html, 5, 1))); $this->assertCount(2, TOCTestUtils::flattenMenuItems($obj->getMenu($html, 5, 5))); // What's up with this? //$this->assertCount(6, TOCTestUtils::flattenMenuItems($obj->getMenu($html, -1, 20))); } // --------------------------------------------------------------- public function testGetMenuReturnsAnEmptyArrayWhenNoContentOrMatches() { $obj = new TocGenerator(); $this->assertEquals(0, count($obj->getMenu("

Boo

Bar

"))); $this->assertEquals(0, count($obj->getMenu(""))); } } /* EOF: TocGeneratorTest.php */