Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Browserkit][Form][Tests] Add submitWithAdditionalValues() method in Symfony\Component\BrowserK…#18330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
4c62292 to38e5d55Comparealexislefebvre commentedMar 27, 2016
I don't know why tests are failing, on AppVeyor the error is not related to my changes and on Travis CI I don't know what is |
38e5d55 to582a494CompareHeahDude commentedMar 27, 2016
Failures are unrelated :) |
HeahDude commentedMar 27, 2016
Actually travis fails because#18275 has not been reverted in 3.0 and master yet. |
fabpot commentedMar 27, 2016
It has been reverted in 3.0 |
fabpot commentedMar 27, 2016
and in master as well now. |
582a494 to36542ccComparealexislefebvre commentedMar 27, 2016
I have force-pushed the commit to launch CI tests again. |
ad02c38 to31a542fComparejaviereguiluz commentedMar 29, 2016
@alexislefebvre thanks for sending this proposal. I'm not against it ... but adding a new method always "complicates" things (people must learn a new method, Symfony developers need to maintain that method forever, etc.) I'd like to ask some Symfony Form experts, like@HeahDude, if they think this is absolutely necessary or if the problem to solve (which I don't understand) can be solved in a simpler way. Thanks! |
HeahDude commentedMar 29, 2016
@javiereguiluz Please don't say I'm an expert :) "involved" seems more appropriate. For me it's a 👍 (I've already add one it a few days ago on the description). |
javiereguiluz commentedMar 29, 2016
@HeahDude could you please explain the problem to solve to people like me, not involved in the Form component?@alexislefebvre said:"I want to submit additional values in my tests but Symfony doesn't allow me to do that". Why does he want to submit additional values? Why doesn't Symfony allow to do that? Why should be "force" Symfony yo allow something it doesn't allow? Thanks. |
HeahDude commentedMar 29, 2016
@javiereguiluz because a form view in a template (like used in a tested page with a crawler) might contain no fields. Think of a Currently the This PR fixes it by allowing to submit extra fields. |
javiereguiluz commentedMar 29, 2016
@HeahDude thanks for the explanation. I think the "right" solution would be to allow the crawler to add nodes dynamically and then submit the form ... but my guess is that they want to maintain the DomCrawler as "read-only", so we can't add anything. Therefore, the proposed solution seems the way to go. Thanks! |
HeahDude commentedMar 29, 2016
Maybe this one could have a |
| $this->assertEquals('http://www.example.com/foo',$client->getRequest()->getUri(),'->submit() submit forms'); | ||
| // The field "foo[0]" have been converted to an array "foo => 0". | ||
| $this->assertEquals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe this test would be more readable assigning variables:
$client->setNextResponse(newResponse('<html><form action="/foo"><input type="submit" /></form></html>'));$crawler =$client->request('GET','http://www.example.com/foo/foobar');$additionalValues =array('foo[0]' =>'bar');$expectedParameters =array('foo' =>array('0' =>'bar'));$client->submitWithAdditionalValues($crawler->filter('input')->form(),array(),$additionalValues);$this->assertEquals('http://www.example.com/foo',$client->getRequest()->getUri(),'->submit() submit forms');$this->assertEquals($expectedParameters,$client->getRequest()->getParameters(),'parameters have not been added');
alexislefebvre commentedMar 29, 2016
Thanks@HeahDude for your explanation to@javiereguiluz. :) Upon further reflection, one drawback of this If you're not OK to add a new method for a not so common case, I suggest another approach:
|
HeahDude commentedMar 29, 2016
ping@jakzal :) |
31a542f tod18e89bCompared18e89b to6cf66b1Comparealexislefebvre commentedApr 2, 2016
Can someone please give some feedback about mylast comment? Thanks. |
| return$this->request($form->getMethod(),$form->getUri(),$form->getPhpValues(),$form->getPhpFiles()); | ||
| } | ||
| /** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
with additional values ?
c39e500 toea5d7deCompareHeahDude commentedApr 2, 2016
Looks good :) |
HeahDude commentedApr 2, 2016
Since the method is in |
HeahDude commentedApr 2, 2016
or |
HeahDude commentedApr 2, 2016
Tests are failing because you need to update the |
…it\ClientExtract code that converts fields to arrays in a new method convertFieldsToArray()
ea5d7de to3823aebComparealexislefebvre commentedApr 2, 2016
After further reflection, I don't like this |
alexislefebvre commentedApr 2, 2016
I'll work on the documentation instead, these changes are not necessary to test a collection of fields. |
alexislefebvre commentedApr 2, 2016
Thanks to@HeahDude and the others for your help and sorry for the inconvenience! I opened aPR for the documentation, I hope that it will be more useful to document how to test a form collection for all the Symfony versions instead of adding a method that will be usable only with the last version of Symfony. |
This PR adds a
submitWithAdditionalValues()method which you can use in order to submit a form with additional data during tests.For example, when you have a
CollectionTypewith the'allow_add' => true,option, you can't change the values with$form[FIELD_NAME][…] = 'foo', it triggers an error.With the
submitWithAdditionalValues()method you can add some fields to the request:Where
array('foo[0]' => 'bar'),is an array which values won't be checked (Symfony won't check if the field exist).