diff --git a/src/dom-document/class.dom-element.php b/src/dom-document/class.dom-element.php index 147cda5a..e9c3684d 100644 --- a/src/dom-document/class.dom-element.php +++ b/src/dom-document/class.dom-element.php @@ -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) { @@ -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)) diff --git a/tests/test.php b/tests/test.php index aaa5bafb..bd27b7d6 100644 --- a/tests/test.php +++ b/tests/test.php @@ -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", @@ -205,7 +238,7 @@ $video->data([ "one" => "1", "two" => "2", - "three" => "3" + "three" => 3 ]); },