[DomCrawler] Added tests to verify previous fix
This commit is contained in:
parent
20ca97c5b3
commit
a6da0fb0c4
@ -299,6 +299,9 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$crawler = $this->createTestCrawler('http://example.com/bar')->selectLink('Foo');
|
$crawler = $this->createTestCrawler('http://example.com/bar')->selectLink('Foo');
|
||||||
$this->assertEquals('http://example.com/foo', $crawler->link()->getUri(), '->link() returns a Link instance');
|
$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 {
|
try {
|
||||||
$this->createTestCrawler()->filter('ol')->link();
|
$this->createTestCrawler()->filter('ol')->link();
|
||||||
$this->fail('->link() throws an \InvalidArgumentException if the node list is empty');
|
$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"s Bar"/></a>
|
<a href="/bar"><img alt="Fabien"s Bar"/></a>
|
||||||
<a href="/bar"><img alt="\' Fabien"s Bar"/></a>
|
<a href="/bar"><img alt="\' Fabien"s Bar"/></a>
|
||||||
|
|
||||||
|
<a href="?get=param">GetLink</a>
|
||||||
|
|
||||||
<form action="foo">
|
<form action="foo">
|
||||||
<input type="submit" value="FooValue" name="FooName" id="FooId" />
|
<input type="submit" value="FooValue" name="FooName" id="FooId" />
|
||||||
<input type="button" value="BarValue" name="BarName" id="BarId" />
|
<input type="button" value="BarValue" name="BarName" id="BarId" />
|
||||||
|
@ -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');
|
$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()
|
public function provideGetUriValues()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
@ -72,5 +72,15 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$link = new Link($node, 'get','http://www.foo.com','/bar/');
|
$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');
|
$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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user