assertInstanceOf('\TOC\TocGenerator', $obj);
}
// ---------------------------------------------------------------
public function testGetItemsMatchesOnlyElementsWithIDs()
{
$obj = new TocGenerator();
$html = "
A Header
Foobar
B Header
C Header
";
$this->assertEquals(['a' => 'A Header', 'c' => 'C Header'], $obj->getItems($html, 1, 3));
}
// ---------------------------------------------------------------
public function testGetItemsUsesTitleForDisplayTextWhenAvailableAndPlainTextWhenNot()
{
$obj = new TocGenerator();
$html = 'A Header
';
$html .= 'B Header
';
$html .= 'C Header
';
$this->assertEquals(
['a' => 'Foo Bar!', 'b' => 'B Header', 'c' => 'Baz Biz~'],
$obj->getItems($html, 1, 3)
);
}
// ---------------------------------------------------------------
public function testGetItemsGetsOnlyHeaderLevelsSpecified()
{
$obj = new TocGenerator();
$html = 'A Header
';
$html .= 'B Header
';
$html .= 'C Header
';
$html .= 'D Header
';
$html .= 'E Header
';
$html .= 'F Header
';
$this->assertCount(1, $obj->getItems($html, 5, 1));
$this->assertCount(2, $obj->getItems($html, 5, 5));
$this->assertCount(6, $obj->getItems($html, -1, 20));
}
// ---------------------------------------------------------------
public function testGetHtmlItemsReturnsExpectedListItems()
{
$obj = new TocGenerator();
$html = 'A Header
';
$html .= 'B Header
';
$html .= 'C Header
';
$this->assertEquals(
"Foo Bar!B HeaderBaz Biz~",
$obj->getHtmlItems($html, 1, 3)
);
}
// ---------------------------------------------------------------
public function testGetItemsReturnsAnEmptyArrayWhenNoContentOrMatches()
{
$obj = new TocGenerator();
$this->assertEquals([], $obj->getItems("Boo
Bar
"));
$this->assertEquals([], $obj->getItems(""));
}
}
/* EOF: TocGeneratorTest.php */