diff options
author | Matt Butcher <[email protected]> | 2014-02-11 09:56:01 -0700 |
---|---|---|
committer | Matt Butcher <[email protected]> | 2014-02-11 09:56:01 -0700 |
commit | 44e8e23626bf619844baf9983e931d2f58606377 (patch) | |
tree | 62625f63a954ab5a3f9bb4184039a68496e3896a /test/HTML5/Parser | |
parent | 77ad931cd824feb33eebae08cf3a5a47bce1e337 (diff) | |
parent | 3b691837c6d7a0969137048fbda274463d6b1d7c (diff) |
Merge branch 'master' of github.com:Masterminds/html5-php
Diffstat (limited to 'test/HTML5/Parser')
-rw-r--r-- | test/HTML5/Parser/DOMTreeBuilderTest.php | 50 | ||||
-rw-r--r-- | test/HTML5/Parser/TokenizerTest.php | 8 | ||||
-rw-r--r-- | test/HTML5/Parser/TreeBuildingRulesTest.php | 11 |
3 files changed, 68 insertions, 1 deletions
diff --git a/test/HTML5/Parser/DOMTreeBuilderTest.php b/test/HTML5/Parser/DOMTreeBuilderTest.php index adfc2c9..6eeafe8 100644 --- a/test/HTML5/Parser/DOMTreeBuilderTest.php +++ b/test/HTML5/Parser/DOMTreeBuilderTest.php @@ -301,6 +301,14 @@ class DOMTreeBuilderTest extends \HTML5\Tests\TestCase { $this->assertEquals('textPath', $textPath->tagName); } + public function testNoScript() { + $html = '<!DOCTYPE html><html><head><noscript>No JS</noscript></head></html>'; + $doc = $this->parse($html); + $this->assertEmpty($doc->errors); + $noscript = $doc->getElementsByTagName('noscript')->item(0); + $this->assertEquals('noscript', $noscript->tagName); + } + /** * Regression for issue #13 */ @@ -314,4 +322,46 @@ class DOMTreeBuilderTest extends \HTML5\Tests\TestCase { $this->assertEquals('span', $span->tagName); $this->assertEquals('Test', $span->textContent); } + + public function testInstructionProcessor() { + $string = '<!DOCTYPE html><html><?foo bar ?></html>'; + + $treeBuilder = new DOMTreeBuilder(); + $is = new InstructionProcessorMock(); + $treeBuilder->setInstructionProcessor($is); + + $input = new StringInputStream($string); + $scanner = new Scanner($input); + $parser = new Tokenizer($scanner, $treeBuilder); + + $parser->parse(); + $dom = $treeBuilder->document(); + $div = $dom->getElementsByTagName('div')->item(0); + + $this->assertEquals(1, $is->count); + $this->assertEquals('foo', $is->name); + $this->assertEquals('bar ', $is->data); + $this->assertEquals('div', $div->tagName); + $this->assertEquals('foo', $div->textContent); + } +} + +class InstructionProcessorMock implements \HTML5\InstructionProcessor { + + public $name = NULL; + public $data = NULL; + public $count = 0; + + public function process(\DOMElement $element, $name, $data) { + $this->name = $name; + $this->data = $data; + $this->count++; + + $div = $element->ownerDocument->createElement("div"); + $div->nodeValue = 'foo'; + + $element->appendChild($div); + + return $div; + } } diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php index 0ac987f..231827c 100644 --- a/test/HTML5/Parser/TokenizerTest.php +++ b/test/HTML5/Parser/TokenizerTest.php @@ -142,7 +142,7 @@ class TokenizerTest extends \HTML5\Tests\TestCase { '</test >' => 'test', '</thisIsTheTagThatDoesntEndItJustGoesOnAndOnMyFriend>' => - 'thisIsTheTagThatDoesntEndItJustGoesOnAndOnMyFriend', + 'thisisthetagthatdoesntenditjustgoesonandonmyfriend', // See 8.2.4.10, which requires this and does not say error. '</a<b>' => 'a<b', ); @@ -427,6 +427,12 @@ class TokenizerTest extends \HTML5\Tests\TestCase { $this->assertEventEquals('text', $expects, $events->get(2)); } + // Testing case sensitivity + $events = $this->parse('<TITLE>a test</TITLE>'); + $this->assertEventEquals('startTag', 'title', $events->get(0)); + $this->assertEventEquals('text', 'a test', $events->get(1)); + $this->assertEventEquals('endTag', 'title', $events->get(2)); + } public function testText() { diff --git a/test/HTML5/Parser/TreeBuildingRulesTest.php b/test/HTML5/Parser/TreeBuildingRulesTest.php index fe02893..a247cea 100644 --- a/test/HTML5/Parser/TreeBuildingRulesTest.php +++ b/test/HTML5/Parser/TreeBuildingRulesTest.php @@ -62,4 +62,15 @@ class TreeBuildingRulesTest extends \HTML5\Tests\TestCase { $this->assertEquals('dd', $list->lastChild->tagName); } + public function testTable() { + $html = sprintf(self::HTML_STUB, '<table><thead id="a"><th>foo<td>bar<td>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); + } + } |