phpunit 与 Zend_Dom_Query
$domDoc = new DOMDocument();
$domDoc->loadHTML($docSrc);
$xpath = new DOMXPath($domDoc);
$nodeList = $xpath->query("//a[@class='active' and @href='/advanced-2-0.html']");
$this->assertTrue($nodeList->length == 1);
如果 $docSrc
是这样的,则此代码效果很好:
$docSrc = '<div><a class="active" href = "/advanced-2-0.html']"></div>';
但是当我像这样将 HTML 分配给 $docSrc
时:
$this->dispatch($_SERVER['REQUEST_URI']);
$html = $this->getResponse()->getBody();
它不起作用。我打印 $html
,里面一切正常;我无法解释它,因为在这两种情况下它都是一个字符串。
我收到错误:
AccountControllerTest::testIfAllow DOMDocument::loadHTML(): 实体中未定义命名空间前缀 fb,第 54 行
我也尝试过:
$domDoc->loadHTML("$this->getResponse()->getBody()");
没有出现错误,但结果为空。
$domDoc = new DOMDocument();
$domDoc->loadHTML($docSrc);
$xpath = new DOMXPath($domDoc);
$nodeList = $xpath->query("//a[@class='active' and @href='/advanced-2-0.html']");
$this->assertTrue($nodeList->length == 1);
This code works great if $docSrc
is something like this:
$docSrc = '<div><a class="active" href = "/advanced-2-0.html']"></div>';
but when I assign HTML to $docSrc
like this:
$this->dispatch($_SERVER['REQUEST_URI']);
$html = $this->getResponse()->getBody();
it doesn't work. I print $html
and everything is ok inside; I can't explain it because in both cases it's a string.
I get the error:
AccountControllerTest::testIfAllow
DOMDocument::loadHTML(): Namespace prefix fb is not defined in Entity, line: 54
I also tried:
$domDoc->loadHTML("$this->getResponse()->getBody()");
Errors don't appear, but the result is empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在输出中使用 FBML,例如
用于“Like”按钮。您可以将输出包装在声明命名空间的元素中。
更新:现在我正在查看我们的代码,我们还必须切换到
loadXML()
而不是loadHTML()
并设置 libxml 的 <代码>恢复标志:You must be using FBML in your output, e.g.
<fb:like ...>
for a Like button. You can possibly wrap the output in an<html>
element that declares the namespace.Update: Now that I am looking at our code, we also had to switch to
loadXML()
instead ofloadHTML()
and set libxml'srecover
flag: