diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/HTML5/ElementsTest.php | 484 | ||||
-rw-r--r-- | test/HTML5/Html5Test.php | 39 | ||||
-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 | ||||
-rw-r--r-- | test/HTML5/Serializer/OutputRulesTest.php | 118 | ||||
-rw-r--r-- | test/HTML5/Serializer/TraverserTest.php | 15 | ||||
-rw-r--r-- | test/HTML5/TestCase.php | 2 | ||||
-rw-r--r-- | test/benchmark/run.php | 10 |
15 files changed, 562 insertions, 551 deletions
diff --git a/test/HTML5/ElementsTest.php b/test/HTML5/ElementsTest.php index e0a8905..08b5ee4 100644 --- a/test/HTML5/ElementsTest.php +++ b/test/HTML5/ElementsTest.php @@ -1,247 +1,247 @@ <?php + namespace Masterminds\HTML5\Tests; use Masterminds\HTML5\Elements; class ElementsTest extends TestCase { - public $html5Elements = array( - "a", - "abbr", - "address", - "area", - "article", - "aside", - "audio", - "b", - "base", - "bdi", - "bdo", - "blockquote", - "body", - "br", - "button", - "canvas", - "caption", - "cite", - "code", - "col", - "colgroup", - "command", + 'a', + 'abbr', + 'address', + 'area', + 'article', + 'aside', + 'audio', + 'b', + 'base', + 'bdi', + 'bdo', + 'blockquote', + 'body', + 'br', + 'button', + 'canvas', + 'caption', + 'cite', + 'code', + 'col', + 'colgroup', + 'command', // "data", - "datalist", - "dd", - "del", - "details", - "dfn", - "dialog", - "div", - "dl", - "dt", - "em", - "embed", - "fieldset", - "figcaption", - "figure", - "footer", - "form", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "head", - "header", - "hgroup", - "hr", - "html", - "i", - "iframe", - "img", - "input", - "ins", - "kbd", - "keygen", - "label", - "legend", - "li", - "link", - "map", - "mark", - "menu", - "meta", - "meter", - "nav", - "noscript", - "object", - "ol", - "optgroup", - "option", - "output", - "p", - "param", - "pre", - "progress", - "q", - "rp", - "rt", - "ruby", - "s", - "samp", - "script", - "section", - "select", - "small", - "source", - "span", - "strong", - "style", - "sub", - "summary", - "sup", - "table", - "tbody", - "td", - "textarea", - "tfoot", - "th", - "thead", - "time", - "title", - "tr", - "track", - "u", - "ul", - "var", - "video", - "wbr" + 'datalist', + 'dd', + 'del', + 'details', + 'dfn', + 'dialog', + 'div', + 'dl', + 'dt', + 'em', + 'embed', + 'fieldset', + 'figcaption', + 'figure', + 'footer', + 'form', + 'h1', + 'h2', + 'h3', + 'h4', + 'h5', + 'h6', + 'head', + 'header', + 'hgroup', + 'hr', + 'html', + 'i', + 'iframe', + 'img', + 'input', + 'ins', + 'kbd', + 'keygen', + 'label', + 'legend', + 'li', + 'link', + 'map', + 'mark', + 'menu', + 'meta', + 'meter', + 'nav', + 'noscript', + 'object', + 'ol', + 'optgroup', + 'option', + 'output', + 'p', + 'param', + 'pre', + 'progress', + 'q', + 'rp', + 'rt', + 'ruby', + 's', + 'samp', + 'script', + 'section', + 'select', + 'small', + 'source', + 'span', + 'strong', + 'style', + 'sub', + 'summary', + 'sup', + 'table', + 'tbody', + 'td', + 'textarea', + 'tfoot', + 'th', + 'thead', + 'time', + 'title', + 'tr', + 'track', + 'u', + 'ul', + 'var', + 'video', + 'wbr', ); public $mathmlElements = array( - "maction", - "maligngroup", - "malignmark", - "math", - "menclose", - "merror", - "mfenced", - "mfrac", - "mglyph", - "mi", - "mlabeledtr", - "mlongdiv", - "mmultiscripts", - "mn", - "mo", - "mover", - "mpadded", - "mphantom", - "mroot", - "mrow", - "ms", - "mscarries", - "mscarry", - "msgroup", - "msline", - "mspace", - "msqrt", - "msrow", - "mstack", - "mstyle", - "msub", - "msup", - "msubsup", - "mtable", - "mtd", - "mtext", - "mtr", - "munder", - "munderover" + 'maction', + 'maligngroup', + 'malignmark', + 'math', + 'menclose', + 'merror', + 'mfenced', + 'mfrac', + 'mglyph', + 'mi', + 'mlabeledtr', + 'mlongdiv', + 'mmultiscripts', + 'mn', + 'mo', + 'mover', + 'mpadded', + 'mphantom', + 'mroot', + 'mrow', + 'ms', + 'mscarries', + 'mscarry', + 'msgroup', + 'msline', + 'mspace', + 'msqrt', + 'msrow', + 'mstack', + 'mstyle', + 'msub', + 'msup', + 'msubsup', + 'mtable', + 'mtd', + 'mtext', + 'mtr', + 'munder', + 'munderover', ); public $svgElements = array( - "a", - "altGlyph", - "altGlyphDef", - "altGlyphItem", - "animate", - "animateColor", - "animateMotion", - "animateTransform", - "circle", - "clipPath", - "color-profile", - "cursor", - "defs", - "desc", - "ellipse", - "feBlend", - "feColorMatrix", - "feComponentTransfer", - "feComposite", - "feConvolveMatrix", - "feDiffuseLighting", - "feDisplacementMap", - "feDistantLight", - "feFlood", - "feFuncA", - "feFuncB", - "feFuncG", - "feFuncR", - "feGaussianBlur", - "feImage", - "feMerge", - "feMergeNode", - "feMorphology", - "feOffset", - "fePointLight", - "feSpecularLighting", - "feSpotLight", - "feTile", - "feTurbulence", - "filter", - "font", - "font-face", - "font-face-format", - "font-face-name", - "font-face-src", - "font-face-uri", - "foreignObject", - "g", - "glyph", - "glyphRef", - "hkern", - "image", - "line", - "linearGradient", - "marker", - "mask", - "metadata", - "missing-glyph", - "mpath", - "path", - "pattern", - "polygon", - "polyline", - "radialGradient", - "rect", - "script", - "set", - "stop", - "style", - "svg", - "switch", - "symbol", - "text", - "textPath", - "title", - "tref", - "tspan", - "use", - "view", - "vkern" + 'a', + 'altGlyph', + 'altGlyphDef', + 'altGlyphItem', + 'animate', + 'animateColor', + 'animateMotion', + 'animateTransform', + 'circle', + 'clipPath', + 'color-profile', + 'cursor', + 'defs', + 'desc', + 'ellipse', + 'feBlend', + 'feColorMatrix', + 'feComponentTransfer', + 'feComposite', + 'feConvolveMatrix', + 'feDiffuseLighting', + 'feDisplacementMap', + 'feDistantLight', + 'feFlood', + 'feFuncA', + 'feFuncB', + 'feFuncG', + 'feFuncR', + 'feGaussianBlur', + 'feImage', + 'feMerge', + 'feMergeNode', + 'feMorphology', + 'feOffset', + 'fePointLight', + 'feSpecularLighting', + 'feSpotLight', + 'feTile', + 'feTurbulence', + 'filter', + 'font', + 'font-face', + 'font-face-format', + 'font-face-name', + 'font-face-src', + 'font-face-uri', + 'foreignObject', + 'g', + 'glyph', + 'glyphRef', + 'hkern', + 'image', + 'line', + 'linearGradient', + 'marker', + 'mask', + 'metadata', + 'missing-glyph', + 'mpath', + 'path', + 'pattern', + 'polygon', + 'polyline', + 'radialGradient', + 'rect', + 'script', + 'set', + 'stop', + 'style', + 'svg', + 'switch', + 'symbol', + 'text', + 'textPath', + 'title', + 'tref', + 'tspan', + 'use', + 'view', + 'vkern', ); public function testIsHtml5Element() @@ -255,7 +255,7 @@ class ElementsTest extends TestCase $nonhtml5 = array( 'foo', 'bar', - 'baz' + 'baz', ); foreach ($nonhtml5 as $element) { $this->assertFalse(Elements::isHtml5Element($element), 'html5 element test failed on: ' . $element); @@ -276,7 +276,7 @@ class ElementsTest extends TestCase $nonMathML = array( 'foo', 'bar', - 'baz' + 'baz', ); foreach ($nonMathML as $element) { $this->assertFalse(Elements::isMathMLElement($element), 'MathML element test failed on: ' . $element); @@ -295,7 +295,7 @@ class ElementsTest extends TestCase $nonSVG = array( 'foo', 'bar', - 'baz' + 'baz', ); foreach ($nonSVG as $element) { $this->assertFalse(Elements::isSvgElement($element), 'SVG element test failed on: ' . $element); @@ -323,7 +323,7 @@ class ElementsTest extends TestCase // SVG is case sensitive so these should all fail. But, there is duplication // html5 and SVG. Since html5 is case insensitive we need to make sure // it's not a html5 element first. - if (! in_array($element, $this->html5Elements)) { + if (!in_array($element, $this->html5Elements)) { $this->assertFalse(Elements::isElement(strtoupper($element)), 'SVG element test failed on: ' . strtoupper($element)); } } @@ -331,7 +331,7 @@ class ElementsTest extends TestCase $nonhtml5 = array( 'foo', 'bar', - 'baz' + 'baz', ); foreach ($nonhtml5 as $element) { $this->assertFalse(Elements::isElement($element), 'html5 element test failed on: ' . $element); @@ -348,7 +348,7 @@ class ElementsTest extends TestCase $nonhtml5 = array( 'foo', 'bar', - 'baz' + 'baz', ); foreach ($nonhtml5 as $element) { $this->assertEquals(0, Elements::element($element)); @@ -373,7 +373,7 @@ class ElementsTest extends TestCase 'embed', 'frame', 'hr', - 'img' + 'img', ); foreach ($voidElements as $element) { @@ -383,7 +383,7 @@ class ElementsTest extends TestCase $nonVoid = array( 'span', 'a', - 'div' + 'div', ); foreach ($nonVoid as $tag) { $this->assertFalse(Elements::isA($tag, Elements::VOID_TAG), 'Void element test failed on: ' . $tag); @@ -421,7 +421,7 @@ class ElementsTest extends TestCase 'table', 'tfoot', 'ul', - 'video' + 'video', ); foreach ($blockTags as $tag) { @@ -431,7 +431,7 @@ class ElementsTest extends TestCase $nonBlockTags = array( 'span', 'img', - 'label' + 'label', ); foreach ($nonBlockTags as $tag) { $this->assertFalse(Elements::isA($tag, Elements::BLOCK_TAG), 'Block tag test failed on: ' . $tag); @@ -446,7 +446,7 @@ class ElementsTest extends TestCase 'BAR' => 'bar', 'fespecularlighting' => 'feSpecularLighting', 'bAz' => 'baz', - 'foreignobject' => 'foreignObject' + 'foreignobject' => 'foreignObject', ); foreach ($tests as $input => $expected) { @@ -462,7 +462,7 @@ class ElementsTest extends TestCase 'BAR' => 'bar', 'limitingconeangle' => 'limitingConeAngle', 'bAz' => 'baz', - 'patterncontentunits' => 'patternContentUnits' + 'patterncontentunits' => 'patternContentUnits', ); foreach ($tests as $input => $expected) { @@ -475,7 +475,7 @@ class ElementsTest extends TestCase $tests = array( 'foo' => 'foo', 'definitionurl' => 'definitionURL', - 'BAR' => 'bar' + 'BAR' => 'bar', ); foreach ($tests as $input => $expected) { diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php index 7873cd9..47bcafd 100644 --- a/test/HTML5/Html5Test.php +++ b/test/HTML5/Html5Test.php @@ -1,9 +1,9 @@ <?php + namespace Masterminds\HTML5\Tests; class Html5Test extends TestCase { - public function setUp() { $this->html5 = $this->getInstance(); @@ -28,20 +28,19 @@ class Html5Test extends TestCase return $out; } - public function testImageTagsInSvg() { - $html = "<!DOCTYPE html> + $html = '<!DOCTYPE html> <html> <head> <title>foo</title> </head> <body> <svg> - <image height=\"10\" width=\"10\"></image> + <image height="10" width="10"></image> </svg> </body> - </html>"; + </html>'; $doc = $this->html5->loadHTML($html); $this->assertInstanceOf('DOMElement', $doc->getElementsByTagName('image')->item(0)); $this->assertEmpty($this->html5->getErrors()); @@ -52,29 +51,29 @@ class Html5Test extends TestCase // doc $dom = $this->html5->loadHTML($this->wrap('<t:tag/>'), array( 'implicitNamespaces' => array('t' => 'http://example.com'), - "xmlNamespaces" => true + 'xmlNamespaces' => true, )); $this->assertInstanceOf('\DOMDocument', $dom); $this->assertEmpty($this->html5->getErrors()); $this->assertFalse($this->html5->hasErrors()); - $xpath = new \DOMXPath( $dom ); - $xpath->registerNamespace( "t", "http://example.com" ); - $this->assertEquals(1, $xpath->query( "//t:tag" )->length); + $xpath = new \DOMXPath($dom); + $xpath->registerNamespace('t', 'http://example.com'); + $this->assertEquals(1, $xpath->query('//t:tag')->length); // doc fragment $frag = $this->html5->loadHTMLFragment('<t:tag/>', array( 'implicitNamespaces' => array('t' => 'http://example.com'), - "xmlNamespaces" => true + 'xmlNamespaces' => true, )); $this->assertInstanceOf('\DOMDocumentFragment', $frag); $this->assertEmpty($this->html5->getErrors()); $this->assertFalse($this->html5->hasErrors()); $frag->ownerDocument->appendChild($frag); - $xpath = new \DOMXPath( $frag->ownerDocument ); - $xpath->registerNamespace( "t", "http://example.com" ); - $this->assertEquals(1, $xpath->query( "//t:tag" , $frag)->length); + $xpath = new \DOMXPath($frag->ownerDocument); + $xpath->registerNamespace('t', 'http://example.com'); + $this->assertEquals(1, $xpath->query('//t:tag', $frag)->length); } public function testErrors() @@ -162,11 +161,11 @@ class Html5Test extends TestCase // Test resource $file = fopen('php://temp', 'w'); $this->html5->save($dom, $file); - $content = stream_get_contents($file, - 1, 0); + $content = stream_get_contents($file, -1, 0); $this->assertRegExp('|<p>This is a test.</p>|', $content); // Test file - $tmpfname = tempnam(sys_get_temp_dir(), "html5-php"); + $tmpfname = tempnam(sys_get_temp_dir(), 'html5-php'); $this->html5->save($dom, $tmpfname); $content = file_get_contents($tmpfname); $this->assertRegExp('|<p>This is a test.</p>|', $content); @@ -197,7 +196,7 @@ class Html5Test extends TestCase $html5 = $this->getInstance(array( 'foo' => 'bar', - 'encode_entities' => true + 'encode_entities' => true, )); $options = $html5->getOptions(); $this->assertEquals('bar', $options['foo']); @@ -233,7 +232,7 @@ class Html5Test extends TestCase $list = $dom->getElementsByTagName('svg'); $this->assertNotEmpty($list->length); $svg = $list->item(0); - $this->assertEquals("0 0 3 2", $svg->getAttribute('viewBox')); + $this->assertEquals('0 0 3 2', $svg->getAttribute('viewBox')); $this->assertFalse($svg->hasAttribute('viewbox')); // Test a mixed case tag. @@ -292,12 +291,12 @@ class Html5Test extends TestCase // they are handled as normal elements. Note, to do this is really // an invalid example and you should not embed prefixed xml in html5. $dom = $this->html5->loadHTMLFragment( - "<f:rug> + '<f:rug> <f:name>Big rectangle thing</f:name> <f:width>40</f:width> <f:length>80</f:length> </f:rug> - <sarcasm>um, yeah</sarcasm>"); + <sarcasm>um, yeah</sarcasm>'); $this->assertEmpty($this->html5->getErrors()); $markup = $this->html5->saveHTML($dom); @@ -423,7 +422,7 @@ class Html5Test extends TestCase $dom = $this->html5->loadHTML( '<html><body><Button color="red">Error</Button></body></html>', array( - "xmlNamespaces" => true + 'xmlNamespaces' => true, ) ); $out = $this->html5->saveHTML($dom); 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); + } +} diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index 72253d3..9130516 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -1,4 +1,5 @@ <?php + namespace Masterminds\HTML5\Tests\Serializer; use Masterminds\HTML5\Serializer\OutputRules; @@ -7,7 +8,6 @@ use Masterminds\HTML5; class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { - protected $markup = '<!doctype html> <html lang="en"> <head> @@ -33,7 +33,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase * Using reflection we make a protected method accessible for testing. * * @param string $name - * The name of the method on the Traverser class to test. + * The name of the method on the Traverser class to test * * @return \ReflectionMethod for the specified method */ @@ -65,7 +65,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase return array( $r, - $stream + $stream, ); } @@ -79,20 +79,20 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $r->document($dom); $expected = '<!DOCTYPE html>' . PHP_EOL . '<html lang="en"><body>foo</body></html>' . PHP_EOL; - $this->assertEquals($expected, stream_get_contents($stream, - 1, 0)); + $this->assertEquals($expected, stream_get_contents($stream, -1, 0)); } public function testEmptyDocument() { - $dom = $this->html5->loadHTML(''); + $dom = $this->html5->loadHTML(''); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); - $r->document($dom); - $expected = '<!DOCTYPE html>' . PHP_EOL; - $this->assertEquals($expected, stream_get_contents($stream, - 1, 0)); + $r->document($dom); + $expected = '<!DOCTYPE html>' . PHP_EOL; + $this->assertEquals($expected, stream_get_contents($stream, -1, 0)); } public function testDoctype() @@ -105,7 +105,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $m = $this->getProtectedMethod('doctype'); $m->invoke($r, 'foo'); - $this->assertEquals("<!DOCTYPE html>" . PHP_EOL, stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<!DOCTYPE html>' . PHP_EOL, stream_get_contents($stream, -1, 0)); } public function testElement() @@ -129,13 +129,13 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('div'); $r->element($list->item(0)); - $this->assertEquals('<div id="foo" class="bar baz">foo bar baz</div>', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<div id="foo" class="bar baz">foo bar baz</div>', stream_get_contents($stream, -1, 0)); } - function testSerializeWithNamespaces() + public function testSerializeWithNamespaces() { $this->html5 = $this->getInstance(array( - 'xmlNamespaces' => true + 'xmlNamespaces' => true, )); $source = ' @@ -153,7 +153,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase </html>'; $dom = $this->html5->loadHTML($source, array( - 'xmlNamespaces' => true + 'xmlNamespaces' => true, )); $this->assertFalse($this->html5->hasErrors(), print_r($this->html5->getErrors(), 1)); @@ -162,10 +162,10 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $t->walk(); - $rendered = stream_get_contents($stream, - 1, 0); + $rendered = stream_get_contents($stream, -1, 0); - $clear = function($s){ - return trim(preg_replace('/[\s]+/', " ", $s)); + $clear = function ($s) { + return trim(preg_replace('/[\s]+/', ' ', $s)); }; $this->assertEquals($clear($source), $clear($rendered)); @@ -205,7 +205,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $jQ("#mktFrmSubmit").wrap("<div class=\'buttonSubmit\'></div>"); $jQ(".buttonSubmit").prepend("<span></span>"); }); - </script>', stream_get_contents($stream, - 1, 0)); + </script>', stream_get_contents($stream, -1, 0)); } public function testElementWithStyle() @@ -235,7 +235,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase body > .bar { display: none; } - </style>', stream_get_contents($stream, - 1, 0)); + </style>', stream_get_contents($stream, -1, 0)); } public function testOpenTag() @@ -254,7 +254,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('div'); $m = $this->getProtectedMethod('openTag'); $m->invoke($r, $list->item(0)); - $this->assertEquals('<div id="foo" class="bar baz">', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<div id="foo" class="bar baz">', stream_get_contents($stream, -1, 0)); } public function testCData() @@ -272,7 +272,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('div'); $r->cdata($list->item(0)->childNodes->item(0)); - $this->assertEquals('<![CDATA[bar]]>', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<![CDATA[bar]]>', stream_get_contents($stream, -1, 0)); $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> @@ -281,7 +281,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase </body> </html>'); - $dom->getElementById('foo')->appendChild(new \DOMCdataSection("]]>Foo<[![CDATA test ]]>")); + $dom->getElementById('foo')->appendChild(new \DOMCdataSection(']]>Foo<[![CDATA test ]]>')); $stream = fopen('php://temp', 'w'); $r = new OutputRules($stream, $this->html5->getOptions()); @@ -289,7 +289,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('div'); $r->cdata($list->item(0)->childNodes->item(0)); - $this->assertEquals('<![CDATA[]]]]><![CDATA[>Foo<[![CDATA test ]]]]><![CDATA[>]]>', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<![CDATA[]]]]><![CDATA[>Foo<[![CDATA test ]]]]><![CDATA[>]]>', stream_get_contents($stream, -1, 0)); } public function testComment() @@ -307,7 +307,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('div'); $r->comment($list->item(0)->childNodes->item(0)); - $this->assertEquals('<!-- foo -->', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<!-- foo -->', stream_get_contents($stream, -1, 0)); $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> @@ -326,7 +326,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase // Could not find more definitive guidelines on what this should be. Went with // what the HTML5 spec says and what \DOMDocument::saveXML() produces. - $this->assertEquals('<!--<!-- --> --> Foo -->-->', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<!--<!-- --> --> Foo -->-->', stream_get_contents($stream, -1, 0)); } public function testText() @@ -344,7 +344,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('script'); $r->text($list->item(0)->childNodes->item(0)); - $this->assertEquals('baz();', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('baz();', stream_get_contents($stream, -1, 0)); $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> @@ -358,25 +358,25 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $r->text($foo->firstChild); - $this->assertEquals('<script>alert("hi");</script>', stream_get_contents($stream, - 1, 0)); + $this->assertEquals('<script>alert("hi");</script>', stream_get_contents($stream, -1, 0)); } public function testNl() { - list ($o, $s) = $this->getOutputRules(); + list($o, $s) = $this->getOutputRules(); $m = $this->getProtectedMethod('nl'); $m->invoke($o); - $this->assertEquals(PHP_EOL, stream_get_contents($s, - 1, 0)); + $this->assertEquals(PHP_EOL, stream_get_contents($s, -1, 0)); } public function testWr() { - list ($o, $s) = $this->getOutputRules(); + list($o, $s) = $this->getOutputRules(); $m = $this->getProtectedMethod('wr'); $m->invoke($o, 'foo'); - $this->assertEquals('foo', stream_get_contents($s, - 1, 0)); + $this->assertEquals('foo', stream_get_contents($s, -1, 0)); } public function getEncData() @@ -386,61 +386,62 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase false, '&\'<>"', '&\'<>"', - '&'<>"' + '&'<>"', ), array( false, 'This + is. a < test', 'This + is. a < test', - 'This + is. a < test' + 'This + is. a < test', ), array( false, '.+#', '.+#', - '.+#' + '.+#', ), array( true, '.+#\'', '.+#\'', - '.+#'' + '.+#'', ), array( true, '&".<', '&".<', - '&".<' + '&".<', ), array( true, '&\'<>"', '&\'<>"', - '&'<>"' + '&'<>"', ), array( true, "\xc2\xa0\"'", ' "\'', - ' "'' - ) + ' "'', + ), ); } /** * Test basic encoding of text. + * * @dataProvider getEncData */ public function testEnc($isAttribute, $test, $expected, $expectedEncoded) { - list ($o, $s) = $this->getOutputRules(); + list($o, $s) = $this->getOutputRules(); $m = $this->getProtectedMethod('enc'); $this->assertEquals($expected, $m->invoke($o, $test, $isAttribute)); - list ($o, $s) = $this->getOutputRules(array( - 'encode_entities' => true + list($o, $s) = $this->getOutputRules(array( + 'encode_entities' => true, )); $m = $this->getProtectedMethod('enc'); $this->assertEquals($expectedEncoded, $m->invoke($o, $test, $isAttribute)); @@ -448,11 +449,12 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase /** * Test basic encoding of text. + * * @dataProvider getEncData */ public function testEscape($isAttribute, $test, $expected, $expectedEncoded) { - list ($o, $s) = $this->getOutputRules(); + list($o, $s) = $this->getOutputRules(); $m = $this->getProtectedMethod('escape'); $this->assertEquals($expected, $m->invoke($o, $test, $isAttribute)); @@ -473,12 +475,13 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase array('<script defer></script>'), ); } + /** * @dataProvider booleanAttributes */ public function testBooleanAttrs($html) { - $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>'.$html.'</body></html>'); + $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>' . $html . '</body></html>'); $stream = fopen('php://temp', 'w'); $r = new OutputRules($stream, $this->html5->getOptions()); @@ -489,13 +492,12 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $m = $this->getProtectedMethod('attrs'); $m->invoke($r, $node); - $content = stream_get_contents($stream, - 1, 0); + $content = stream_get_contents($stream, -1, 0); $html = preg_replace('~<[a-z]+(.*)></[a-z]+>~', '\1', $html); $html = preg_replace('~<[a-z]+(.*)/?>~', '\1', $html); $this->assertEquals($content, $html); - } public function testAttrs() @@ -516,7 +518,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $m = $this->getProtectedMethod('attrs'); $m->invoke($r, $list->item(0)); - $content = stream_get_contents($stream, - 1, 0); + $content = stream_get_contents($stream, -1, 0); $this->assertEquals(' id="foo" class="bar baz"', $content); } @@ -544,7 +546,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('svg'); $r->element($list->item(0)); - $contents = stream_get_contents($stream, - 1, 0); + $contents = stream_get_contents($stream, -1, 0); $this->assertRegExp('|<svg width="150" height="100" viewBox="0 0 3 2">|', $contents); $this->assertRegExp('|<rect width="1" height="2" x="0" fill="#008d46" />|', $contents); $this->assertRegExp('|<rect id="Bar" x="300" y="100" width="300" height="100" fill="rgb\(255,255,0\)">|', $contents); @@ -573,7 +575,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('math'); $r->element($list->item(0)); - $content = stream_get_contents($stream, - 1, 0); + $content = stream_get_contents($stream, -1, 0); $this->assertRegExp('|<math>|', $content); $this->assertRegExp('|<csymbol definitionURL="http://www.example.com/mathops/multiops.html#plusminus">|', $content); } @@ -587,7 +589,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $r->processorInstruction($dom->firstChild); - $content = stream_get_contents($stream, - 1, 0); + $content = stream_get_contents($stream, -1, 0); $this->assertRegExp('|<\?foo bar \?>|', $content); } @@ -611,7 +613,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $list = $dom->getElementsByTagName('address'); $r->element($list->item(0)); - $contents = stream_get_contents($stream, - 1, 0); + $contents = stream_get_contents($stream, -1, 0); $this->assertRegExp('|<address>|', $contents); $this->assertRegExp('|<a href="../People/Raggett/">Dave Raggett</a>,|', $contents); @@ -621,7 +623,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase } /** - * Ensure direct DOM manipulation doesn't break TEXT_RAW elements (iframe, script, etc...) + * Ensure direct DOM manipulation doesn't break TEXT_RAW elements (iframe, script, etc...). */ public function testHandlingInvalidRawContent() { @@ -635,16 +637,16 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase </body> </html>'); - $badNode = $dom->createElement("p", "Bar"); + $badNode = $dom->createElement('p', 'Bar'); // modify the content of the TEXT_RAW element: <script id="template"> appending dom nodes - $styleElement = $dom->getElementById("template"); + $styleElement = $dom->getElementById('template'); $styleElement->appendChild($badNode); $contents = $this->html5->saveHTML($dom); - $this->assertTrue(strpos($contents, '<script id="template" type="x-tmpl-mustache"> + $this->assertTrue(false !== strpos($contents, '<script id="template" type="x-tmpl-mustache"> <h1>Hello!</h1> - <p>Bar</p></script>')!==false); + <p>Bar</p></script>')); } } diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php index a156553..d4ae7b3 100644 --- a/test/HTML5/Serializer/TraverserTest.php +++ b/test/HTML5/Serializer/TraverserTest.php @@ -1,13 +1,12 @@ <?php + namespace Masterminds\HTML5\Tests\Serializer; use Masterminds\HTML5\Serializer\OutputRules; use Masterminds\HTML5\Serializer\Traverser; -use Masterminds\HTML5\Parser; class TraverserTest extends \Masterminds\HTML5\Tests\TestCase { - protected $markup = '<!doctype html> <html lang="en"> <head> @@ -28,7 +27,7 @@ class TraverserTest extends \Masterminds\HTML5\Tests\TestCase * Using reflection we make a protected method accessible for testing. * * @param string $name - * The name of the method on the Traverser class to test. + * The name of the method on the Traverser class to test * * @return \ReflectionMethod \ReflectionMethod for the specified method */ @@ -51,7 +50,7 @@ class TraverserTest extends \Masterminds\HTML5\Tests\TestCase // We return both the traverser and stream so we can pull from it. return array( $t, - $stream + $stream, ); } @@ -84,7 +83,7 @@ class TraverserTest extends \Masterminds\HTML5\Tests\TestCase $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $t->walk(); - $this->assertEquals($html, stream_get_contents($stream, - 1, 0)); + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); } public function testFragment() @@ -99,7 +98,7 @@ class TraverserTest extends \Masterminds\HTML5\Tests\TestCase $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $t->walk(); - $this->assertEquals($html, stream_get_contents($stream, - 1, 0)); + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); } public function testProcessorInstructionDeprecated() @@ -116,7 +115,7 @@ class TraverserTest extends \Masterminds\HTML5\Tests\TestCase $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $t->walk(); - $this->assertEquals($html, stream_get_contents($stream, - 1, 0)); + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); } public function testProcessorInstruction() @@ -132,6 +131,6 @@ class TraverserTest extends \Masterminds\HTML5\Tests\TestCase $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $t->walk(); - $this->assertEquals($html, stream_get_contents($stream, - 1, 0)); + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); } } diff --git a/test/HTML5/TestCase.php b/test/HTML5/TestCase.php index 2f220b1..990e8c1 100644 --- a/test/HTML5/TestCase.php +++ b/test/HTML5/TestCase.php @@ -1,4 +1,5 @@ <?php + namespace Masterminds\HTML5\Tests; use Masterminds\HTML5; @@ -6,7 +7,6 @@ use PHPUnit\Framework\TestCase as BaseTestCase; class TestCase extends BaseTestCase { - const DOC_OPEN = '<!DOCTYPE html><html><head><title>test</title></head><body>'; const DOC_CLOSE = '</body></html>'; diff --git a/test/benchmark/run.php b/test/benchmark/run.php index bee7c2d..2ca1907 100644 --- a/test/benchmark/run.php +++ b/test/benchmark/run.php @@ -1,6 +1,6 @@ <?php -require __DIR__ . "/../../vendor/autoload.php"; +require __DIR__ . '/../../vendor/autoload.php'; $iterations = isset($argv[1]) ? $argv[1] : 100; @@ -9,21 +9,21 @@ $content = file_get_contents(__DIR__ . '/example.html'); $dom = $html5->loadHTML($content); $samples = array(); -for ($i = 0; $i < $iterations; $i++) { +for ($i = 0; $i < $iterations; ++$i) { $t = microtime(true); $dom = $html5->loadHTML($content); $samples[] = microtime(true) - $t; } $time = array_sum($samples) / count($samples); -echo "Loading: " . ($time * 1000) . "\n"; +echo 'Loading: ' . ($time * 1000) . "\n"; $samples = array(); -for ($i = 0; $i < $iterations; $i++) { +for ($i = 0; $i < $iterations; ++$i) { $t = microtime(true); $html5->saveHTML($dom); $samples[] = microtime(true) - $t; } $time = array_sum($samples) / count($samples); -echo "Writing: " . ($time * 1000) . "\n"; +echo 'Writing: ' . ($time * 1000) . "\n"; exit(0); |