Skip to content

Commit

Permalink
Merge pull request #23 from PerryRylance/Fix-html-does-not-clear-befo…
Browse files Browse the repository at this point in the history
…re-importing

Fix html does not clear before importing
  • Loading branch information
PerryRylance authored Feb 13, 2021
2 parents d3c998a + 1c94b5c commit bf2ee5d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/dom-document/class.dom-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ public function html($html=null)
"disable_html_ns" => true
]);

$this->clear();

$body = $temp->querySelector('#domdocument-import-payload___');
for($child = $body->firstChild; $child != null; $child = $child->nextSibling)
{
Expand Down Expand Up @@ -529,7 +531,7 @@ public function attr($arg, $val=null)
if(!is_string($arg) && !is_array($arg))
throw new \Exception("First argument must be a string attribute name, or a key value array of attributes to set");

if($val === null)
if($val === null && is_string($arg))
return $this->getAttribute($arg);

if(is_string($arg))
Expand Down
35 changes: 34 additions & 1 deletion tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,39 @@

],

[
"caption" => "Attribute handling",

"operation" => function() {

global $document;

$video = $document->querySelector("video");

$video->attr("controls", "true");
$video->attr([
"muted" => true,
"autoplay" => true
]);

},

"assertion" => function() {

global $document;

$video = $document->querySelector("video");

return (
$video->attr("controls") == "true"
&& $video->attr("muted")
&& $video->attr("autoplay")
);

}

],

[

"caption" => "data- attribute interface",
Expand All @@ -205,7 +238,7 @@
$video->data([
"one" => "1",
"two" => "2",
"three" => "3"
"three" => 3
]);

},
Expand Down

0 comments on commit bf2ee5d

Please sign in to comment.