public function testBuildTOCWithWeirdDOM() { $document = <<<EOL <h2>h2</h2> <h3>h3</h3> <h2>h2</h2> <h4>h4</h4> <h3>h3</h3> EOL; $expected = array(0 => array('title' => null, 'id' => null, 'children' => array(1 => array('title' => 'h2', 'id' => 'h2', 'children' => array(1 => array('title' => 'h3', 'id' => 'h3', 'children' => array()))), 2 => array('title' => 'h2', 'id' => 'h2-2', 'children' => array(1 => array('title' => null, 'id' => null, 'children' => array(1 => array('title' => 'h4', 'id' => 'h4', 'children' => array()))), 2 => array('title' => 'h3', 'id' => 'h3-2', 'children' => array())))))); $this->assertSame($expected, Helpers::buildTOC($document)); }