bug #10245 [DomCrawler] Added support for <area> tags to be treated as links (shamess)
This PR was merged into the 2.3 branch.
Discussion
----------
[DomCrawler] Added support for <area> tags to be treated as links
The [HTML area tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area) behaves exactly like the `a` tag in that they're both clickable, and if it has a `href` follows a link. The Link class works the same with both tags.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Commits
-------
23acd26
[DomCrawler] Added support for <area> tags to be treated as links
This commit is contained in:
commit
8cd285cd2c
@ -12,7 +12,7 @@
|
||||
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>
|
||||
*
|
||||
@ -188,7 +188,7 @@ class Link
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,18 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
||||
$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()
|
||||
{
|
||||
return array(
|
||||
|
Reference in New Issue
Block a user