[DomCrawler] Added support for <area> tags to be treated as links

This commit is contained in:
Shane Preece 2014-02-11 14:26:57 +00:00
parent a1813cb57a
commit 23acd26d4a
2 changed files with 14 additions and 2 deletions

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\DomCrawler; namespace Symfony\Component\DomCrawler;
/** /**
* Link represents an HTML link (an HTML a tag). * Link represents an HTML link (an HTML a or area tag).
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
* *
@ -188,7 +188,7 @@ class Link
*/ */
protected function setNode(\DOMNode $node) protected function setNode(\DOMNode $node)
{ {
if ('a' != $node->nodeName) { if ('a' != $node->nodeName && 'area' != $node->nodeName) {
throw new \LogicException(sprintf('Unable to click on a "%s" tag.', $node->nodeName)); throw new \LogicException(sprintf('Unable to click on a "%s" tag.', $node->nodeName));
} }

View File

@ -74,6 +74,18 @@ class LinkTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $link->getUri()); $this->assertEquals($expected, $link->getUri());
} }
/**
* @dataProvider getGetUriTests
*/
public function testGetUriOnArea($url, $currentUri, $expected)
{
$dom = new \DOMDocument();
$dom->loadHTML(sprintf('<html><map><area href="%s" /></map></html>', $url));
$link = new Link($dom->getElementsByTagName('area')->item(0), $currentUri);
$this->assertEquals($expected, $link->getUri());
}
public function getGetUriTests() public function getGetUriTests()
{ {
return array( return array(