summaryrefslogtreecommitdiff
path: root/modules/simpletest/drupal_web_test_case.php
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-17 23:26:33 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-17 23:26:33 +0000
commitee2e63d7f9064ae57b3fb91007c53ceddf31ae48 (patch)
tree9536e30197339acf0902133e2096ee205f6b7b1a /modules/simpletest/drupal_web_test_case.php
parent16dcae23519b3ad5a1b6c287f69d2f049b2f8841 (diff)
downloadbrdo-ee2e63d7f9064ae57b3fb91007c53ceddf31ae48.tar.gz
brdo-ee2e63d7f9064ae57b3fb91007c53ceddf31ae48.tar.bz2
#402804 by roychri and Damien Tournoud: Add assertions to check if text was found only once or more than once.
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r--modules/simpletest/drupal_web_test_case.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 11212e760..b865d8659 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1705,6 +1705,78 @@ class DrupalWebTestCase {
}
/**
+ * Pass if the text is found ONLY ONCE on the text version of the page.
+ *
+ * The text version is the equivalent of what a user would see when viewing
+ * through a web browser. In other words the HTML has been filtered out of
+ * the contents.
+ *
+ * @param $text
+ * Plain text to look for.
+ * @param $message
+ * Message to display.
+ * @param $group
+ * The group this message belongs to, defaults to 'Other'.
+ * @return
+ * TRUE on pass, FALSE on fail.
+ */
+ protected function assertUniqueText($text, $message = '', $group = 'Other') {
+ return $this->assertUniqueTextHelper($text, $message, $group, TRUE);
+ }
+
+ /**
+ * Pass if the text is found MORE THAN ONCE on the text version of the page.
+ *
+ * The text version is the equivalent of what a user would see when viewing
+ * through a web browser. In other words the HTML has been filtered out of
+ * the contents.
+ *
+ * @param $text
+ * Plain text to look for.
+ * @param $message
+ * Message to display.
+ * @param $group
+ * The group this message belongs to, defaults to 'Other'.
+ * @return
+ * TRUE on pass, FALSE on fail.
+ */
+ protected function assertNoUniqueText($text, $message = '', $group = 'Other') {
+ return $this->assertUniqueTextHelper($text, $message, $group, FALSE);
+ }
+
+ /**
+ * Helper for assertUniqueText and assertNoUniqueText.
+ *
+ * It is not recommended to call this function directly.
+ *
+ * @param $text
+ * Plain text to look for.
+ * @param $message
+ * Message to display.
+ * @param $group
+ * The group this message belongs to.
+ * @param $be_unique
+ * TRUE if this text should be found only once, FALSE if it should be found more than once.
+ * @return
+ * TRUE on pass, FALSE on fail.
+ */
+ protected function assertUniqueTextHelper($text, $message, $group, $be_unique) {
+ if ($this->plainTextContent === FALSE) {
+ $this->plainTextContent = filter_xss($this->content, array());
+ }
+ if (!$message) {
+ $message = '"' . $text . '"'. ($be_unique ? ' found only once' : ' found more than once');
+ }
+ $first_occurance = strpos($this->plainTextContent, $text);
+ if ($first_occurance === FALSE) {
+ return $this->assert(FALSE, $message, $group);
+ }
+ $offset = $first_occurance + strlen($text);
+ $second_occurance = strpos($this->plainTextContent, $text, $offset);
+ return $this->assert($be_unique == ($second_occurance === FALSE), $message, $group);
+ }
+
+ /**
* Will trigger a pass if the Perl regex pattern is found in the raw content.
*
* @param $pattern