I would like to test the behaviour of my application if I send wrong values in a select
input in form.
This is my form in HTML :
<form (...)>
(...)
<select name="select_input">
<option value="1">text</option>
</select>
</select>
In my test, in get the form with the crawler and try to "select" an incorrect value :
$form['select_input'] = 9999999;
$client->submit($form);
/* EDIT */
/*I am expecting the user to not be redirected to the user page,
and the server to respond with the same form, containing an error message */
$this->assertFalse($client->getResponse()->isRedirect('/success_page'));
$this->assertEquals(1, $client->getCrawler()->filter('input.error'));
But in the console, I get the message :
InvalidArgumentException: Input "user_profile[voteProfile]" cannot take "9999999" as a value (possible values: 1)
How can I choose an incorrect value for testing the answer ? It would be possible to send an incorrect value by a real server.
The disableValidation
function allow to select impossible values in options :
$form = $crawler->selectButton('button')->form();
$form->get('select_input')->disableValidation()->setValue(999999);
$client->submit($form);
And the job is done !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With