Sets the attributes for this tag
public setAttributes ( array $attr ) | ||
$attr | array |
public function testOuterHtmlEmpty() { $a = new Tag('a'); $a->setAttributes(['href' => ['value' => 'http://google.com', 'doubleQuote' => false]]); $node = new HtmlNode($a); $this->assertEquals("<a href='http://google.com'></a>", $node->OuterHtml()); }
public function testMakeOpeningTagEmptyAttr() { $attr = ['href' => ['value' => 'http://google.com', 'doubleQuote' => true]]; $tag = new Tag('a'); $tag->setAttributes($attr); $tag->selected = ['value' => null]; $this->assertEquals('<a href="http://google.com" selected>', $tag->makeOpeningTag()); }
public function testIterator() { $div = new Tag('div'); $div->setAttributes(['class' => ['value' => 'all', 'doubleQuote' => true]]); $a = new Tag('a'); $a->setAttributes(['href' => ['value' => 'http://google.com', 'doubleQuote' => false]]); $br = new Tag('br'); $br->selfClosing(); $parent = new HtmlNode($div); $childa = new HtmlNode($a); $childbr = new HtmlNode($br); $parent->addChild($childa); $parent->addChild($childbr); $childa->addChild(new TextNode('link')); $children = 0; foreach ($parent as $child) { ++$children; } $this->assertEquals(2, $children); }