There seem to be multiple ways to select elements in the DOM:
- assertQuery - CSS selector
- assertXpath - Xpath selector
- strpos (!) - search through the html as a string
I first tried CSS selector:
All should work, but there are different problems. The two first selections don't work, event though they work in firebug. The last line doesnt work either because of the period '.' which gives a "DOMXPath::query(): Invalid predicate" error.
Seems Zend PHPUnit converts from CSS to Xpath selectors and doesnt manage to do it right.
Therefore using Xpath directly is better. (Download the FireXpath extension to Firebug for Firefox and play around to learn it (also http://www.w3schools.com/XPath/default.asp is good)). So here's Xpath:
Works out of the box.
Alternatively you can search through the html code linearly:
$this->assertTrue(strpos($this->_response->getBody(), 'email@example.com') !== false); //emailaddress
However, if anything changes in the html code, the test might fail.
Solution sources: http://framework.zend.com/manual/en/zend.test.phpunit.html, http://www.tig12.net/downloads/apidocs/zf/, others I cant remember.