[DomCrawler] Added tests to verify previous fix

This commit is contained in:
Jordi Boggiano 2010-09-02 20:47:15 +02:00 committed by Fabien Potencier
parent 20ca97c5b3
commit a6da0fb0c4
3 changed files with 23 additions and 0 deletions

View File

@ -299,6 +299,9 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase
$crawler = $this->createTestCrawler('http://example.com/bar')->selectLink('Foo');
$this->assertEquals('http://example.com/foo', $crawler->link()->getUri(), '->link() returns a Link instance');
$crawler = $this->createTestCrawler('http://example.com/bar')->selectLink('GetLink');
$this->assertEquals('http://example.com/bar?get=param', $crawler->link()->getUri(), '->link() returns a Link instance');
try {
$this->createTestCrawler()->filter('ol')->link();
$this->fail('->link() throws an \InvalidArgumentException if the node list is empty');
@ -475,6 +478,8 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase
<a href="/bar"><img alt="Fabien&quot;s Bar"/></a>
<a href="/bar"><img alt="\' Fabien&quot;s Bar"/></a>
<a href="?get=param">GetLink</a>
<form action="foo">
<input type="submit" value="FooValue" name="FooName" id="FooId" />
<input type="button" value="BarValue" name="BarName" id="BarId" />

View File

@ -280,6 +280,14 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('/foo', $form->getUri(true), '->getUri() returns absolute URIs only if the host has been defined in the constructor');
}
public function testGetUriWithOnlyQueryString()
{
$form = $this->createForm('<form action="?get=param"><input type="submit" /></form>', null, 'http://localhost', '/foo/bar');
$this->assertEquals('http://localhost/foo/bar?get=param', $form->getUri(true), '->getUri() returns absolute URIs only if the host has been defined in the constructor');
$this->assertEquals('/foo/bar?get=param', $form->getUri(false), '->getUri() returns absolute URIs only if the host has been defined in the constructor');
}
public function provideGetUriValues()
{
return array(

View File

@ -72,5 +72,15 @@ class LinkTest extends \PHPUnit_Framework_TestCase
$link = new Link($node, 'get','http://www.foo.com','/bar/');
$this->assertEquals('http://login.foo.com/foo', $link->getUri(), '->getUri() returns the absolute URI of the link, regardless of the context of the object');
$dom = new \DOMDocument();
$dom->loadHTML('<html><a href="?get=param">foo</a></html>');
$node = $dom->getElementsByTagName('a')->item(0);
$link = new Link($node, 'get', 'http://www.foo.com', '/foo/bar');
$this->assertEquals('http://www.foo.com/foo/bar?get=param', $link->getUri(), '->getUri() returns the absolute URI of the link, regardless of the context of the object');
$link = new Link($node, 'get', 'http://www.foo.com', '/foo/bar');
$this->assertEquals('/foo/bar?get=param', $link->getUri(false), '->getUri() returns the relative URI of the link if false is the first argument');
}
}