summaryrefslogtreecommitdiff
path: root/test/HTML5
diff options
context:
space:
mode:
authorMatt Butcher <[email protected]>2013-04-24 20:09:02 -0500
committerMatt Butcher <[email protected]>2013-04-24 20:09:02 -0500
commit6815b2bd3a08201f6a75f09f7e24b50c5d3aeab2 (patch)
treefb547ecaeac2add94e6174dab62158791bff8dcb /test/HTML5
parent36d1367a7e365e1f3a4d63161999970799257e42 (diff)
parentfe3d7b815756b6f9ec3bad7c9bfe400b6ea11222 (diff)
Merge branch 'master' of github.com:technosophos/HTML5-PHP
Diffstat (limited to 'test/HTML5')
-rw-r--r--test/HTML5/ElementsTest.php19
-rw-r--r--test/HTML5/Parser/DOMTreeBuilderTest.php91
-rw-r--r--test/HTML5/Parser/EventStack.php6
3 files changed, 111 insertions, 5 deletions
diff --git a/test/HTML5/ElementsTest.php b/test/HTML5/ElementsTest.php
index 20161bb..69d0675 100644
--- a/test/HTML5/ElementsTest.php
+++ b/test/HTML5/ElementsTest.php
@@ -322,4 +322,21 @@ class ElementsTest extends TestCase {
}
}
-} \ No newline at end of file
+ public function testElement() {
+ foreach ($this->html5Elements as $element) {
+ $this->assertGreaterThan(0, Elements::element($element));
+ }
+ $nonhtml5 = array('foo', 'bar', 'baz');
+ foreach ($nonhtml5 as $element) {
+ $this->assertFalse(Elements::element($element));
+ }
+ }
+
+ public function testIsA() {
+ $this->assertTrue(Elements::isA('script', Elements::KNOWN_ELEMENT));
+ $this->assertFalse(Elements::isA('scriptypoo', Elements::KNOWN_ELEMENT));
+ $this->assertTrue(Elements::isA('script', Elements::TEXT_RAW));
+ $this->assertFalse(Elements::isA('script', Elements::TEXT_RCDATA));
+ }
+
+}
diff --git a/test/HTML5/Parser/DOMTreeBuilderTest.php b/test/HTML5/Parser/DOMTreeBuilderTest.php
index 6ffae75..a901238 100644
--- a/test/HTML5/Parser/DOMTreeBuilderTest.php
+++ b/test/HTML5/Parser/DOMTreeBuilderTest.php
@@ -1,11 +1,98 @@
<?php
/**
* @file
- * Test the Scanner. This requires the InputStream tests are all good.
+ * Test the Tree Builder.
*/
namespace HTML5\Parser;
+use HTML5\Elements;
+
require_once __DIR__ . '/../TestCase.php';
-class DOMTreeParserTest extends \HTML5\Tests\TestCase {
+/**
+ * These tests are functional, not necessarily unit tests.
+ */
+class DOMTreeBuilderTest extends \HTML5\Tests\TestCase {
+
+ /**
+ * 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 testDocument() {
+ $html = "<!DOCTYPE html><html></html>";
+ $doc = $this->parse($html);
+
+ $this->assertInstanceOf('\DOMDocument', $doc);
+ $this->assertEquals('html', $doc->documentElement->tagName);
+ }
+
+ public function testElements() {
+ $html = "<!DOCTYPE html><html><head><title></title></head><body></body></html>";
+ $doc = $this->parse($html);
+ $root = $doc->documentElement;
+
+ $this->assertEquals('html', $root->tagName);
+ $this->assertEquals('html', $root->localName);
+ $this->assertEquals('html', $root->nodeName);
+
+ $this->assertEquals(2, $root->childNodes->length);
+ $kids = $root->childNodes;
+
+ $this->assertEquals('head', $kids->item(0)->tagName);
+ $this->assertEquals('body', $kids->item(1)->tagName);
+
+ $head = $kids->item(0);
+ $this->assertEquals(1, $head->childNodes->length);
+ $this->assertEquals('title', $head->childNodes->item(0)->tagName);
+ }
+
+ public function testAttributes() {
+ $html = "<!DOCTYPE html>
+ <html>
+ <head><title></title></head>
+ <body id='a' class='b c'></body>
+ </html>";
+ $doc = $this->parse($html);
+ $root = $doc->documentElement;
+
+ $body = $root->GetElementsByTagName('body')->item(0);
+ $this->assertEquals('body', $body->tagName);
+ $this->assertTrue($body->hasAttributes());
+ $this->assertEquals('a', $body->getAttribute('id'));
+ $this->assertEquals('b c', $body->getAttribute('class'));
+
+ $body2 = $doc->getElementById('a');
+ $this->assertEquals('body', $body2->tagName);
+ $this->assertEquals('a', $body2->getAttribute('id'));
+ }
+
+ public function testComment() {
+ $this->markTestIncomplete("Incomplete.");
+ }
+
+ public function testCDATA() {
+ $this->markTestIncomplete("Incomplete.");
+ }
+
+ public function testText() {
+ $this->markTestIncomplete("Incomplete.");
+ }
+
+ public function testParseErrors() {
+ $this->markTestIncomplete("Incomplete.");
+ }
+
+ public function testProcessingInstruction() {
+ $this->markTestIncomplete("Incomplete.");
+ }
}
diff --git a/test/HTML5/Parser/EventStack.php b/test/HTML5/Parser/EventStack.php
index c9ac20e..1f56ea9 100644
--- a/test/HTML5/Parser/EventStack.php
+++ b/test/HTML5/Parser/EventStack.php
@@ -1,13 +1,15 @@
<?php
namespace HTML5\Parser;
+use HTML5\Elements;
+
/**
* This testing class gathers events from a parser and builds a stack of events.
* It is useful for checking the output of a tokenizer.
*
* IMPORTANT:
*
- * The startTag event also kicks the parser into TEXTMODE_RAW when it encounters
+ * The startTag event also kicks the parser into TEXT_RAW when it encounters
* script or pre tags. This is to match the behavior required by the HTML5 spec,
* which says that the tree builder must tell the tokenizer when to switch states.
*/
@@ -49,7 +51,7 @@ class EventStack implements EventHandler {
$args = func_get_args();
$this->store('startTag', $args);
if ($name == 'pre' || $name == 'script') {
- return Tokenizer::TEXTMODE_RAW;
+ return Elements::TEXT_RAW;
}
}