/** * {@inheritdoc} */ public function listAttribute($content) { $this->crawler->addContent($content); $this->links = array(); $this->crawler->filter('a')->each(function (HtmlPageCrawler $anchor, $uri) { $href = $anchor->attr('href'); // @todo deprecated method. $this->links[] = $this->urlGenerator->generateFromPath($href, array('absolute' => TRUE)); }); $this->crawler->remove(); return implode(',', $this->links); }
/** * @covers Wa72\HtmlPageDom\HtmlPageCrawler::addContent */ public function testAddContent() { $c = new HtmlPageCrawler(); $c->addContent('<html><body><div id="content"><h1>Title</h1></div></body>'); $this->assertEquals('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">' . "\n" . '<html><body><div id="content"><h1>Title</h1></div></body></html>' . "\n", $c->saveHTML()); $c = new HtmlPageCrawler(); $c->addContent('<div id="content"><h1>Title'); $this->assertEquals('<div id="content"><h1>Title</h1></div>', $c->saveHTML()); $c = new HtmlPageCrawler(); $c->addContent('<p>asdf<p>asdfaf</p>'); $this->assertEquals(2, count($c)); $this->assertEquals('<p>asdf</p><p>asdfaf</p>', $c->saveHTML()); }