【问题标题】:phpUnit - assertQuery fails withphpUnit - assertQuery 失败
【发布时间】:2011-07-06 04:13:28
【问题描述】:

我在使用 assertQuery() 时遇到问题。在我拥有的 html 中(通过输出正文进行验证)

<input type="text" name="LASTNAME" id="LASTNAME" value="" maxlength="25" size="20" />

所以我写了一个查询来测试它以确保这个元素存在并且值为空

    $this->assertQuery('input#LASTNAME[value=""]', 1);

PhpUnit 说断言失败

断言节点失败 输入#LASTNAME[value=""] 存在

你能告诉我为什么这个断言失败以及如何正确编写它吗?

提前致谢!

【问题讨论】:

    标签: php zend-framework testing phpunit assert


    【解决方案1】:

    将 CSS 选择器转换为 XPath 查询的 Zend Framework 代码已损坏。它不会在属性名称之前添加所需的@。使用这个,尽管 CSS 不正确,断言:

    $this->assertQuery('input#LASTNAME[@value=""]', 1);
    

    详情请见this forum thread

    更新:issue was reportedfixed in release 1.10,因此您可以升级 Zend 框架以替代使用无效的 CSS 选择器。

    【讨论】:

    • 非常好的和完整的答案:)
    【解决方案2】:

    或者,您可以使用XPath 代替CSS 选择器,从而跳过Zend_Dom_Query 执行的CSSXPath 转换:

    $this->assertXpath( '//input[@id="LASTNAME"][@value=""]' );
    

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 2017-01-10
      • 2013-07-28
      • 2017-03-01
      • 2017-06-24
      • 2014-02-24
      • 2014-08-28
      • 1970-01-01
      • 2015-02-01
      相关资源
      最近更新 更多