8000 Added types and tweaked PHPdoc of clickLink() and submitForm() methods by javiereguiluz · Pull Request #27956 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Added types and tweaked PHPdoc of clickLink() and submitForm() methods #27956

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,13 @@ public function click(Link $link)
}

/**
* 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());
}

/**
Expand All @@ -322,20 +318,20 @@ public function submit(Form $form, array $values = array()/*, array $serverParam
}

/**
* 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);
}

/**
Expand Down
18 changes: 13 additions & 5 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,23 @@ public function testSubmit()
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()
Expand Down
0