0

我正处于功能测试学习曲线的陡峭部分。在更改机构状态(是->否、否->是)的简单表单上,记录编辑失败。测试代码为:

$crawler = $client->request('GET', '/agency/manage');
//read agency table
$nodeValues = $crawler->filter('td')->each(function ($node, $i) {
    return $node->nodeValue;
});

//$initial = number of Active=Yes agencies
$initial = 0;
foreach ($nodeValues as $node) {
    if ($node == 'Yes') {
        $initial ++;
    }
}
//edit agency to Active=No
$crawler = $client->request('GET', '/agency/1/edit');
$form = $crawler->selectButton('Edit')->form();
$form['agency[active]'] = 'No';
$crawler = $client->submit($form);

$crawler = $client->request('GET', '/agency/manage');

$nodeValues = $crawler->filter('td')->each(function ($node, $i) {
    return $node->nodeValue;
});

//$final = number of Active=Yes agencies
$final = 0;
foreach ($nodeValues as $node) {
    if ($node == 'Yes') {
        $final ++;
    }
}

$this->assertTrue($initial > $final);

对于我的测试用例,初始值和最终值都是 2。我已经构建了一个正确添加代理的测试,所以我知道我并没有完全偏离轨道。(我还想有更简单的方法来计算“是”出现在表格中的次数。)

谢谢。

4

1 回答 1

0

答案:修复编辑操作的路由!现在测试通过了。

于 2013-03-14T01:25:26.990 回答