diff options
-rw-r--r-- | src/HTML5/Parser/TreeBuildingRules.php | 1 | ||||
-rw-r--r-- | test/HTML5/Parser/DOMTreeBuilderTest.php | 29 | ||||
-rw-r--r-- | test/HTML5/Parser/TreeBuildingRulesTest.php | 13 |
3 files changed, 42 insertions, 1 deletions
diff --git a/src/HTML5/Parser/TreeBuildingRules.php b/src/HTML5/Parser/TreeBuildingRules.php index 2af3c66..6236208 100644 --- a/src/HTML5/Parser/TreeBuildingRules.php +++ b/src/HTML5/Parser/TreeBuildingRules.php @@ -76,7 +76,6 @@ class TreeBuildingRules case 'option': return $this->closeIfCurrentMatches($new, $current, array( 'option', - 'optgroup' )); case 'tr': return $this->closeIfCurrentMatches($new, $current, array( diff --git a/test/HTML5/Parser/DOMTreeBuilderTest.php b/test/HTML5/Parser/DOMTreeBuilderTest.php index d0bea5f..95d870b 100644 --- a/test/HTML5/Parser/DOMTreeBuilderTest.php +++ b/test/HTML5/Parser/DOMTreeBuilderTest.php @@ -540,4 +540,33 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEquals('div', $div->tagName); $this->assertEquals('foo', $div->textContent); } + + public function testSelectGroupedOptions() + { + $html = <<<EOM +<!DOCTYPE html> +<html> + <head> + <title>testSelectGroupedOptions</title> + </head> + <body> + <select> + <optgroup id="first" label="first"> + <option value="foo">foo</option> + <option value="bar">bar</option> + <option value="baz">baz</option> + </optgroup> + <optgroup id="second" label="first"> + <option value="lorem">lorem</option> + <option value="ipsum">ipsum</option> + </optgroup> + </select> + </body> +</html> +EOM; + $dom = $this->parse($html); + + $this->assertSame(3, $dom->getElementById('first')->getElementsByTagName('option')->length); + $this->assertSame(2, $dom->getElementById('second')->getElementsByTagName('option')->length); + } } diff --git a/test/HTML5/Parser/TreeBuildingRulesTest.php b/test/HTML5/Parser/TreeBuildingRulesTest.php index bff2530..59d65a2 100644 --- a/test/HTML5/Parser/TreeBuildingRulesTest.php +++ b/test/HTML5/Parser/TreeBuildingRulesTest.php @@ -90,6 +90,19 @@ class TreeBuildingRulesTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEquals('dd', $list->lastChild->tagName); } + public function testHandleOption() + { + $html = sprintf(self::HTML_STUB, '<optgroup id="foo" label="foo" ><option value="foo" >bar</option></optgroup>'); + $doc = $this->parse($html); + + $list = $doc->getElementById('foo'); + + $this->assertEquals(1, $list->childNodes->length); + foreach ($list->childNodes as $ele) { + $this->assertEquals('option', $ele->tagName); + } + } + public function testTable() { $html = sprintf(self::HTML_STUB, '<table><thead id="a"><th>foo<td>bar<td>baz'); |