%s'; /** * Convenience function for parsing. */ protected function parse($string) { $treeBuilder = new DOMTreeBuilder(); $input = new StringInputStream($string); $scanner = new Scanner($input); $parser = new Tokenizer($scanner, $treeBuilder); $parser->parse(); return $treeBuilder->document(); } public function testHasRules() { $doc = new \DOMDocument('1.0'); $engine = new TreeBuildingRules($doc); $this->assertTrue($engine->hasRules('li')); $this->assertFalse($engine->hasRules('imaginary')); } public function testHandleLI() { $html = sprintf(self::HTML_STUB, ''); $doc = $this->parse($html); $list = $doc->getElementById('a'); $this->assertEquals(2, $list->childNodes->length); foreach ($list->childNodes as $ele) { $this->assertEquals('li', $ele->tagName); } } public function testHandleDT() { $html = sprintf(self::HTML_STUB, '
Hello
Hi
'); $doc = $this->parse($html); $list = $doc->getElementById('a'); $this->assertEquals(2, $list->childNodes->length); $this->assertEquals('dt', $list->firstChild->tagName); $this->assertEquals('dd', $list->lastChild->tagName); } public function testTable() { $html = sprintf(self::HTML_STUB, '
foobarbaz'); $doc = $this->parse($html); $list = $doc->getElementById('a'); $this->assertEquals(3, $list->childNodes->length); $this->assertEquals('th', $list->firstChild->tagName); $this->assertEquals('td', $list->lastChild->tagName); } }