From 273235b13c072713052e5845ff107e9f197c4d61 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Thu, 26 Sep 2013 12:23:22 -0400 Subject: The serializer was a wrapper for serializing the same way html5 at the top level was a wrapper for parsing. Moved the serializing interface to be in the same form as the parser for consistency. --- test/HTML5/Html5Test.php | 129 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'test/HTML5/Html5Test.php') diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php index 6511ae5..13f5b19 100644 --- a/test/HTML5/Html5Test.php +++ b/test/HTML5/Html5Test.php @@ -5,6 +5,23 @@ require_once 'TestCase.php'; class Html5Test extends TestCase { + /** + * Parse and serialize a string. + */ + protected function cycle($html) { + $dom = \HTML5::loadHTML('' . $html . ''); + $out = \HTML5::saveHTML($dom); + + return $out; + } + + protected function cycleFragment($fragment) { + $dom = \HTML5::loadHTMLFragment($fragment); + $out = \HTML5::saveHTML($dom); + + return $out; + } + public function testLoad() { $dom = \HTML5::load(__DIR__ . '/Html5Test.html'); $this->assertInstanceOf('\DOMDocument', $dom); @@ -182,4 +199,116 @@ class Html5Test extends TestCase { $this->assertRegExp('|Big rectangle thing|',$markup); } + public function testElements() { + // Should have content. + $res = $this->cycle('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + + // Should be empty + $res = $this->cycle(''); + $this->assertRegExp('||', $res); + + // Should have content. + $res = $this->cycleFragment('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + + // Should be empty + $res = $this->cycleFragment(''); + $this->assertRegExp('||', $res); + + // Should have no closing tag. + $res = $this->cycle('
'); + $this->assertRegExp('|
|', $res); + + } + + public function testAttributes() { + $res = $this->cycle('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + + // XXX: Note that spec does NOT require attrs in the same order. + $res = $this->cycle('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + + $res = $this->cycle('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + + $res = $this->cycleFragment('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + + // XXX: Note that spec does NOT require attrs in the same order. + $res = $this->cycleFragment('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + + $res = $this->cycleFragment('
FOO
'); + $this->assertRegExp('|
FOO
|', $res); + } + + public function testPCData() { + $res = $this->cycle('This is a test.'); + $this->assertRegExp('|This is a test.|', $res); + + $res = $this->cycleFragment('This is a test.'); + $this->assertRegExp('|This is a test.|', $res); + + $res = $this->cycle('This + is + a + test.'); + + // Check that newlines are there, but don't count spaces. + $this->assertRegExp('|This\n\s*is\n\s*a\n\s*test.|', $res); + + $res = $this->cycleFragment('This + is + a + test.'); + + // Check that newlines are there, but don't count spaces. + $this->assertRegExp('|This\n\s*is\n\s*a\n\s*test.|', $res); + + $res = $this->cycle('This is a test.'); + $this->assertRegExp('|This is a test.|', $res); + + $res = $this->cycleFragment('This is a test.'); + $this->assertRegExp('|This is a test.|', $res); + } + + public function testUnescaped() { + $res = $this->cycle(''); + $this->assertRegExp('|2 < 1|', $res); + + $res = $this->cycle(''); + $this->assertRegExp('|div>div>div|', $res); + + $res = $this->cycleFragment(''); + $this->assertRegExp('|2 < 1|', $res); + + $res = $this->cycleFragment(''); + $this->assertRegExp('|div>div>div|', $res); + } + + public function testEntities() { + $res = $this->cycle('Apples & bananas.'); + $this->assertRegExp('|Apples & bananas.|', $res); + + $res = $this->cycleFragment('Apples & bananas.'); + $this->assertRegExp('|Apples & bananas.|', $res); + } + + public function testComment() { + $res = $this->cycle('ab'); + $this->assertRegExp('||', $res); + + $res = $this->cycleFragment('ab'); + $this->assertRegExp('||', $res); + } + + public function testCDATA() { + $res = $this->cycle('a a test. ]]>b'); + $this->assertRegExp('| a test\. \]\]>|', $res); + + $res = $this->cycleFragment('a a test. ]]>b'); + $this->assertRegExp('| a test\. \]\]>|', $res); + } } -- cgit v1.2.3