Explorar o código

[DomCrawler] Uppercase http methods

Jordi Boggiano %!s(int64=14) %!d(string=hai) anos
pai
achega
08e7629fb4

+ 3 - 3
src/Symfony/Component/DomCrawler/Form.php

@@ -117,7 +117,7 @@ class Form extends Link implements \ArrayAccess
      */
     public function getFiles()
     {
-        if (!in_array($this->getMethod(), array('post', 'put', 'delete'))) {
+        if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE'))) {
             return array();
         }
 
@@ -182,7 +182,7 @@ class Form extends Link implements \ArrayAccess
     {
         $uri = parent::getUri();
 
-        if (!in_array($this->getMethod(), array('post', 'put', 'delete')) && $queryString = http_build_query($this->getValues(), null, '&')) {
+        if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE')) && $queryString = http_build_query($this->getValues(), null, '&')) {
             $sep = false === strpos($uri, '?') ? '?' : '&';
             $uri .= $sep.$queryString;
         }
@@ -210,7 +210,7 @@ class Form extends Link implements \ArrayAccess
             return $this->method;
         }
 
-        return $this->node->getAttribute('method') ? strtolower($this->node->getAttribute('method')) : 'get';
+        return $this->node->getAttribute('method') ? strtoupper($this->node->getAttribute('method')) : 'GET';
     }
 
     /**

+ 2 - 2
src/Symfony/Component/DomCrawler/Link.php

@@ -35,14 +35,14 @@ class Link
      *
      * @api
      */
-    public function __construct(\DOMNode $node, $currentUri, $method = 'get')
+    public function __construct(\DOMNode $node, $currentUri, $method = 'GET')
     {
         if (!in_array(substr($currentUri, 0, 4), array('http', 'file'))) {
             throw new \InvalidArgumentException(sprintf('Current URI must be an absolute URL ("%s").', $currentUri));
         }
 
         $this->setNode($node);
-        $this->method = $method;
+        $this->method = $method ? strtoupper($method) : null;
         $this->currentUri = $currentUri;
     }
 

+ 1 - 1
tests/Symfony/Tests/Component/DomCrawler/CrawlerTest.php

@@ -295,7 +295,7 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase
         $crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');
         $this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Link', $crawler->link(), '->link() returns a Link instance');
 
-        $this->assertEquals('post', $crawler->link('post')->getMethod(), '->link() takes a method as its argument');
+        $this->assertEquals('POST', $crawler->link('post')->getMethod(), '->link() takes a method as its argument');
 
         $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');

+ 3 - 3
tests/Symfony/Tests/Component/DomCrawler/FormTest.php

@@ -142,13 +142,13 @@ class FormTest extends \PHPUnit_Framework_TestCase
     public function testGetMethod()
     {
         $form = $this->createForm('<form><input type="submit" /></form>');
-        $this->assertEquals('get', $form->getMethod(), '->getMethod() returns get if no method is defined');
+        $this->assertEquals('GET', $form->getMethod(), '->getMethod() returns get if no method is defined');
 
         $form = $this->createForm('<form method="post"><input type="submit" /></form>');
-        $this->assertEquals('post', $form->getMethod(), '->getMethod() returns the method attribute value of the form');
+        $this->assertEquals('POST', $form->getMethod(), '->getMethod() returns the method attribute value of the form');
 
         $form = $this->createForm('<form method="post"><input type="submit" /></form>', 'put');
-        $this->assertEquals('put', $form->getMethod(), '->getMethod() returns the method defined in the constructor if provided');
+        $this->assertEquals('PUT', $form->getMethod(), '->getMethod() returns the method defined in the constructor if provided');
     }
 
     public function testGetSetValue()

+ 2 - 2
tests/Symfony/Tests/Component/DomCrawler/LinkTest.php

@@ -56,10 +56,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase
         $node = $dom->getElementsByTagName('a')->item(0);
         $link = new Link($node, 'http://example.com/');
 
-        $this->assertEquals('get', $link->getMethod(), '->getMethod() returns the method of the link');
+        $this->assertEquals('GET', $link->getMethod(), '->getMethod() returns the method of the link');
 
         $link = new Link($node, 'http://example.com/', 'post');
-        $this->assertEquals('post', $link->getMethod(), '->getMethod() returns the method of the link');
+        $this->assertEquals('POST', $link->getMethod(), '->getMethod() returns the method of the link');
     }
 
     /**