php – Symfony2功能测试 – 检查表内容
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Symfony2功能测试 – 检查表内容,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3076字,纯文字阅读大概需要5分钟。
内容图文
我在断言中只使用过contains()这样的东西,所以我不确定如何处理像这样复杂的东西.
假设我有一系列预期答案 – 在这种情况下,它是YES,YES,NO.
所以这意味着有效,对于我希望看到的第一个和第二个问题< span class =“glyphicon glyphicon-ok”>< / span>在第三个< td>内对于第三个问题,我希望在第四个< td>内看到它.
这是我的HTML代码:
<table class="table table-curved">
<tr>
<th width="10%">Item</th>
<th width="60%">Description</th>
<th width="10%">YES</th>
<th width="10%">NO</th>
<th width="10%">NOT APPLICABLE</th>
</tr>
<tr>
<td class="report-table-inner report-centre">1</td>
<td class="report-table-inner">Check cargo is secure and undamaged.</td>
<td class="report-centre success"><span class="glyphicon glyphicon-ok"></span></td>
<td class="report-centre"></td>
<td class="report-centre"></td>
</tr>
<tr>
<td class="report-table-inner report-centre">2</td>
<td class="report-table-inner">Is all cargo accounted for.</td>
<td class="report-centre success"><span class="glyphicon glyphicon-ok"></span></td>
<td class="report-centre"></td>
<td class="report-centre"></td>
</tr>
<tr>
<td class="report-table-inner report-centre">3</td>
<td class="report-table-inner">Is all cargo checked by customs.</td>
<td class="report-centre"></td>
<td class="report-centre danger"><span class="glyphicon glyphicon-ok"></span></td>
<td class="report-centre"></td>
</tr>
...
我该如何为此编写测试?以编程方式迭代< tr>是否很难?
谢谢
解决方法:
请注意,我根本不是Symfony,但这是一个使用纯PHP DOM的答案;它需要$values作为一个数组,带有’pass'(跳过这个< tr>)或者哪个列应该有glyphicon-ok类的索引:
<?php
$data = <<<DATA
<table class="table table-curved">
<tr>
<th width="10%">Item</th>
<th width="60%">Description</th>
<th width="10%">YES</th>
<th width="10%">NO</th>
<th width="10%">NOT APPLICABLE</th>
</tr>
<tr>
<td class="report-table-inner report-centre">1</td>
<td class="report-table-inner">Check cargo is secure and undamaged.</td>
<td class="report-centre success"><span class="glyphicon glyphicon-ok"></span></td>
<td class="report-centre"></td>
<td class="report-centre"></td>
</tr>
<tr>
<td class="report-table-inner report-centre">2</td>
<td class="report-table-inner">Is all cargo accounted for.</td>
<td class="report-centre success"><span class="glyphicon glyphicon-ok"></span></td>
<td class="report-centre"></td>
<td class="report-centre"></td>
</tr>
<tr>
<td class="report-table-inner report-centre">3</td>
<td class="report-table-inner">Is all cargo checked by customs.</td>
<td class="report-centre"></td>
<td class="report-centre danger"><span class="glyphicon glyphicon-ok"></span></td>
<td class="report-centre"></td>
</tr>
</table>
DATA;
$dom = new DOMDocument();
$dom->loadXML($data);
$xpath = new DOMXPath($dom);
$values = ['pass', 2, 2, 3];
$idx = 0;
foreach($xpath->query('//tr') as $tr) {
if ($values[$idx] != 'pass') {
$tds = $tr->getElementsByTagName('td');
$td = $tds->item($values[$idx]);
if ($td instanceof DOMNode && $td->hasChildNodes()) {
if (FALSE !== strpos($td->firstChild->getAttribute('class'), 'glyphicon-ok')) {
echo "Matched on ", $tds->item(1)->textContent, "\n";
} else {
echo "Not matched on ", $tds->item(1)->textContent, "\n";
}
}
}
++$idx;
}
内容总结
以上是互联网集市为您收集整理的php – Symfony2功能测试 – 检查表内容全部内容,希望文章能够帮你解决php – Symfony2功能测试 – 检查表内容所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。