diff options
Diffstat (limited to 'test/HTML5')
-rw-r--r-- | test/HTML5/Html5Test.php | 15 | ||||
-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 | ||||
-rw-r--r-- | test/HTML5/Serializer/OutputRulesTest.php | 11 | ||||
-rw-r--r-- | test/HTML5/Serializer/TraverserTest.php | 37 |
6 files changed, 117 insertions, 15 deletions
diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php index 13f5b19..dcb51cd 100644 --- a/test/HTML5/Html5Test.php +++ b/test/HTML5/Html5Test.php @@ -26,6 +26,15 @@ class Html5Test extends TestCase { $dom = \HTML5::load(__DIR__ . '/Html5Test.html'); $this->assertInstanceOf('\DOMDocument', $dom); $this->assertEmpty($dom->errors); + + $file = fopen(__DIR__ . '/Html5Test.html', 'r'); + $dom = \HTML5::load($file); + $this->assertInstanceOf('\DOMDocument', $dom); + $this->assertEmpty($dom->errors); + + $dom = \HTML5::loadHTMLFile(__DIR__ . '/Html5Test.html'); + $this->assertInstanceOf('\DOMDocument', $dom); + $this->assertEmpty($dom->errors); } public function testLoadHTML() { @@ -125,7 +134,7 @@ class Html5Test extends TestCase { </body> </html>'); - $this->assertEmpty($dom->errors); + $this->assertEmpty($dom->errors, print_r($dom->errors, TRUE)); // Test a mixed case attribute. $list = $dom->getElementsByTagName('svg'); @@ -192,11 +201,13 @@ class Html5Test extends TestCase { <f:name>Big rectangle thing</f:name> <f:width>40</f:width> <f:length>80</f:length> - </f:rug>"); + </f:rug> + <sarcasm>um, yeah</sarcasm>"); $this->assertEmpty($dom->errors); $markup = \HTML5::saveHTML($dom); $this->assertRegExp('|<f:name>Big rectangle thing</f:name>|',$markup); + $this->assertRegExp('|<sarcasm>um, yeah</sarcasm>|',$markup); } public function testElements() { 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); + } + } diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index a451055..61e2d50 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -330,4 +330,15 @@ class OutputRulesTest extends \HTML5\Tests\TestCase { $this->assertRegExp('|<csymbol definitionURL="http://www.example.com/mathops/multiops.html#plusminus">|', $content); } + function testProcessorInstruction() { + $dom = \HTML5::loadHTMLFragment('<?foo bar ?>'); + + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, \HTML5::options()); + $t = new Traverser($dom, $stream, $r, \HTML5::options()); + + $r->processorInstruction($dom->firstChild); + $content = stream_get_contents($stream, -1, 0); + $this->assertRegExp('|<\?foo bar \?>|', $content); + } } diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php index 6fa5c1e..5816bfc 100644 --- a/test/HTML5/Serializer/TraverserTest.php +++ b/test/HTML5/Serializer/TraverserTest.php @@ -59,20 +59,33 @@ class TraverserTest extends \HTML5\Tests\TestCase { $this->assertInstanceOf('\HTML5\Serializer\Traverser', $t); } - function testFragment() { - $html = '<span class="bar">foo</span><span></span><div>bar</div>'; - $input = new \HTML5\Parser\StringInputStream($html); - $dom = \HTML5::parseFragment($input); + function testFragment() { + $html = '<span class="bar">foo</span><span></span><div>bar</div>'; + $input = new \HTML5\Parser\StringInputStream($html); + $dom = \HTML5::parseFragment($input); - //fprintf(STDOUT, print_r($dom, TRUE)); + $this->assertInstanceOf('\DOMDocumentFragment', $dom); - $this->assertInstanceOf('\DOMDocumentFragment', $dom); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, \HTML5::options()); + $t = new Traverser($dom, $stream, $r, \HTML5::options()); + + $out = $t->walk(); + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); + } + + function testProcessorInstruction() { + $html = '<?foo bar ?>'; + $input = new \HTML5\Parser\StringInputStream($html); + $dom = \HTML5::parseFragment($input); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, \HTML5::options()); - $t = new Traverser($dom, $stream, $r, \HTML5::options()); + $this->assertInstanceOf('\DOMDocumentFragment', $dom); - $out = $t->walk(); - $this->assertEquals($html, stream_get_contents($stream, -1, 0)); - } + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, \HTML5::options()); + $t = new Traverser($dom, $stream, $r, \HTML5::options()); + + $out = $t->walk(); + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); + } } |