Skip to content

Simplify some parts of the functional tests #27627

Closed
@javiereguiluz

Description

@javiereguiluz

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');

Metadata

Metadata

Assignees

No one assigned

    Labels

    BrowserKitDXDX = Developer eXperience (anything that improves the experience of using Symfony)Feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions