From 0226e0ca0dc70f9a0310b3eef045ee1c1e0ca3ac Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2022 20:00:46 +0300 Subject: split into a separate repo --- .../test/HTML5/Parser/TreeBuildingRulesTest.php | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 vendor/masterminds/html5/test/HTML5/Parser/TreeBuildingRulesTest.php (limited to 'vendor/masterminds/html5/test/HTML5/Parser/TreeBuildingRulesTest.php') diff --git a/vendor/masterminds/html5/test/HTML5/Parser/TreeBuildingRulesTest.php b/vendor/masterminds/html5/test/HTML5/Parser/TreeBuildingRulesTest.php new file mode 100644 index 0000000..45c68bc --- /dev/null +++ b/vendor/masterminds/html5/test/HTML5/Parser/TreeBuildingRulesTest.php @@ -0,0 +1,118 @@ +test%s'; + + /** + * Convenience function for parsing. + */ + protected function parse($string) + { + $treeBuilder = new DOMTreeBuilder(); + $scanner = new Scanner($string); + $parser = new Tokenizer($scanner, $treeBuilder); + + $parser->parse(); + + return $treeBuilder->document(); + } + + /** + * Convenience function for parsing fragments. + */ + protected function parseFragment($string) + { + $events = new DOMTreeBuilder(true); + $scanner = new Scanner($string); + $parser = new Tokenizer($scanner, $events); + + $parser->parse(); + + return $events->fragment(); + } + + public function testTDFragment() + { + $frag = $this->parseFragment('This is a test of the HTML5 parser'); + + $td = $frag->childNodes->item(0); + + $this->assertEquals(1, $frag->childNodes->length); + $this->assertEquals('td', $td->tagName); + $this->assertEquals('This is a test of the HTML5 parser', $td->nodeValue); + } + + 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 testHandleOptionGroupAndOption() + { + $html = sprintf(self::HTML_STUB, ''); + $doc = $this->parse($html); + + $list = $doc->getElementById('foo'); + + $this->assertEquals(1, $list->childNodes->length); + + $option = $list->childNodes->item(0); + $this->assertEquals('option', $option->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); + } +} -- cgit v1.2.3