Form->getUri() should return it's path if no action is defined

This commit is contained in:
Bouke Haarsma 2010-12-24 01:35:33 +01:00 committed by Fabien Potencier
parent 154611e572
commit bf98b3c1ae
2 changed files with 13 additions and 1 deletions

View File

@ -171,6 +171,10 @@ class Form implements \ArrayAccess
$uri = $this->node->getAttribute('action');
$urlHaveScheme = 'http' === substr($uri, 0, 4);
if(!$uri) {
$uri = $this->path;
}
if (!in_array($this->getMethod(), array('post', 'put', 'delete')) && $queryString = http_build_query($this->getValues(), null, '&')) {
$sep = false === strpos($uri, '?') ? '?' : '&';
$uri .= $sep.$queryString;

View File

@ -288,6 +288,14 @@ class FormTest extends \PHPUnit_Framework_TestCase
$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 testGetUriWithoutAction()
{
$form = $this->createForm('<form><input type="submit" /></form>', null, 'http://localhost', '/foo/bar');
$this->assertEquals('http://localhost/foo/bar', $form->getUri(true), '->getUri() returns path if no action defined');
$this->assertEquals('/foo/bar', $form->getUri(false), '->getUri() returns path if no action defined');
}
public function provideGetUriValues()
{
return array(
@ -325,7 +333,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
'returns an empty URI if the action is empty',
'<form><input type="submit" /></form>',
array(),
'',
'/',
),
array(
'appends the form values even if the action is empty',