/** * @covers Wa72\HtmlPageDom\HtmlPageCrawler::wrap */ public function testWrap() { $c = new HtmlPageCrawler('<div id="content"><h1>Title</h1></div>'); $c->filter('h1')->wrap('<div class="innercontent">'); $this->assertEquals('<div id="content"><div class="innercontent"><h1>Title</h1></div></div>', $c->saveHTML()); $c = new HtmlPageCrawler('<div id="content"><h1>Title</h1></div>'); $c->filter('h1')->wrap('<div class="ic">asdf<div class="a1"><div class="a2"></div></div></div></div>'); $this->assertEquals('<div id="content"><div class="ic">asdf<div class="a1"><div class="a2"><h1>Title</h1></div></div></div></div>', $c->saveHTML()); $c = new HtmlPageCrawler('<div id="content"><h1>Title</h1></div>'); $c->filter('h1')->wrap('<div class="ic">asdf</div><div>jkl</div>'); // wrap has more than 1 root element $this->assertEquals('<div id="content"><div class="ic">asdf<h1>Title</h1></div></div>', $c->saveHTML()); // only first element is used // Test for wrapping multiple nodes $c = new HtmlPageCrawler('<div id="content"><p>p1</p><p>p2</p></div>'); $c->filter('p')->wrap('<div class="p"></div>'); $this->assertEquals('<div id="content"><div class="p"><p>p1</p></div><div class="p"><p>p2</p></div></div>', $c->saveHTML()); $c = new HtmlPageCrawler('plain text node'); $c->wrap('<div class="ic"></div>'); $this->assertEquals('<div class="ic">plain text node</div>', $c->parents()->eq(0)->saveHTML()); $c = HtmlPageCrawler::create('<div>'); $m = HtmlPageCrawler::create('message 1')->appendTo($c); $m->wrap('<p>'); $m = HtmlPageCrawler::create('message 2')->appendTo($c); $m->wrap('<p>'); $this->assertEquals('<div><p>message 1</p><p>message 2</p></div>', $c->saveHTML()); }