X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fmasterminds%2Fhtml5%2Ftest%2FHTML5%2FParser%2FTreeBuildingRulesTest.php;fp=vendor%2Fmasterminds%2Fhtml5%2Ftest%2FHTML5%2FParser%2FTreeBuildingRulesTest.php;h=de94d06201c1eb95963fd48c30f9409274ee5d2f;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5
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 000000000..de94d0620
--- /dev/null
+++ b/vendor/masterminds/html5/test/HTML5/Parser/TreeBuildingRulesTest.php
@@ -0,0 +1,117 @@
+
test%s';
+
+ /**
+ * Convenience function for parsing.
+ */
+ protected function parse($string)
+ {
+ $treeBuilder = new DOMTreeBuilder();
+ $scanner = new Scanner(new StringInputStream($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(new StringInputStream($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, 'foo | bar | baz');
+ $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);
+ }
+}
|