使用PHPUnit的问题勾选复选框(功能测试)

时间:2015-10-13 15:21:58

标签: checkbox phpunit

我有问题通过PHPUnit选择以下代码的复选框。

<div id="user_project">
<input type="checkbox" id="user_project_1" name="user[project][]" value="1" checked="checked" />
<label for="user_project_1">Project 1</label>
<input type="checkbox" id="user_project_2" name="user[project][]" value="2" /><label for="user_project_2">Project 2</label>
<input type="checkbox" id="user_project_3" name="user[project][]" value="3" checked="checked" />
<label for="user_project_3">Project 3</label>
<input type="checkbox" id="user_project_4" name="user[project][]" value="4" checked="checked" />
<label for="user_project_4">Project 4</label>
<input type="checkbox" id="user_project_5" name="user[project][]" value="5" checked="checked" />
<label for="user_project_5">Project 5</label>
<input type="checkbox" id="user_project_6" name="user[project][]" value="6" checked="checked" />
<label for="user_project_6">Project 6</label>
<input type="checkbox" id="user_project_7" name="user[project][]" value="7" />
<label for="user_project_7">Project 7</label>
<input type="checkbox" id="user_project_10" name="user[project][]" value="10" /><label for="user_project_10">Project 10</label>
<input type="checkbox" id="user_project_12" name="user[project][]" value="12" /><label for="user_project_12">Project 12</label>
<input type="checkbox" id="user_project_13" name="user[project][]" value="13" />
<label for="user_project_13">Project 13</label>
</div>

通常情况下,我会勾选复选框,使用“$ form [”复选框名称“] - &gt; tick();” - 但我无法更改名称(因为它是通过Symfony2生成的)。

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

假设您在$form对象中检索表单,请尝试选择第二个元素:

    $select = $form->get('user[project]');
    $cb = $select[1];  // the second table row
    $cb->tick();

希望这个帮助