summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Farina <[email protected]>2013-05-02 19:49:32 -0400
committerMatt Farina <[email protected]>2013-05-02 19:49:32 -0400
commitec36cb8d909b4f8d36c9fd479265c053b3b813f1 (patch)
treece452a71e478ead17f9750871384c8fd5be99b6f /test
parentea8aedd526eaebf5c184047b82c05bb805b273c7 (diff)
parent6588cbeecefdd41010adf6f7ce88b5048bf0bba9 (diff)
Merge branch 'master' of github.com:technosophos/HTML5-PHP
Diffstat (limited to 'test')
-rw-r--r--test/HTML5/Parser/TreeBuildingRulesTest.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/HTML5/Parser/TreeBuildingRulesTest.php b/test/HTML5/Parser/TreeBuildingRulesTest.php
new file mode 100644
index 0000000..fe02893
--- /dev/null
+++ b/test/HTML5/Parser/TreeBuildingRulesTest.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * @file
+ * Test the Tree Builder's special-case rules.
+ */
+namespace HTML5\Parser;
+
+use HTML5\Elements;
+
+require_once __DIR__ . '/../TestCase.php';
+
+/**
+ * These tests are functional, not necessarily unit tests.
+ */
+class TreeBuildingRulesTest extends \HTML5\Tests\TestCase {
+
+ const HTML_STUB = '<!DOCTYPE html><html><head><title>test</title></head><body>%s</body></html>';
+
+ /**
+ * 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, '<ul id="a"><li>test<li>test2</ul><a></a>');
+ $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, '<dl id="a"><dt>Hello<dd>Hi</dl><a></a>');
+ $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);
+ }
+
+}