diff options
author | Matt Farina <[email protected]> | 2013-11-06 07:35:21 -0500 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-11-06 07:35:21 -0500 |
commit | 51afaed4bad68a56c1719b89156f1fd80bdc7e44 (patch) | |
tree | 9a87914b049161a702a81cb714af0e8632fbebd9 | |
parent | 5734589d119502ddb81211fb6c3b55e28bc5eed3 (diff) |
Improved test coverage. This caused a bug in processor instructions to appear. Fix them so they actually work now.
-rw-r--r-- | RELEASE.md | 2 | ||||
-rw-r--r-- | src/HTML5/Parser/DOMTreeBuilder.php | 2 | ||||
-rw-r--r-- | test/HTML5/Parser/DOMTreeBuilderTest.php | 39 |
3 files changed, 42 insertions, 1 deletions
@@ -4,6 +4,8 @@ - CDATA encoding is improved. (Non-standard; Issue #19) - Some parser rules were not returning the new current element. (Issue #20) - Added, to the README, details on code test coverage and to packagist version. +- Fixed processor instructions. +- Improved test coverage. 1.0.0 (2013-10-02) - Initial release. diff --git a/src/HTML5/Parser/DOMTreeBuilder.php b/src/HTML5/Parser/DOMTreeBuilder.php index 094104e..c28b436 100644 --- a/src/HTML5/Parser/DOMTreeBuilder.php +++ b/src/HTML5/Parser/DOMTreeBuilder.php @@ -372,7 +372,7 @@ class DOMTreeBuilder implements EventHandler { // Important: The processor may modify the current DOM tree however // it sees fit. if (isset($this->processor)) { - $res = $processor->process($this->current, $name, $data); + $res = $this->processor->process($this->current, $name, $data); if (!empty($res)) { $this->current = $res; } diff --git a/test/HTML5/Parser/DOMTreeBuilderTest.php b/test/HTML5/Parser/DOMTreeBuilderTest.php index adfc2c9..0adaed5 100644 --- a/test/HTML5/Parser/DOMTreeBuilderTest.php +++ b/test/HTML5/Parser/DOMTreeBuilderTest.php @@ -301,6 +301,14 @@ class DOMTreeBuilderTest extends \HTML5\Tests\TestCase { $this->assertEquals('textPath', $textPath->tagName); } + public function testNoScript() { + $html = '<!DOCTYPE html><html><head><noscript>No JS</noscript></head></html>'; + $doc = $this->parse($html); + $this->assertEmpty($doc->errors); + $noscript = $doc->getElementsByTagName('noscript')->item(0); + $this->assertEquals('noscript', $noscript->tagName); + } + /** * Regression for issue #13 */ @@ -314,4 +322,35 @@ class DOMTreeBuilderTest extends \HTML5\Tests\TestCase { $this->assertEquals('span', $span->tagName); $this->assertEquals('Test', $span->textContent); } + + public function testInstructionProcessor() { + $string = '<!DOCTYPE html><html><?foo bar ?></html>'; + + $treeBuilder = new DOMTreeBuilder(); + $is = new InstructionProcessorMock(); + $treeBuilder->setInstructionProcessor($is); + + $input = new StringInputStream($string); + $scanner = new Scanner($input); + $parser = new Tokenizer($scanner, $treeBuilder); + + $parser->parse(); + + $this->assertEquals(1, $is->count); + $this->assertEquals('foo', $is->name); + $this->assertEquals('bar ', $is->data); + } +} + +class InstructionProcessorMock implements \HTML5\InstructionProcessor { + + public $name = NULL; + public $data = NULL; + public $count = 0; + + public function process(\DOMElement $element, $name, $data) { + $this->name = $name; + $this->data = $data; + $this->count++; + } } |