Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Symfony\Component\DomCrawler\Field\ChoiceFormField should accept selecting by content #51423

Open
@tarjei

Description

@tarjei

Description

If I got a formfield like:

$form->add('status', ChoiceType::class, [
    'label' => 'Status',
    'choices' => [
        'error' => 'Error',
        'ok' => 'This is ok'
    ]
]);

Then in my test I should be able to do:

$form = $crawler->form();
$form['form[status]']->selectByText('This is ok');

Today I must do this by having an outside algorithm:

private function formSelectChoose(ChoiceFormField $formField, string $value, Crawler $crawler )
{
    $name = $formField->getName();
    $select = $crawler->filter('select[name="'.$name.'"]')->first();
    foreach($select->filter('option') as $option) {
        print $option->textContent ."\n";
        if (trim($option->textContent) == $value) {
            $formField->select($option->getAttribute('value'));
            return;
        }
    }
    throw new \Exception("Could not find option $value");
}

It would be great to be able to do this directly on the ChoiceFormField.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions