selfClosing() public method

Sets the tag to be self closing.
public selfClosing ( )
Example #1
0
 public function testOuterHtml()
 {
     $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'));
     $this->assertEquals('<div class="all"><a href=\'http://google.com\'>link</a><br /></div>', $parent->outerHtml());
 }
Example #2
0
 public function testMakeClosingTagSelfClosing()
 {
     $tag = new Tag('div');
     $tag->selfClosing();
     $this->assertEmpty($tag->makeClosingTag());
 }
Example #3
0
 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);
 }