Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.10 diff -u -r1.10 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 28 May 2008 13:11:11 -0000 1.10 +++ modules/simpletest/drupal_web_test_case.php 2 Jun 2008 04:32:32 -0000 @@ -1105,4 +1105,78 @@ $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code; return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser')); } + + /** + * Assert that the message was found. Compares plain text, after stripping + * tags. + * + * @param string $dmessage Drupal message to look for. + * @param string $message Message to display. + * @return boolean Assertion result. + */ + function assertDrupalMessage($dmessage, $message = '') { + if ($this->parse()) { + $found = FALSE; + $errors = $this->elements->xpath("//div[@class='messages status'] | //div[@class='messages status']"); + $dmessage = trim(strip_tags($dmessage)); // Remove all tags for text comparison. + + if (!empty($errors)) { + $errors = $errors[0]; + + // If ul is present then multiple messages displayed. + if (isset($errors->ul)) { + foreach ($errors->ul->li as $li) { + if ($this->asText($li) == $dmessage) { + $found = TRUE; + break; + } + } + } + else if ($this->asText($errors) == $dmessage) { + $found = TRUE; + } + } + if (!$message) { + $message = t('"@message" found.', array('@message' => $dmessage)); + } + return $this->assertTrue($found, $message, t('Messages')); + } + return FALSE; + } + + /** + * Assert that no errors were found. + * + * @return boolean Assertion result. + */ + function assertNoDrupalErrors() { + if ($this->parse()) { + $errors = $this->elements->xpath("//div[@class='messages error']"); + return $this->assertTrue(empty($errors), t('No errors found.')); + } + return FALSE; + } + + /** + * Assert that no message were found. + * + * @return boolean Assertion result. + */ + function assertNoDrupalMessages() { + if ($this->parse()) { + $errors = $this->elements->xpath("//div[@class='messages status']"); + return $this->assertTrue(empty($errors), t('No messages found.')); + } + return FALSE; + } + + /** + * Extract the text contained by an element. + * + * @param SimpleXMLElement $element Element to extract text from. + * @return string Extracted text. + */ + function asText(SimpleXMLElement $element) { + return trim(strip_tags($element->asXML())); + } } Index: modules/simpletest/simpletest.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.test,v retrieving revision 1.1 diff -u -r1.1 simpletest.test --- modules/simpletest/simpletest.test 28 May 2008 14:07:46 -0000 1.1 +++ modules/simpletest/simpletest.test 2 Jun 2008 04:32:32 -0000 @@ -148,16 +148,6 @@ } /** - * Extract the text contained by the element. - * - * @param SimpleXMLElement $element Element to extract text from. - * @return string Extracted text. - */ - function asText(SimpleXMLElement $element) { - return strip_tags($element->asXML()); - } - - /** * Check if the test is being run from inside a CURL request. * * @return The test is being run from inside a CURL request.