浏览代码

[DomCrawler] Added tests to verify previous fix

Jordi Boggiano 14 年之前
父节点
当前提交
a6da0fb0c4

+ 5 - 0
tests/Symfony/Tests/Component/DomCrawler/CrawlerTest.php

@@ -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" />

+ 8 - 0
tests/Symfony/Tests/Component/DomCrawler/FormTest.php

@@ -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(

+ 10 - 0
tests/Symfony/Tests/Component/DomCrawler/LinkTest.php

@@ -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');
     }
 }