【发布时间】:2011-01-11 10:27:39
【问题描述】:
我是 PHPUnit 新手,在单元测试 HTML 输出时遇到了一些问题。
我的测试如下:
/**
* @covers Scrap::removeTags
*
*/
public function testRemoveTags() {
// Variables
$simple_parameter = 'script';
$array_parameter = array('script', 'div');
$html = '<div class="pubanunciomrec" style="background:#FFFFFF;"><script type="text/javascript"><!-- google_ad_slot = "9853257829"; google_ad_width = 300; google_ad_height = 250; //--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div><table></table>';
// Expected HTML
$expected_html_whitout_script = new DOMDocument;
$expected_html_whitout_script->loadHTML('<div class="pubanunciomrec" style="background:#FFFFFF;"></div><table></table>');
$expected_html_without_script_div = new DOMDocument;
$expected_html_without_script_div->loadHTML('<table></table>');
// Actual HTML
$actual_whitout_script = new DOMDocument;
$actual_whitout_script->loadHTML($this->scrap->removeTags($html, $simple_parameter));
$actual_without_script_div = new DOMDocument;
$actual_without_script_div->loadHTML($this->scrap->removeTags($html, $array_parameter));
// Test
$this->assertEquals($expected_html_whitout_script, $actual_whitout_script);
$this->assertEquals($expected_html_without_script_div, $actual_without_script_div);
}
我的问题是 DOMDocument 对象生成了一些 HTML 代码,我无法比较它。如何打印 DOMDocument 对象以查看输出?有关如何比较 HTML 的任何线索?
对不起,我的英语不好。
最好的问候,
【问题讨论】:
-
我需要一些关于单元测试的指导。请问您如何开始对 Web 应用程序进行单元测试。进行单元测试后会得到什么输出。
标签: html unit-testing phpunit