Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8b087e

Browse files
committed
Added a $serverParameters argument to submitForm()
1 parent 80fac35 commit c8b087e

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,17 @@ public function submit(Form $form, array $values = array()/*, array $serverParam
321321
* Finds the first form that contains a button with the given content and
322322
* uses it to submit the given form field values.
323323
*
324-
* @param string $button The text content, id, value or name of the form <button> or <input type="submit">
325-
* @param array $fieldValues Use this syntax: array('my_form[name]' => '...', 'my_form[email]' => '...')
326-
* @param string $method The HTTP method used to submit the form
324+
* @param string $button The text content, id, value or name of the form <button> or <input type="submit">
325+
* @param array $fieldValues Use this syntax: array('my_form[name]' => '...', 'my_form[email]' => '...')
326+
* @param string $method The HTTP method used to submit the form
327+
* @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include a HTTP_ prefix as PHP does)
327328
*/
328-
public function submitForm(string $button, array $fieldValues = array(), string $method = 'POST'): Crawler
329+
public function submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array()): Crawler
329330
{
330331
$buttonNode = $this->getCrawler()->selectButton($button);
331332
$form = $buttonNode->form($fieldValues, $method);
332333

333-
return $this->submit($form);
334+
return $this->submit($form, array(), $serverParameters);
334335
}
335336

336337
/**

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,23 @@ public function testSubmit()
371371
public function testSubmitForm()
372372
{
373373
$client = new TestClient();
374-
$client->setNextResponse(new Response('<html><form name="signup" action="/foo"><input type="text" name="username" /><input type="password" name="password" /><input type="submit" value="Register" /></form></html>'));
374+
$client->setNextResponse(new Response('<html><form name="signup" action="/foo"><input type="text" name="username" value="the username" /><input type="password" name="password" value="the password" /><input type="submit" value="Register" /></form></html>'));
375375
$client->request('GET', 'http://www.example.com/foo/foobar');
376376

377377
$client->submitForm('Register', array(
378-
'username' => 'username',
379-
'password' => 'password',
380-
), 'POST');
378+
'username' => 'new username',
379+
'password' => 'new password',
380+
), 'PUT', array(
381+
'HTTP_USER_AGENT' => 'Symfony User Agent',
382+
'HTTPS' => true,
383+
));
381384

382-
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->submit() submit forms');
385+
$this->assertEquals('https://www.example.com/foo', $client->getRequest()->getUri(), '->submitForm() submit forms');
386+
$this->assertEquals('PUT', $client->getRequest()->getMethod(), '->submitForm() allows to change the method');
387+
$this->assertEquals('new username', $client->getRequest()->getParameters()['username'], '->submitForm() allows to override the form values');
388+
$this->assertEquals('new password', $client->getRequest()->getParameters()['password'], '->submitForm() allows to override the form values');
389+
$this->assertEquals('Symfony User Agent', $client->getRequest()->getServer()['HTTP_USER_AGENT'], '->submitForm() allows to change the $_SERVER parameters');
390+
$this->assertEquals(true, $client->getRequest()->getServer()['HTTPS'], '->submitForm() allows to change the $_SERVER parameters');
383391
}
384392

385393
public function testSubmitFormNotFound()

0 commit comments

Comments
 (0)