Symfony2功能测试以选中复选框 [英] Symfony2 functional test to select checkboxes

查看:73
本文介绍了Symfony2功能测试以选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编写Symfony 2功能测试以设置作为数组一部分的复选框时遇到麻烦(即,多个展开的选择小部件)

I'm having trouble writing a Symfony 2 functional test to set checkboxes that are part of an array (i.e. a multiple and expanded select widget)

文档中,示例为

$form['registration[interests]']->select(array('symfony', 'cookies'));

但是它没有显示可以使用的html,也不适用于我的.这是我表格的精简版

But it doesn't show what html that will work with and it doesn't work with mine. Here is a cutdown version of my form

<form class="proxy" action="/proxy/13/update" method="post" >
    <input type="checkbox" id="niwa_pictbundle_proxytype_chronologyControls_1" name="niwa_pictbundle_proxytype[chronologyControls][]" value="1" />

    <input type="checkbox" id="niwa_pictbundle_proxytype_chronologyControls_2" name="niwa_pictbundle_proxytype[chronologyControls][]" value="2" />

    <input type="checkbox" id="niwa_pictbundle_proxytype_chronologyControls_3" name="niwa_pictbundle_proxytype[chronologyControls][]" value="3" />
</form>   

一旦它开始工作,我将继续使用手工制作的表格

Once it get it working there I'm going to move on to a manually made form

<input type="checkbox" id="13" name="proxyIDs[]" value="13">
<input type="checkbox" id="14" name="proxyIDs[]" value="14">
<input type="checkbox" id="15" name="proxyIDs[]" value="15">

我尝试过

$form = $crawler->selectButton('Save')->form();
$form['niwa_pictbundle_proxytype[chronologyControls]']->select(array('3'));
$form['niwa_pictbundle_proxytype[chronologyControls][]']->select(array('3'));

,但第一个失败说select正在非对象上运行,第二个失败说Unreachable field "".

but the first fails saying select is being run on a non-object and the second says Unreachable field "".

推荐答案

尝试

$form['niwa_pictbundle_proxytype[chronologyControls]'][0]->tick();

即使以[]

或者,如果它对您没有真正的帮助,您可以尝试直接将数组发布到操作上,而不是使用symfony的表单选择器.请参阅: Symfony2:对ArrayCollection的测试会给出无法访问的字段"

Or if it doesn't really helps you, you can try POSTing an array directly to the action instead of using symfony's form selectors. See: Symfony2: Test on ArrayCollection gives "Unreachable field"

希望其中之一可以帮助您.

Hope one of them helps you.

这篇关于Symfony2功能测试以选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆