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.
[Browserkit][Form][Tests] Add submitWithAdditionalValues() method in Symfony\Component\BrowserK…#18330
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -286,6 +286,52 @@ public function testSubmit() | ||
| $this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->submit() submit forms'); | ||
| } | ||
| /** | ||
| * @expectedException \InvalidArgumentException | ||
| * @expectedExceptionMessage Unreachable field "foo" | ||
| */ | ||
| public function testSubmitMissingField() | ||
| { | ||
| $client = new TestClient(); | ||
| $client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>')); | ||
| $crawler = $client->request('GET', 'http://www.example.com/foo/foobar'); | ||
| $client->submit($crawler->filter('input')->form(), array('foo[0]' => 'bar')); | ||
| } | ||
| /** | ||
| * Submit the same data that in testSubmitMissingField() but | ||
| * without triggering an Exception. | ||
| */ | ||
| public function testSubmitWithAdditionalValues() | ||
| { | ||
| $client = new TestClient(); | ||
| $client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>')); | ||
| $crawler = $client->request('GET', 'http://www.example.com/foo/foobar'); | ||
| $additionalValues = array('foo[0]' => 'bar'); | ||
| // The field "foo[0]" will be converted to an array "foo => 0". | ||
| $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'); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Maybe should you reverse the message meaning ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not sure to understand your question. This text appears only if | ||
| // Add an element to an existing collection. | ||
| $client->setNextResponse(new Response('<html><form action="/foo" method="post"><input type="text" name="foo[0][name]" value="foo" /><input type="text" name="foo[1][name]" value="bar" /><input type="submit" /></form></html>')); | ||
| $crawler = $client->request('GET', 'http://www.example.com/foo/foobar'); | ||
| $additionalValues = array('foo[2][name]' => 'foobar'); | ||
| $expectedParameters = array('foo' => array('2' => array('name' => 'foobar'))); | ||
| $form = $crawler->filter('input[type=submit]')->form(); | ||
| $client->submitWithAdditionalValues($form, $form->getPhpValues(), $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'); | ||
| } | ||
| public function testSubmitPreserveAuth() | ||
| { | ||
| $client = new TestClient(array('PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar')); | ||