Skip to content

Commit

Permalink
[DomCrawler] Uppercase http methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed May 25, 2011
1 parent 5e1710f commit 08e7629
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -117,7 +117,7 @@ public function getValues()
*/
public function getFiles()
{
if (!in_array($this->getMethod(), array('post', 'put', 'delete'))) {
if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE'))) {
return array();
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public function getUri()
{
$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;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ public function getMethod()
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';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DomCrawler/Link.php
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Symfony/Tests/Component/DomCrawler/CrawlerTest.php
Expand Up @@ -295,7 +295,7 @@ public function testLink()
$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');
Expand Down
6 changes: 3 additions & 3 deletions tests/Symfony/Tests/Component/DomCrawler/FormTest.php
Expand Up @@ -142,13 +142,13 @@ public function testGetFormNode()
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()
Expand Down
4 changes: 2 additions & 2 deletions tests/Symfony/Tests/Component/DomCrawler/LinkTest.php
Expand Up @@ -56,10 +56,10 @@ public function testGetMethod()
$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');
}

/**
Expand Down

0 comments on commit 08e7629

Please sign in to comment.