使用Symfony DomCrawler在选择输入中选择不可能的值 [英] Select impossible value in select inputs with Symfony DomCrawler
本文介绍了使用Symfony DomCrawler在选择输入中选择不可能的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在表单的select
输入中发送错误的值,我想测试应用程序的行为.
I would like to test the behaviour of my application if I send wrong values in a select
input in form.
这是我的HTML表单:
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.
推荐答案
disableValidation
函数允许在选项中选择不可能的值:
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);
工作完成了!
这篇关于使用Symfony DomCrawler在选择输入中选择不可能的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文