Skip to content

Commit

Permalink
[DomCrawler] Added support for link tags in the Link class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephaneseng authored and fabpot committed Nov 16, 2014
1 parent e7067cb commit d8d6fcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/DomCrawler/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\DomCrawler;

/**
* Link represents an HTML link (an HTML a or area tag).
* Link represents an HTML link (an HTML a, area or link tag).
*
* @author Fabien Potencier <[email protected]>
*
Expand Down Expand Up @@ -179,8 +179,8 @@ protected function canonicalizePath($path)
*/
protected function setNode(\DOMElement $node)
{
if ('a' !== $node->nodeName && 'area' !== $node->nodeName) {
throw new \LogicException(sprintf('Unable to click on a "%s" tag.', $node->nodeName));
if ('a' !== $node->nodeName && 'area' !== $node->nodeName && 'link' !== $node->nodeName) {
throw new \LogicException(sprintf('Unable to navigate from a "%s" tag.', $node->nodeName));
}

$this->node = $node;
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ public function testGetUriOnArea($url, $currentUri, $expected)
$this->assertEquals($expected, $link->getUri());
}

/**
* @dataProvider getGetUriTests
*/
public function testGetUriOnLink($url, $currentUri, $expected)
{
$dom = new \DOMDocument();
$dom->loadHTML(sprintf('<html><head><link href="%s" /></head></html>', $url));
$link = new Link($dom->getElementsByTagName('link')->item(0), $currentUri);

$this->assertEquals($expected, $link->getUri());
}

public function getGetUriTests()
{
return array(
Expand Down

0 comments on commit d8d6fcf

Please sign in to comment.