我想创建一个测试,它将直接将数据发布到Laravel页面,以测试它处理坏数据。
我可以从打开表单的页面开始运行验收测试,调用$I->click('Search');
,页面将按预期处理数据。
阅读Codeception网站上的功能测试介绍,它指出
In simple terms we set $_REQUEST, $_GET and $_POST variables, then we execute your script inside a test, we receive output, and then we test it.
这听起来很理想,设置一个POST数据数组并直接在处理页面上激发它。但我找不到任何文档。我玩过sendAjaxPostRequest
,但它没有向$_POST传递任何信息。
有没有一种方法可以像这样孤立地测试页面?
发现解决方案在于Codeception REST模块。
将其添加到functional.suite.yml
文件中可以写入:
$I = new TestGuy($scenario);
$I->wantTo('check a page is resistant to POST injection');
$I->sendPOST(
'search',
array(
'startDate' => '2013-07-03',
'endDate' => '2013-07-10',
'exec' => 'some dodgy commands',
));
$I->see('Search results');
$I->dontSee('Dodgy command executed');
有点笨重,但它允许对单个页面进行测试。
来自手册@http://codeception.com/docs/04-AcceptanceTests
$I->submitForm('#update_form',array('user'=>array('name'=>'Miles',"电子邮件"=>"Davis",'gender'=>'m')))