phpUnit - assertQuery fails with
I am having trouble with an assertQuery(). In the html I have (verified by outputting the body)
<input type="text" name="L开发者_StackOverflowASTNAME" id="LASTNAME" value="" maxlength="25" size="20" />
So I wrote a query for it to test to make sure this element exists and that the value is empty
$this->assertQuery('input#LASTNAME[value=""]', 1);
PhpUnit says the assertion fails
Failed asserting node DENOTED BY input#LASTNAME[value=""] EXISTS
Can you give me some insight into why this assertion fails and how to write it properly?
Thanks in advance!
Zend Framework's code that converts the CSS selector to an XPath query is broken. It doesn't add the required @ before the attribute name. Use this, albeit incorrect CSS, assertion:
$this->assertQuery('input#LASTNAME[@value=""]', 1);
See this forum thread for details.
Update: The issue was reported and fixed in release 1.10, so you could upgrade your Zend Framework as an alternative to using an invalid CSS selector.
Alternatively, you could use XPath instead of CSS selectors, and thus skip the CSS to XPath conversion performed by Zend_Dom_Query:
$this->assertXpath( '//input[@id="LASTNAME"][@value=""]' );
加载中,请稍侯......
精彩评论