diff options
author | Titouan Galopin <[email protected]> | 2018-11-25 00:58:42 +0100 |
---|---|---|
committer | Titouan Galopin <[email protected]> | 2018-11-25 14:58:29 +0100 |
commit | d829a30e092ea5d868b93a258724b12f9aa313fd (patch) | |
tree | 1c8819b825738ce95d87d96e6e2cafeb2c7f14c8 /test/HTML5/Parser | |
parent | d39a98a478c95e0df86ed564650f7326244116e2 (diff) |
Fix coding style
Diffstat (limited to 'test/HTML5/Parser')
-rw-r--r-- | test/HTML5/Parser/CharacterReferenceTest.php | 2 | ||||
-rw-r--r-- | test/HTML5/Parser/DOMTreeBuilderTest.php | 102 | ||||
-rw-r--r-- | test/HTML5/Parser/EventStack.php | 14 | ||||
-rw-r--r-- | test/HTML5/Parser/EventStackError.php | 1 | ||||
-rw-r--r-- | test/HTML5/Parser/InstructionProcessorMock.php | 6 | ||||
-rw-r--r-- | test/HTML5/Parser/ScannerTest.php | 9 | ||||
-rw-r--r-- | test/HTML5/Parser/TokenizerTest.php | 269 | ||||
-rw-r--r-- | test/HTML5/Parser/TreeBuildingRulesTest.php | 8 | ||||
-rw-r--r-- | test/HTML5/Parser/UTF8UtilsTest.php | 34 |
9 files changed, 228 insertions, 217 deletions
diff --git a/test/HTML5/Parser/CharacterReferenceTest.php b/test/HTML5/Parser/CharacterReferenceTest.php index 762bcc2..a5eee73 100644 --- a/test/HTML5/Parser/CharacterReferenceTest.php +++ b/test/HTML5/Parser/CharacterReferenceTest.php @@ -3,13 +3,13 @@ * @file * Test the Scanner. This requires the InputStream tests are all good. */ + namespace Masterminds\HTML5\Tests\Parser; use Masterminds\HTML5\Parser\CharacterReference; class CharacterReferenceTest extends \Masterminds\HTML5\Tests\TestCase { - public function testLookupName() { $this->assertEquals('&', CharacterReference::lookupName('amp')); diff --git a/test/HTML5/Parser/DOMTreeBuilderTest.php b/test/HTML5/Parser/DOMTreeBuilderTest.php index ef1b3cb..21e9cea 100644 --- a/test/HTML5/Parser/DOMTreeBuilderTest.php +++ b/test/HTML5/Parser/DOMTreeBuilderTest.php @@ -3,6 +3,7 @@ * @file * Test the Tree Builder. */ + namespace Masterminds\HTML5\Tests\Parser; use Masterminds\HTML5\Parser\Scanner; @@ -48,7 +49,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testDocument() { - $html = "<!DOCTYPE html><html></html>"; + $html = '<!DOCTYPE html><html></html>'; $doc = $this->parse($html); $this->assertInstanceOf('\DOMDocument', $doc); @@ -101,9 +102,10 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase </body> </html>', $doc->saveXML()); } + public function testBareAmpersandNotAllowedInBody() { - $html = "<!doctype html> + $html = '<!doctype html> <html> <body> a&b @@ -113,7 +115,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase a&+ a& -- valid </body> - </html>"; + </html>'; $doc = $this->parse($html); $this->assertCount(5, $this->errors); @@ -132,28 +134,28 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testStrangeCapitalization() { - $html = "<!doctype html> + $html = '<!doctype html> <html> <head> <Title>Hello, world!</TitlE> </head> <body>TheBody<script>foo</script></body> - </html>"; + </html>'; $doc = $this->parse($html); $this->assertInstanceOf('\DOMDocument', $doc); $this->assertEquals('html', $doc->documentElement->tagName); - $xpath = new \DOMXPath( $doc ); - $xpath->registerNamespace( "x", "http://www.w3.org/1999/xhtml" ); + $xpath = new \DOMXPath($doc); + $xpath->registerNamespace('x', 'http://www.w3.org/1999/xhtml'); - $this->assertEquals("Hello, world!", $xpath->query( "//x:title" )->item( 0 )->nodeValue); - $this->assertEquals("foo", $xpath->query( "//x:script" )->item( 0 )->nodeValue); + $this->assertEquals('Hello, world!', $xpath->query('//x:title')->item(0)->nodeValue); + $this->assertEquals('foo', $xpath->query('//x:script')->item(0)->nodeValue); } public function testDocumentWithDisabledNamespaces() { - $html = "<!DOCTYPE html><html></html>"; + $html = '<!DOCTYPE html><html></html>'; $doc = $this->parse($html, array('disable_html_ns' => true)); $this->assertInstanceOf('\DOMDocument', $doc); @@ -165,7 +167,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase { $targetDom = new \DOMDocument(); - $html = "<!DOCTYPE html><html></html>"; + $html = '<!DOCTYPE html><html></html>'; $doc = $this->parse($html, array('target_document' => $targetDom)); $this->assertInstanceOf('\DOMDocument', $doc); @@ -175,16 +177,16 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testDocumentFakeAttrAbsence() { - $html = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><body>foo</body></html>"; - $doc = $this->parse($html, array('xmlNamespaces'=>true)); + $html = '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><body>foo</body></html>'; + $doc = $this->parse($html, array('xmlNamespaces' => true)); $xp = new \DOMXPath($doc); - $this->assertEquals(0, $xp->query("//@html5-php-fake-id-attribute")->length); + $this->assertEquals(0, $xp->query('//@html5-php-fake-id-attribute')->length); } public function testFragment() { - $html = "<div>test</div><span>test2</span>"; + $html = '<div>test</div><span>test2</span>'; $doc = $this->parseFragment($html); $this->assertInstanceOf('\DOMDocumentFragment', $doc); @@ -197,7 +199,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testElements() { - $html = "<!DOCTYPE html><html><head><title></title></head><body></body></html>"; + $html = '<!DOCTYPE html><html><head><title></title></head><body></body></html>'; $doc = $this->parse($html); $root = $doc->documentElement; @@ -233,8 +235,8 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase { $dom = $this->parse('<!DOCTYPE html><html><body><a t:href="bar">foo</a></body></html>', array( 'implicitNamespaces' => array( - 't' => 'http://www.example.com' - ) + 't' => 'http://www.example.com', + ), )); $a = $dom->getElementsByTagName('a')->item(0); $attr = $a->getAttributeNode('t:href'); @@ -242,8 +244,8 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase $dom = $this->parse('<!DOCTYPE html><html><body><t:a>foo</t:a></body></html>', array( 'implicitNamespaces' => array( - 't' => 'http://www.example.com' - ) + 't' => 'http://www.example.com', + ), )); $list = $dom->getElementsByTagNameNS('http://www.example.com', 'a'); $this->assertEquals(1, $list->length); @@ -258,7 +260,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase </body> <div>foo</div> </html>', array( - 'xmlNamespaces' => true + 'xmlNamespaces' => true, )); $a = $dom->getElementsByTagName('a')->item(0); $attr = $a->getAttributeNode('t:href'); @@ -283,10 +285,9 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase <xn:d xmlns:xn="http://www.prefixed.com/xn" xmlns="http://www.prefixed.com/bar5_x" id="bar5"><x id="bar5_x"/></xn:d> </body> </html>', array( - 'xmlNamespaces' => true + 'xmlNamespaces' => true, )); - $this->assertEmpty($this->errors); $div = $dom->getElementById('div'); @@ -299,34 +300,34 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEquals('http://www.prefixed.com/bar1', $bar1->namespaceURI); $bar2 = $dom->getElementById('bar2'); - $this->assertEquals("http://www.prefixed.com/bar2", $bar2->namespaceURI); + $this->assertEquals('http://www.prefixed.com/bar2', $bar2->namespaceURI); $bar3 = $dom->getElementById('bar3'); - $this->assertEquals("http://www.w3.org/1999/xhtml", $bar3->namespaceURI); + $this->assertEquals('http://www.w3.org/1999/xhtml', $bar3->namespaceURI); $bar4 = $dom->getElementById('bar4'); - $this->assertEquals("http://www.prefixed.com/bar4", $bar4->namespaceURI); + $this->assertEquals('http://www.prefixed.com/bar4', $bar4->namespaceURI); $svg = $dom->getElementById('svg'); - $this->assertEquals("http://www.w3.org/2000/svg", $svg->namespaceURI); + $this->assertEquals('http://www.w3.org/2000/svg', $svg->namespaceURI); $prefixed = $dom->getElementById('prefixed'); - $this->assertEquals("http://www.prefixed.com", $prefixed->namespaceURI); + $this->assertEquals('http://www.prefixed.com', $prefixed->namespaceURI); $prefixed = $dom->getElementById('bar5'); - $this->assertEquals("http://www.prefixed.com/xn", $prefixed->namespaceURI); + $this->assertEquals('http://www.prefixed.com/xn', $prefixed->namespaceURI); $prefixed = $dom->getElementById('bar5_x'); - $this->assertEquals("http://www.prefixed.com/bar5_x", $prefixed->namespaceURI); + $this->assertEquals('http://www.prefixed.com/bar5_x', $prefixed->namespaceURI); } public function testMoveNonInlineElements() { - $doc = $this->parse('<p>line1<br/><hr/>line2</p>'); - $this->assertEquals('<html xmlns="http://www.w3.org/1999/xhtml"><p>line1<br/></p><hr/>line2</html>', $doc->saveXML($doc->documentElement), 'Move non-inline elements outside of inline containers.'); + $doc = $this->parse('<p>line1<br/><hr/>line2</p>'); + $this->assertEquals('<html xmlns="http://www.w3.org/1999/xhtml"><p>line1<br/></p><hr/>line2</html>', $doc->saveXML($doc->documentElement), 'Move non-inline elements outside of inline containers.'); - $doc = $this->parse('<p>line1<div>line2</div></p>'); - $this->assertEquals('<html xmlns="http://www.w3.org/1999/xhtml"><p>line1</p><div>line2</div></html>', $doc->saveXML($doc->documentElement), 'Move non-inline elements outside of inline containers.'); + $doc = $this->parse('<p>line1<div>line2</div></p>'); + $this->assertEquals('<html xmlns="http://www.w3.org/1999/xhtml"><p>line1</p><div>line2</div></html>', $doc->saveXML($doc->documentElement), 'Move non-inline elements outside of inline containers.'); } public function testAttributes() @@ -396,7 +397,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testMissingHtmlTag() { - $html = "<!DOCTYPE html><title>test</title>"; + $html = '<!DOCTYPE html><title>test</title>'; $doc = $this->parse($html); $this->assertEquals('html', $doc->documentElement->tagName); @@ -411,23 +412,23 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase $comment = $doc->documentElement->childNodes->item(0); $this->assertEquals(XML_COMMENT_NODE, $comment->nodeType); - $this->assertEquals("Hello World.", $comment->data); + $this->assertEquals('Hello World.', $comment->data); $html = '<!--Hello World.--><html></html>'; $doc = $this->parse($html); $comment = $doc->childNodes->item(1); $this->assertEquals(XML_COMMENT_NODE, $comment->nodeType); - $this->assertEquals("Hello World.", $comment->data); + $this->assertEquals('Hello World.', $comment->data); $comment = $doc->childNodes->item(2); $this->assertEquals(XML_ELEMENT_NODE, $comment->nodeType); - $this->assertEquals("html", $comment->tagName); + $this->assertEquals('html', $comment->tagName); } public function testCDATA() { - $html = "<!DOCTYPE html><html><math><![CDATA[test]]></math></html>"; + $html = '<!DOCTYPE html><html><math><![CDATA[test]]></math></html>'; $doc = $this->parse($html); $wrapper = $doc->getElementsByTagName('math')->item(0); @@ -439,7 +440,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testText() { - $html = "<!DOCTYPE html><html><head></head><body><math>test</math></body></html>"; + $html = '<!DOCTYPE html><html><head></head><body><math>test</math></body></html>'; $doc = $this->parse($html); $wrapper = $doc->getElementsByTagName('math')->item(0); @@ -449,8 +450,8 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEquals('test', $data->data); // The DomTreeBuilder has special handling for text when in before head mode. - $html = "<!DOCTYPE html><html> - Foo<head></head><body></body></html>"; + $html = '<!DOCTYPE html><html> + Foo<head></head><body></body></html>'; $doc = $this->parse($html); $this->assertEquals('Line 0, Col 0: Unexpected text. Ignoring: Foo', $this->errors[0]); $headElement = $doc->documentElement->firstChild; @@ -459,7 +460,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testParseErrors() { - $html = "<!DOCTYPE html><html><math><![CDATA[test"; + $html = '<!DOCTYPE html><html><math><![CDATA[test'; $doc = $this->parse($html); // We're JUST testing that we can access errors. Actual testing of @@ -488,7 +489,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase public function testAutocloseP() { - $html = "<!DOCTYPE html><html><body><p><figure></body></html>"; + $html = '<!DOCTYPE html><html><body><p><figure></body></html>'; $doc = $this->parse($html); $p = $doc->getElementsByTagName('p')->item(0); @@ -576,7 +577,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase } /** - * Regression for issue #13 + * Regression for issue #13. */ public function testRegressionHTMLNoBody() { @@ -635,13 +636,14 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase </body> </html> EOM; - $dom = $this->parse($html); + $dom = $this->parse($html); $this->assertSame(3, $dom->getElementById('first')->getElementsByTagName('option')->length); $this->assertSame(2, $dom->getElementById('second')->getElementsByTagName('option')->length); } - public function testVoidTag() { + public function testVoidTag() + { $html = <<<EOM <!DOCTYPE html> <html> @@ -660,7 +662,8 @@ EOM; $this->assertSame(0, $dom->getElementsByTagName('meta')->item(1)->childNodes->length); } - public function testIgnoreSelfClosingTag() { + public function testIgnoreSelfClosingTag() + { $html = <<<EOM <!DOCTYPE html> <html> @@ -677,7 +680,8 @@ EOM; $this->assertSame(1, $dom->getElementsByTagName('div')->item(0)->childNodes->length); } - public function testIAudioInParagraph() { + public function testIAudioInParagraph() + { $html = <<<EOM <!DOCTYPE html> <html> diff --git a/test/HTML5/Parser/EventStack.php b/test/HTML5/Parser/EventStack.php index 60e2abe..3d1de77 100644 --- a/test/HTML5/Parser/EventStack.php +++ b/test/HTML5/Parser/EventStack.php @@ -1,4 +1,5 @@ <?php + namespace Masterminds\HTML5\Tests\Parser; use Masterminds\HTML5\Elements; @@ -16,7 +17,6 @@ use Masterminds\HTML5\Parser\EventHandler; */ class EventStack implements EventHandler { - protected $stack; public function __construct() @@ -46,7 +46,7 @@ class EventStack implements EventHandler { $this->stack[] = array( 'name' => $event, - 'data' => $data + 'data' => $data, ); } @@ -56,7 +56,7 @@ class EventStack implements EventHandler $name, $type, $id, - $quirks + $quirks, ); $this->store('doctype', $args); } @@ -65,7 +65,7 @@ class EventStack implements EventHandler { $args = func_get_args(); $this->store('startTag', $args); - if ($name == 'pre' || $name == 'script') { + if ('pre' == $name || 'script' == $name) { return Elements::TEXT_RAW; } } @@ -73,14 +73,14 @@ class EventStack implements EventHandler public function endTag($name) { $this->store('endTag', array( - $name + $name, )); } public function comment($cdata) { $this->store('comment', array( - $cdata + $cdata, )); } @@ -93,7 +93,7 @@ class EventStack implements EventHandler { // fprintf(STDOUT, "Received TEXT event with: " . $cdata); $this->store('text', array( - $cdata + $cdata, )); } diff --git a/test/HTML5/Parser/EventStackError.php b/test/HTML5/Parser/EventStackError.php index e58fdff..05c0a49 100644 --- a/test/HTML5/Parser/EventStackError.php +++ b/test/HTML5/Parser/EventStackError.php @@ -1,4 +1,5 @@ <?php + namespace Masterminds\HTML5\Tests\Parser; class EventStackError extends \Exception diff --git a/test/HTML5/Parser/InstructionProcessorMock.php b/test/HTML5/Parser/InstructionProcessorMock.php index 32a2204..4637a80 100644 --- a/test/HTML5/Parser/InstructionProcessorMock.php +++ b/test/HTML5/Parser/InstructionProcessorMock.php @@ -1,9 +1,9 @@ <?php + namespace Masterminds\HTML5\Tests\Parser; class InstructionProcessorMock implements \Masterminds\HTML5\InstructionProcessor { - public $name = null; public $data = null; @@ -14,9 +14,9 @@ class InstructionProcessorMock implements \Masterminds\HTML5\InstructionProcesso { $this->name = $name; $this->data = $data; - $this->count ++; + ++$this->count; - $div = $element->ownerDocument->createElement("div"); + $div = $element->ownerDocument->createElement('div'); $div->nodeValue = 'foo'; $element->appendChild($div); diff --git a/test/HTML5/Parser/ScannerTest.php b/test/HTML5/Parser/ScannerTest.php index 763eebc..9f75c4d 100644 --- a/test/HTML5/Parser/ScannerTest.php +++ b/test/HTML5/Parser/ScannerTest.php @@ -3,6 +3,7 @@ * @file * Test the Scanner. This requires the InputStream tests are all good. */ + namespace Masterminds\HTML5\Tests\Parser; use Masterminds\HTML5\Parser\StringInputStream; @@ -15,7 +16,7 @@ class ScannerTest extends \Masterminds\HTML5\Tests\TestCase */ public function testConstructDeprecated() { - $is = new StringInputStream("abc"); + $is = new StringInputStream('abc'); $s = new Scanner($is); $this->assertInstanceOf('\Masterminds\HTML5\Parser\Scanner', $s); @@ -28,7 +29,7 @@ class ScannerTest extends \Masterminds\HTML5\Tests\TestCase public function testNextDeprecated() { - $s = new Scanner(new StringInputStream("abc")); + $s = new Scanner(new StringInputStream('abc')); $this->assertEquals('b', $s->next()); $this->assertEquals('c', $s->next()); @@ -87,7 +88,7 @@ class ScannerTest extends \Masterminds\HTML5\Tests\TestCase // Move forward a bunch of positions. $amount = 7; - for ($i = 0; $i < $amount; $i ++) { + for ($i = 0; $i < $amount; ++$i) { $s->next(); } @@ -99,7 +100,7 @@ class ScannerTest extends \Masterminds\HTML5\Tests\TestCase public function testGetHex() { - $s = new Scanner("ab13ck45DE*"); + $s = new Scanner('ab13ck45DE*'); $this->assertEquals('ab13c', $s->getHex()); diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php index 30335e1..153dd23 100644 --- a/test/HTML5/Parser/TokenizerTest.php +++ b/test/HTML5/Parser/TokenizerTest.php @@ -1,4 +1,5 @@ <?php + namespace Masterminds\HTML5\Tests\Parser; use Masterminds\HTML5\Parser\UTF8Utils; @@ -10,19 +11,20 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase // ================================================================ // Additional assertions. // ================================================================ + /** * Tests that an event matches both the event type and the expected value. * * @param string $type - * Expected event type. + * Expected event type * @param string $expects - * The value expected in $event['data'][0]. + * The value expected in $event['data'][0] */ public function assertEventEquals($type, $expects, $event) { $this->assertEquals($type, $event['name'], "Event $type for " . print_r($event, true)); if (is_array($expects)) { - $this->assertEquals($expects, $event['data'], "Event $type should equal " . print_r($expects, true) . ": " . print_r($event, true)); + $this->assertEquals($expects, $event['data'], "Event $type should equal " . print_r($expects, true) . ': ' . print_r($event, true)); } else { $this->assertEquals($expects, $event['data'][0], "Event $type should equal $expects: " . print_r($event, true)); } @@ -33,7 +35,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase */ public function assertEventError($event) { - $this->assertEquals('error', $event['name'], "Expected error for event: " . print_r($event, true)); + $this->assertEquals('error', $event['name'], 'Expected error for event: ' . print_r($event, true)); } /** @@ -65,7 +67,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase // ================================================================ public function testParse() { - list ($tok, $events) = $this->createTokenizer(''); + list($tok, $events) = $this->createTokenizer(''); $tok->parse(); $e1 = $events->get(0); @@ -77,7 +79,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase public function testWhitespace() { $spaces = ' '; - list ($tok, $events) = $this->createTokenizer($spaces); + list($tok, $events) = $this->createTokenizer($spaces); $tok->parse(); @@ -95,7 +97,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '&' => '&', '<' => '<', '&' => '&', - '&' => '&' + '&' => '&', ); $this->isAllGood('text', 2, $good); @@ -133,7 +135,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<![CDATA[', '<![CDATA[hellooooo hello', '<? Hello World ?>', - '<? Hello World' + '<? Hello World', ); foreach ($bogus as $str) { $events = $this->parse($str); @@ -151,7 +153,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase >' => 'test', '</thisIsTheTagThatDoesntEndItJustGoesOnAndOnMyFriend>' => 'thisisthetagthatdoesntenditjustgoesonandonmyfriend', // See 8.2.4.10, which requires this and does not say error. - '</a<b>' => 'a<b' + '</a<b>' => 'a<b', ); $this->isAllGood('endTag', 2, $succeed); @@ -161,7 +163,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '</a <b>' => 'a', '</a <b <c>' => 'a', '</a is the loneliest letter>' => 'a', - '</a' => 'a' + '</a' => 'a', ); foreach ($fail as $test => $result) { $events = $this->parse($test); @@ -176,7 +178,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $comments = array( '</>' => '</>', '</ >' => '</ >', - '</ a>' => '</ a>' + '</ a>' => '</ a>', ); foreach ($comments as $test => $result) { $events = $this->parse($test); @@ -198,7 +200,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<!-- --$i -->' => ' --$i ', '<!----$i-->' => '--$i', "<!--\nHello World.\na-->" => "\nHello World.\na", - '<!-- <!-- -->' => ' <!-- ' + '<!-- <!-- -->' => ' <!-- ', ); foreach ($good as $test => $expected) { $events = $this->parse($test); @@ -209,7 +211,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<!-->' => '', '<!--Hello' => 'Hello', "<!--\0Hello" => UTF8Utils::FFFD . 'Hello', - '<!--' => '' + '<!--' => '', ); foreach ($fail as $test => $expected) { $events = $this->parse($test); @@ -225,7 +227,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<![CDATA[ This is a test. ]]>' => ' This is a test. ', '<![CDATA[CDATA]]>' => 'CDATA', '<![CDATA[ ]] > ]]>' => ' ]] > ', - '<![CDATA[ ]]>' => ' ' + '<![CDATA[ ]]>' => ' ', ); $this->isAllGood('cdata', 2, $good); } @@ -237,80 +239,80 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase 'html', 0, null, - false + false, ), '<!doctype html>' => array( 'html', 0, null, - false + false, ), '<!DocType html>' => array( 'html', 0, null, - false + false, ), "<!DOCTYPE\nhtml>" => array( 'html', 0, null, - false + false, ), "<!DOCTYPE\fhtml>" => array( 'html', 0, null, - false + false, ), '<!DOCTYPE html PUBLIC "foo bar">' => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - false + false, ), "<!DOCTYPE html PUBLIC 'foo bar'>" => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - false + false, ), '<!DOCTYPE html PUBLIC "foo bar" >' => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - false + false, ), "<!DOCTYPE html \nPUBLIC\n'foo bar'>" => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - false + false, ), '<!DOCTYPE html SYSTEM "foo bar">' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - false + false, ), "<!DOCTYPE html SYSTEM 'foo bar'>" => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - false + false, ), '<!DOCTYPE html SYSTEM "foo/bar" >' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo/bar', - false + false, ), "<!DOCTYPE html \nSYSTEM\n'foo bar'>" => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - false - ) + false, + ), ); $this->isAllGood('doctype', 2, $good); @@ -319,43 +321,43 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase null, EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE >' => array( null, EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo PUB' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo PUB>' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo PUB "Looks good">' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo SYSTME "Looks good"' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), // Can't tell whether these are ids or ID types, since the context is chopped. @@ -363,39 +365,39 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo PUBLIC>' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo SYSTEM' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE foo SYSTEM>' => array( 'foo', EventStack::DOCTYPE_NONE, null, - true + true, ), '<!DOCTYPE html SYSTEM "foo bar"' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - true + true, ), '<!DOCTYPE html SYSTEM "foo bar" more stuff>' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - true - ) + true, + ), ); foreach ($bad as $test => $expects) { $events = $this->parse($test); @@ -412,12 +414,12 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<?hph ?>' => 'hph', '<?hph echo "Hello World"; ?>' => array( 'hph', - 'echo "Hello World"; ' + 'echo "Hello World"; ', ), "<?hph \necho 'Hello World';\n?>" => array( 'hph', - "echo 'Hello World';\n" - ) + "echo 'Hello World';\n", + ), ); $this->isAllGood('pi', 2, $good); } @@ -433,7 +435,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<fOO>' => 'foo', '<foo >' => 'foo', "<foo\n\n\n\n>" => 'foo', - '<foo:bar>' => 'foo:bar' + '<foo:bar>' => 'foo:bar', ); $this->isAllGood('startTag', 2, $open); @@ -442,7 +444,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<FOO/>' => 'foo', '<foo />' => 'foo', "<foo\n\n\n\n/>" => 'foo', - '<foo:bar/>' => 'foo:bar' + '<foo:bar/>' => 'foo:bar', ); foreach ($selfClose as $test => $expects) { $events = $this->parse($test); @@ -456,7 +458,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<foo' => 'foo', '<foo ' => 'foo', '<foo/' => 'foo', - '<foo /' => 'foo' + '<foo /' => 'foo', ); foreach ($bad as $test => $expects) { @@ -474,7 +476,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<color="white">' => 'color', "<class='neaktivni_stranka'>" => 'class', '<bgcolor="white">' => 'bgcolor', - '<class="nom">' => 'class' + '<class="nom">' => 'class', ); foreach ($cases as $html => $expected) { @@ -490,18 +492,18 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase public function testTagNotClosedAfterTagName() { $cases = array( - "<noscript<img>" => array( + '<noscript<img>' => array( 'noscript', - 'img' + 'img', ), '<center<a>' => array( 'center', - 'a' + 'a', ), '<br<br>' => array( 'br', - 'br' - ) + 'br', + ), ); foreach ($cases as $html => $expected) { @@ -575,111 +577,111 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<foo bar="baz">' => array( 'foo', array( - 'bar' => 'baz' + 'bar' => 'baz', ), - false + false, ), '<foo bar=" baz ">' => array( 'foo', array( - 'bar' => ' baz ' + 'bar' => ' baz ', ), - false + false, ), "<foo bar=\"\nbaz\n\">" => array( 'foo', array( - 'bar' => "\nbaz\n" + 'bar' => "\nbaz\n", ), - false + false, ), "<foo bar='baz'>" => array( 'foo', array( - 'bar' => 'baz' + 'bar' => 'baz', ), - false + false, ), '<foo bar="A full sentence.">' => array( 'foo', array( - 'bar' => 'A full sentence.' + 'bar' => 'A full sentence.', ), - false + false, ), "<foo a='1' b=\"2\">" => array( 'foo', array( 'a' => '1', - 'b' => '2' + 'b' => '2', ), - false + false, ), "<foo ns:bar='baz'>" => array( 'foo', array( - 'ns:bar' => 'baz' + 'ns:bar' => 'baz', ), - false + false, ), "<foo a='blue&red'>" => array( 'foo', array( - 'a' => 'blue&red' + 'a' => 'blue&red', ), - false + false, ), "<foo a='blue&red'>" => array( 'foo', array( - 'a' => 'blue&red' + 'a' => 'blue&red', ), - false + false, ), "<foo a='blue&&&red'>" => array( 'foo', array( - 'a' => 'blue&&&red' + 'a' => 'blue&&&red', ), - false + false, ), "<foo a='blue&&red'>" => array( 'foo', array( - 'a' => 'blue&&red' + 'a' => 'blue&&red', ), - false + false, ), "<foo\nbar='baz'\n>" => array( 'foo', array( - 'bar' => 'baz' + 'bar' => 'baz', ), - false + false, ), '<doe a deer>' => array( 'doe', array( 'a' => null, - 'deer' => null + 'deer' => null, ), - false + false, ), '<foo bar=baz>' => array( 'foo', array( - 'bar' => 'baz' + 'bar' => 'baz', ), - false + false, ), // Updated for 8.1.2.3 '<foo bar = "baz" >' => array( 'foo', array( - 'bar' => 'baz' + 'bar' => 'baz', ), - false + false, ), // The spec allows an unquoted value '/'. This will not be a closing @@ -687,17 +689,17 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<foo bar=/>' => array( 'foo', array( - 'bar' => '/' + 'bar' => '/', ), - false + false, ), '<foo bar=baz/>' => array( 'foo', array( - 'bar' => 'baz/' + 'bar' => 'baz/', ), - false - ) + false, + ), ); $this->isAllGood('startTag', 2, $good); @@ -706,23 +708,23 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<foo bar="baz"/>' => array( 'foo', array( - 'bar' => 'baz' + 'bar' => 'baz', ), - true + true, ), '<foo BAR="baz"/>' => array( 'foo', array( - 'bar' => 'baz' + 'bar' => 'baz', ), - true + true, ), '<foo BAR="BAZ"/>' => array( 'foo', array( - 'bar' => 'BAZ' + 'bar' => 'BAZ', ), - true + true, ), "<foo a='1' b=\"2\" c=3 d/>" => array( 'foo', @@ -730,10 +732,10 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase 'a' => '1', 'b' => '2', 'c' => '3', - 'd' => null + 'd' => null, ), - true - ) + true, + ), ); $this->isAllGood('startTag', 2, $withEnd); @@ -743,30 +745,30 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase "<foo a='blue&+dark'>" => array( 'foo', array( - 'a' => 'blue&+dark' + 'a' => 'blue&+dark', ), - false + false, ), '<foo bar=>' => array( 'foo', array( - 'bar' => null + 'bar' => null, ), - false + false, ), '<foo bar="oh' => array( 'foo', array( - 'bar' => 'oh' + 'bar' => 'oh', ), - false + false, ), '<foo bar=oh">' => array( 'foo', array( - 'bar' => 'oh"' + 'bar' => 'oh"', ), - false + false, ), // these attributes are ignored because of current implementation @@ -775,23 +777,23 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<foo b"="baz">' => array( 'foo', array(), - false + false, ), '<foo 2abc="baz">' => array( 'foo', array(), - false + false, ), '<foo ?="baz">' => array( 'foo', array(), - false + false, ), '<foo foo?bar="baz">' => array( 'foo', array(), - false - ) + false, + ), ) ; foreach ($bad as $test => $expects) { @@ -807,23 +809,23 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase 'foo', array( '=' => null, - '"bar"' => null + '"bar"' => null, ), - false + false, ), '<foo////>' => array( 'foo', array(), - true + true, ), // character "&" in unquoted attribute shouldn't cause an infinite loop '<foo bar=index.php?str=1&id=29>' => array( 'foo', array( - 'bar' => 'index.php?str=1&id=29' + 'bar' => 'index.php?str=1&id=29', ), - false - ) + false, + ), ); foreach ($reallyBad as $test => $expects) { $events = $this->parse($test); @@ -840,17 +842,17 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEventEquals('startTag', array( 'foo', array( - 'baz' => '1' + 'baz' => '1', ), - false + false, ), $events->get(1)); $this->assertEventEquals('startTag', array( 'bar', array(), - false + false, ), $events->get(2)); $this->assertEventEquals('endTag', array( - 'foo' + 'foo', ), $events->get(3)); } @@ -864,7 +866,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase "<script>\nhello</script\n</script>" => "\nhello</script\n", '<script>&</script>' => '&', '<script><!--not a comment--></script>' => '<!--not a comment-->', - '<script><![CDATA[not a comment]]></script>' => '<![CDATA[not a comment]]>' + '<script><![CDATA[not a comment]]></script>' => '<![CDATA[not a comment]]>', ); foreach ($good as $test => $expects) { $events = $this->parse($test); @@ -875,7 +877,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $bad = array( '<script>&</script' => '&</script', - '<script>Hello world' => 'Hello world' + '<script>Hello world' => 'Hello world', ); foreach ($bad as $test => $expects) { $events = $this->parse($test); @@ -900,7 +902,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase public function testRcdata() { - list ($tok, $events) = $this->createTokenizer('<title>'<!-- not a comment --></TITLE>'); + list($tok, $events) = $this->createTokenizer('<title>'<!-- not a comment --></TITLE>'); $tok->setTextMode(\Masterminds\HTML5\Elements::TEXT_RCDATA, 'title'); $tok->parse(); $this->assertEventEquals('text', "'<!-- not a comment -->", $events->get(1)); @@ -909,19 +911,19 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase public function testText() { $events = $this->parse('a<br>b'); - $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, true)); + $this->assertEquals(4, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('text', 'a', $events->get(0)); $this->assertEventEquals('startTag', 'br', $events->get(1)); $this->assertEventEquals('text', 'b', $events->get(2)); $events = $this->parse('<a>Test</a>'); - $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, true)); + $this->assertEquals(4, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('startTag', 'a', $events->get(0)); $this->assertEventEquals('text', 'Test', $events->get(1)); $this->assertEventEquals('endTag', 'a', $events->get(2)); $events = $this->parse('<p>0</p><p>1</p>'); - $this->assertEquals(7, $events->depth(), "Events: " . print_r($events, true)); + $this->assertEquals(7, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('startTag', 'p', $events->get(0)); $this->assertEventEquals('text', '0', $events->get(1)); @@ -931,25 +933,24 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEventEquals('text', '1', $events->get(4)); $this->assertEventEquals('endTag', 'p', $events->get(5)); - $events = $this->parse('a<![CDATA[test]]>b'); - $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, true)); + $this->assertEquals(4, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('text', 'a', $events->get(0)); $this->assertEventEquals('cdata', 'test', $events->get(1)); $this->assertEventEquals('text', 'b', $events->get(2)); $events = $this->parse('a<!--test-->b'); - $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, true)); + $this->assertEquals(4, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('text', 'a', $events->get(0)); $this->assertEventEquals('comment', 'test', $events->get(1)); $this->assertEventEquals('text', 'b', $events->get(2)); $events = $this->parse('a&b'); - $this->assertEquals(2, $events->depth(), "Events: " . print_r($events, true)); + $this->assertEquals(2, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('text', 'a&b', $events->get(0)); $events = $this->parse('a²b'); - $this->assertEquals(2, $events->depth(), "Events: " . print_r($events, true)); + $this->assertEquals(2, $events->depth(), 'Events: ' . print_r($events, true)); $this->assertEventEquals('text', 'a²b', $events->get(0)); } @@ -965,13 +966,13 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase return array( new Tokenizer($scanner, $eventHandler), - $eventHandler + $eventHandler, ); } public function parse($string, $debug = false) { - list ($tok, $events) = $this->createTokenizer($string, $debug); + list($tok, $events) = $this->createTokenizer($string, $debug); $tok->parse(); return $events; diff --git a/test/HTML5/Parser/TreeBuildingRulesTest.php b/test/HTML5/Parser/TreeBuildingRulesTest.php index 1d08cbc..45c68bc 100644 --- a/test/HTML5/Parser/TreeBuildingRulesTest.php +++ b/test/HTML5/Parser/TreeBuildingRulesTest.php @@ -3,6 +3,7 @@ * @file * Test the Tree Builder's special-case rules. */ + namespace Masterminds\HTML5\Tests\Parser; use Masterminds\HTML5\Parser\TreeBuildingRules; @@ -15,7 +16,6 @@ use Masterminds\HTML5\Parser\DOMTreeBuilder; */ class TreeBuildingRulesTest extends \Masterminds\HTML5\Tests\TestCase { - const HTML_STUB = '<!DOCTYPE html><html><head><title>test</title></head><body>%s</body></html>'; /** @@ -28,8 +28,10 @@ class TreeBuildingRulesTest extends \Masterminds\HTML5\Tests\TestCase $parser = new Tokenizer($scanner, $treeBuilder); $parser->parse(); + return $treeBuilder->document(); } + /** * Convenience function for parsing fragments. */ @@ -40,13 +42,13 @@ class TreeBuildingRulesTest extends \Masterminds\HTML5\Tests\TestCase $parser = new Tokenizer($scanner, $events); $parser->parse(); + return $events->fragment(); } public function testTDFragment() { - - $frag = $this->parseFragment("<td>This is a test of the HTML5 parser</td>"); + $frag = $this->parseFragment('<td>This is a test of the HTML5 parser</td>'); $td = $frag->childNodes->item(0); diff --git a/test/HTML5/Parser/UTF8UtilsTest.php b/test/HTML5/Parser/UTF8UtilsTest.php index 0e8555a..72c26a4 100644 --- a/test/HTML5/Parser/UTF8UtilsTest.php +++ b/test/HTML5/Parser/UTF8UtilsTest.php @@ -6,21 +6,23 @@ use Masterminds\HTML5\Parser\UTF8Utils; class UTF8UtilsTest extends \Masterminds\HTML5\Tests\TestCase { - public function testConvertToUTF8() { - $out = UTF8Utils::convertToUTF8('éàa', 'ISO-8859-1'); - $this->assertEquals('éà a', $out); - } + public function testConvertToUTF8() + { + $out = UTF8Utils::convertToUTF8('éàa', 'ISO-8859-1'); + $this->assertEquals('éà a', $out); + } - /** - * @todo add tests for invalid codepoints - */ - public function testCheckForIllegalCodepoints() { - $smoke = "Smoke test"; - $err = UTF8Utils::checkForIllegalCodepoints($smoke); - $this->assertEmpty($err); + /** + * @todo add tests for invalid codepoints + */ + public function testCheckForIllegalCodepoints() + { + $smoke = 'Smoke test'; + $err = UTF8Utils::checkForIllegalCodepoints($smoke); + $this->assertEmpty($err); - $data = "Foo Bar \0 Baz"; - $errors = UTF8Utils::checkForIllegalCodepoints($data); - $this->assertContains('null-character', $errors); - } -}
\ No newline at end of file + $data = "Foo Bar \0 Baz"; + $errors = UTF8Utils::checkForIllegalCodepoints($data); + $this->assertContains('null-character', $errors); + } +} |