diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6b6f5e03ee8a4cc19ee7cc38386cc2b11ca20df8..5c7c8b274cdbde33dc5f08a613dca77f1284f215 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,8 @@ Drupal 7.18, xxxx-xx-xx (development version) ----------------------- +- Added an assertThemeOutput() method to Simpletest to allow tests to check + that themed output matches an expected HTML string (API addition). - Added a link to "Install another module" after a module has been successfully downloaded via the Update Manager (UI change). - Added an optional "exclusive" flag to installation profile .info files which diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index e3cab62a276609d15fe3ca987ecf466e46680ce9..694880b9184a616895587549f634583253db321c 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -3148,6 +3148,42 @@ protected function assertNoTitle($title, $message = '', $group = 'Other') { return $this->assertNotEqual($actual, $title, $message, $group); } + /** + * Asserts themed output. + * + * @param $callback + * The name of the theme function to invoke; e.g. 'links' for theme_links(). + * @param $variables + * An array of variables to pass to the theme function. + * @param $expected + * The expected themed output string. + * @param $message + * (optional) A message to display with the assertion. Do not translate + * messages: use format_string() to embed variables in the message text, not + * t(). If left blank, a default message will be displayed. + * @param $group + * (optional) The group this message is in, which is displayed in a column + * in test output. Use 'Debug' to indicate this is debugging output. Do not + * translate this string. Defaults to 'Other'; most tests do not override + * this default. + * + * @return + * TRUE on pass, FALSE on fail. + */ + protected function assertThemeOutput($callback, array $variables = array(), $expected, $message = '', $group = 'Other') { + $output = theme($callback, $variables); + $this->verbose('Variables:' . '
' .  check_plain(var_export($variables, TRUE)) . '
' + . '
' . 'Result:' . '
' .  check_plain(var_export($output, TRUE)) . '
' + . '
' . 'Expected:' . '
' .  check_plain(var_export($expected, TRUE)) . '
' + . '
' . $output + ); + if (!$message) { + $message = '%callback rendered correctly.'; + } + $message = format_string($message, array('%callback' => 'theme_' . $callback . '()')); + return $this->assertIdentical($output, $expected, $message, $group); + } + /** * Asserts that a field exists in the current page by the given XPath. *