Skip to content

Commit 5df4c5f

Browse files
committed
Added a whitespaceTextNode option and test
1 parent c4e74fa commit 5df4c5f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ class Dom {
5656
*/
5757
protected $globalOptions = [];
5858

59+
/**
60+
* A persistent option object to be used for all options in the
61+
* parsing of the file.
62+
*
63+
* @var Options
64+
*/
65+
protected $options;
66+
5967
/**
6068
* A list of tags which will always be self closing
6169
*

tests/DomTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,26 @@ public function testGetElementsByClass()
156156
$dom->load('<div class="all"><p>Hey bro, <a href="google.com" id="78">click here</a></div><br />');
157157
$this->assertEquals('<p>Hey bro, <a href="google.com" id="78">click here</a></p>', $dom->getElementsByClass('all')[0]->innerHtml);
158158
}
159+
160+
public function testConfigGlobalNoWhitespaceTextNode()
161+
{
162+
$dom = new Dom;
163+
$dom->setOptions([
164+
'whitespaceTextNode' => false,
165+
]);
166+
$dom->load('<div><p id="hey">Hey you</p> <p id="ya">Ya you!</p></div>');
167+
$this->assertEquals('Ya you!', $dom->getElementById('hey')->nextSibling()->text);
168+
}
169+
170+
public function testConfigLocalOverride()
171+
{
172+
$dom = new Dom;
173+
$dom->setOptions([
174+
'whitespaceTextNode' => false,
175+
]);
176+
$dom->load('<div><p id="hey">Hey you</p> <p id="ya">Ya you!</p></div>', [
177+
'whitespaceTextNode' => true,
178+
]);
179+
$this->assertEquals(' ', $dom->getElementById('hey')->nextSibling()->text);
180+
}
159181
}

0 commit comments

Comments
 (0)