8000 Added types and tweaked PHPdoc of clickLink() and submitForm() methods · symfony/symfony@be9d578 · GitHub
[go: up one dir, main page]

Skip to content

Commit be9d578

Browse files
javiereguiluzfabpot
authored andcommitted
Added types and tweaked PHPdoc of clickLink() and submitForm() methods
1 parent eb112a5 commit be9d578

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,13 @@ public function click(Link $link)
291291
}
292292

293293
/**
294-
* Finds link by given text and then clicks on it.
294+
* Clicks the first link (or clickable image) that contains the given text.
295295
*
296-
* @param string $value The link text
297-
*
298-
* @return Crawler
296+
* @param string $linkText The text of the link or the alt attribute of the clickable image
299297
*/
300-
public function clickLink($value)
298+
public function clickLink(string $linkText): Crawler
301299
{
302-
$link = $this->getCrawler()->selectLink($value)->link();
303-
304-
return $this->click($link);
300+
return $this->click($this->getCrawler()->selectLink($linkText)->link());
305301
}
306302

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

324320
/**
325-
* Finds a form by submit button text and then submits it.
321+
* Finds the first form that contains a button with the given content and
322+
* uses it to submit the given form field values.
326323
*
327-
* @param string $button The button text
328-
* @param array $values An array of form field values
329-
* @param string $method The method for the form
330-
*
331-
* @return Crawler
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)
332328
*/
333-
public function submitForm($button, $values, $method)
329+
public function submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array()): Crawler
334330
{
335331
$buttonNode = $this->getCrawler()->selectButton($button);
336-
$form = $buttonNode->form($values, $method);
332+
$form = $buttonNode->form($fieldValues, $method);
337333

338-
return $this->submit($form);
334+
return $this->submit($form, array(), $serverParameters);
339335
}
340336

341337
/**

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)
0