Skip to content

Instantly share code, notes, and snippets.

@havvg
Created May 22, 2013 10:12
Show Gist options
  • Save havvg/5626552 to your computer and use it in GitHub Desktop.
Save havvg/5626552 to your computer and use it in GitHub Desktop.
<?php
use Symfony\Component\DomCrawler\Crawler;
class CrawlerTest extends \PHPUnit_Framework_TestCase
{
public function testAttribute()
{
$xml = <<<XML
<div>
<a>Foo</a>
<a rel="somefield[withKey]">Bar</a>
<a rel="somefield[withKey]" href="http://example.com">Baz</a>
</div>
XML;
$crawler = new Crawler($xml);
$this->assertEquals([
'',
'http://example.com',
], $crawler->filterXPath('//a[@rel="somefield[withKey]"]')->extract(['href']));
$this->assertEquals([
'http://example.com',
], $crawler->filterXPath('//a[@rel="somefield[withKey]"][@href]')->extract(['href']));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment