summaryrefslogtreecommitdiff
path: root/test/HTML5/Parser
diff options
context:
space:
mode:
authorValentin Kunz <[email protected]>2016-05-12 14:29:41 +0000
committerAsmir Mustafic <[email protected]>2016-09-22 12:37:05 +0200
commit9b0419a214d6c20b25de615653cc07597719fb1b (patch)
tree822556bd8a8b824d9dcaff6cd5f81a3314bcd159 /test/HTML5/Parser
parentc30ea30fa99c3475e09e81499ef3d9a869043d4a (diff)
don't close optgroup when followed by an option
Make sure options are children of optgroup, not the parent select. Otherwise we end up with a bunch of empty optgroups.
Diffstat (limited to 'test/HTML5/Parser')
-rw-r--r--test/HTML5/Parser/DOMTreeBuilderTest.php29
-rw-r--r--test/HTML5/Parser/TreeBuildingRulesTest.php13
2 files changed, 42 insertions, 0 deletions
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');