Closed
Description
Description
The code needed to click links or submit forms in functional tests looks a bit verbose.
The steps used to get the Link
object may be OK when using this inside the DomCrawler component ... because you can do advanced things like calling the getUri()
on the Link
object. However, when using this inside a Symfony app, it looks unnecessary.
Example
Links
Before:
$link = $crawler->selectLink('Click here')->link();
$client->click($link);
After:
$client->click('Click here');
// if click() arguments can't be changed, then
// $client->clickLink(...)
Forms
Before:
$buttonCrawlerNode = $crawler->selectButton('Register');
$form = $buttonCrawlerNode->form();
$form = $buttonCrawlerNode->form([
'my_form_name[name]' => 'Fabien',
'my_form_name[subject]' => 'Symfony rocks!',
], 'DELETE');
$client->submit($form);
After:
$client->submit('Register', [
'my_form_name[name]' => 'Fabien',
'my_form_name[subject]' => 'Symfony rocks!',
], 'DELETE');
// if submit() arguments can't be changed, then
// $client->submitForm(...)
We could also change how things work and take the forms via their names (if they don't have a name, then use the traditional way). The above example would look like this:
$client->submit('my_form_name', [
'name' => 'Fabien',
'subject' => 'Symfony rocks!',
], 'DELETE');