feature #27956 Added types and tweaked PHPdoc of clickLink() and submitForm() methods (javiereguiluz)
This PR was squashed before being merged into the 4.2-dev branch (closes #27956).
Discussion
----------
Added types and tweaked PHPdoc of clickLink() and submitForm() methods
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | - <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | -
I wanted to suggest these changes to #27807 but I failed to do that before it was merged.
Commits
-------
be9d578d4b
Added types and tweaked PHPdoc of clickLink() and submitForm() methods
This commit is contained in:
commit
d8f78c5314
@ -291,17 +291,13 @@ abstract class Client
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds link by given text and then clicks on it.
|
||||
* Clicks the first link (or clickable image) that contains the given text.
|
||||
*
|
||||
* @param string $value The link text
|
||||
*
|
||||
* @return Crawler
|
||||
* @param string $linkText The text of the link or the alt attribute of the clickable image
|
||||
*/
|
||||
public function clickLink($value)
|
||||
public function clickLink(string $linkText): Crawler
|
||||
{
|
||||
$link = $this->getCrawler()->selectLink($value)->link();
|
||||
|
||||
return $this->click($link);
|
||||
return $this->click($this->getCrawler()->selectLink($linkText)->link());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -322,20 +318,20 @@ abstract class Client
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a form by submit button text and then submits it.
|
||||
* Finds the first form that contains a button with the given content and
|
||||
* uses it to submit the given form field values.
|
||||
*
|
||||
* @param string $button The button text
|
||||
* @param array $values An array of form field values
|
||||
* @param string $method The method for the form
|
||||
*
|
||||
* @return Crawler
|
||||
* @param string $button The text content, id, value or name of the form <button> or <input type="submit">
|
||||
* @param array $fieldValues Use this syntax: array('my_form[name]' => '...', 'my_form[email]' => '...')
|
||||
* @param string $method The HTTP method used to submit the form
|
||||
* @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include a HTTP_ prefix as PHP does)
|
||||
*/
|
||||
public function submitForm($button, $values, $method)
|
||||
public function submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array()): Crawler
|
||||
{
|
||||
$buttonNode = $this->getCrawler()->selectButton($button);
|
||||
$form = $buttonNode->form($values, $method);
|
||||
$form = $buttonNode->form($fieldValues, $method);
|
||||
|
||||
return $this->submit($form);
|
||||
return $this->submit($form, array(), $serverParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -371,15 +371,23 @@ class ClientTest extends TestCase
|
||||
public function testSubmitForm()
|
||||
{
|
||||
$client = new TestClient();
|
||||
$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>'));
|
||||
$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>'));
|
||||
$client->request('GET', 'http://www.example.com/foo/foobar');
|
||||
|
||||
$client->submitForm('Register', array(
|
||||
'username' => 'username',
|
||||
'password' => 'password',
|
||||
), 'POST');
|
||||
'username' => 'new username',
|
||||
'password' => 'new password',
|
||||
), 'PUT', array(
|
||||
'HTTP_USER_AGENT' => 'Symfony User Agent',
|
||||
'HTTPS' => true,
|
||||
));
|
||||
|
||||
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->submit() submit forms');
|
||||
$this->assertEquals('https://www.example.com/foo', $client->getRequest()->getUri(), '->submitForm() submit forms');
|
||||
$this->assertEquals('PUT', $client->getRequest()->getMethod(), '->submitForm() allows to change the method');
|
||||
$this->assertEquals('new username', $client->getRequest()->getParameters()['username'], '->submitForm() allows to override the form values');
|
||||
$this->assertEquals('new password', $client->getRequest()->getParameters()['password'], '->submitForm() allows to override the form values');
|
||||
$this->assertEquals('Symfony User Agent', $client->getRequest()->getServer()['HTTP_USER_AGENT'], '->submitForm() allows to change the $_SERVER parameters');
|
||||
$this->assertEquals(true, $client->getRequest()->getServer()['HTTPS'], '->submitForm() allows to change the $_SERVER parameters');
|
||||
}
|
||||
|
||||
public function testSubmitFormNotFound()
|
||||
|
Reference in New Issue
Block a user