summaryrefslogtreecommitdiff
path: root/test/HTML5/Parser
diff options
context:
space:
mode:
authorMatt Butcher <[email protected]>2013-04-12 21:33:17 -0500
committerMatt Butcher <[email protected]>2013-04-12 21:33:17 -0500
commit3d8562c11dd5e7591ea29562c43fb74939836b83 (patch)
tree38e0e3e6aed4934c97777db9b18ab9bc9b91c9a3 /test/HTML5/Parser
parentffcfa507b081cf132db5b90c26bfad66d79a4eb4 (diff)
CDATA handling is complete. DOCTYPE is begun.
Diffstat (limited to 'test/HTML5/Parser')
-rw-r--r--test/HTML5/Parser/EventStack.php4
-rw-r--r--test/HTML5/Parser/TokenizerTest.php35
2 files changed, 38 insertions, 1 deletions
diff --git a/test/HTML5/Parser/EventStack.php b/test/HTML5/Parser/EventStack.php
index 4d82629..478ae60 100644
--- a/test/HTML5/Parser/EventStack.php
+++ b/test/HTML5/Parser/EventStack.php
@@ -52,6 +52,10 @@ class EventStack implements EventHandler {
$this->store('comment', array($cdata));
}
+ public function cdata($data) {
+ $this->store('cdata', func_get_args());
+ }
+
public function text($cdata) {
//fprintf(STDOUT, "Received TEXT event with: " . $cdata);
$this->store('text', array($cdata));
diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php
index ead02d0..40259ea 100644
--- a/test/HTML5/Parser/TokenizerTest.php
+++ b/test/HTML5/Parser/TokenizerTest.php
@@ -90,10 +90,17 @@ class TokenizerTest extends \HTML5\Tests\TestCase {
$bogus = array(
'</+this is a bogus comment. +>',
'<!+this is a bogus comment. !>',
+ '<!D OCTYPE foo bar>',
'<!DOCTYEP foo bar>',
+ '<![CADATA[ TEST ]]>',
+ '<![CDATA Hello ]]>',
+ '<![CDATA[ Hello [[>',
+ '<!CDATA[[ test ]]>',
+ '<![CDATA[',
+ '<![CDATA[hellooooo hello',
);
foreach ($bogus as $str) {
- $events = $this->parse($str . ' ');
+ $events = $this->parse($str);
$e0 = $events->get(0);
$this->assertEquals('error', $e0['name']);
$e1 = $events->get(1);
@@ -182,6 +189,7 @@ class TokenizerTest extends \HTML5\Tests\TestCase {
'<!-->' => '',
'<!--Hello' => 'Hello',
"<!--\0Hello" => UTF8Utils::FFFD . 'Hello',
+ '<!--' => '',
);
foreach ($fail as $test => $expected) {
$events = $this->parse($test);
@@ -194,4 +202,29 @@ class TokenizerTest extends \HTML5\Tests\TestCase {
}
}
+
+ public function testCDATASection() {
+ $good = array(
+ '<![CDATA[ This is a test. ]]>' => ' This is a test. ',
+ '<![CDATA[CDATA]]>' => 'CDATA',
+ '<![CDATA[ ]] > ]]>' => ' ]] > ',
+ '<![CDATA[ ]]>' => ' ',
+ );
+ foreach ($good as $test => $expects) {
+ $events = $this->parse($test);
+ $e1 = $events->get(0);
+ $this->assertEquals('cdata', $e1['name'], "CDATA section for " . $test . print_r($events, TRUE));
+ $this->assertEquals($expects, $e1['data'][0], "CDATA section for " . $test);
+ }
+ }
+
+ public function testText() {
+ $good = array(
+ 'a<br>b',
+ '<a>test</a>',
+ 'a<![[ test ]]>b',
+ 'a&amp;b',
+ );
+ $this->markTestIncomplete("Need tag parsing first.");
+ }
}