phpunit src/Symfony/Component/DomCrawler/Tests/FormTest.php #11066 #10808 crawler test (defrag)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11066).

Discussion
----------

#10808 crawler test

 Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |#10808
| License       | MIT

Adds test for #10808

Commits
-------

876d6ca issue #10808 crawler test
This commit is contained in:
Fabien Potencier 2014-06-06 07:27:57 +02:00
commit fddd010e49
2 changed files with 8 additions and 4 deletions

View File

@ -146,7 +146,7 @@ class Form extends Link implements \ArrayAccess
$values = array();
foreach ($this->getValues() as $name => $value) {
$qs = http_build_query(array($name => $value), '', '&');
if(!empty($qs)) {
if (!empty($qs)) {
parse_str($qs, $expandedValue);
$varName = substr($name, 0, strlen(key($expandedValue)));
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
@ -171,7 +171,7 @@ class Form extends Link implements \ArrayAccess
$values = array();
foreach ($this->getFiles() as $name => $value) {
$qs = http_build_query(array($name => $value), '', '&');
if(!empty($qs)) {
if (!empty($qs)) {
parse_str($qs, $expandedValue);
$varName = substr($name, 0, strlen(key($expandedValue)));
$values = array_replace_recursive($values, array($varName => current($expandedValue)));

View File

@ -374,8 +374,8 @@ class FormTest extends \PHPUnit_Framework_TestCase
public function testGetValues()
{
$form = $this->createForm('<form><input type="text" name="foo[bar]" value="foo" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$this->assertEquals(array('foo[bar]' => 'foo', 'bar' => 'bar'), $form->getValues(), '->getValues() returns all form field values');
$form = $this->createForm('<form><input type="text" name="foo[bar]" value="foo" /><input type="text" name="bar" value="bar" /><select multiple="multiple" name="baz[]"></select><input type="submit" /></form>');
$this->assertEquals(array('foo[bar]' => 'foo', 'bar' => 'bar', 'baz' => array()), $form->getValues(), '->getValues() returns all form field values');
$form = $this->createForm('<form><input type="checkbox" name="foo" value="foo" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include not-checked checkboxes');
@ -411,6 +411,10 @@ class FormTest extends \PHPUnit_Framework_TestCase
$form = $this->createForm('<form><input type="text" name="fo.o[ba.r][]" value="foo" /><input type="text" name="fo.o[ba.r][ba.z]" value="bar" /><input type="submit" /></form>');
$this->assertEquals(array('fo.o' => array('ba.r' => array('foo', 'ba.z' => 'bar'))), $form->getPhpValues(), '->getPhpValues() preserves periods and spaces in names recursively');
$form = $this->createForm('<form><input type="text" name="foo[bar]" value="foo" /><input type="text" name="bar" value="bar" /><select multiple="multiple" name="baz[]"></select><input type="submit" /></form>');
$this->assertEquals(array('foo' => array('bar' => 'foo'), 'bar' => 'bar'), $form->getPhpValues(), "->getPhpValues() doesn't return empty values");
}
public function testGetFiles()