Commit 9532b4b8 authored by catch's avatar catch

Issue #1706878 by tim.plunkett: Add WebTestBase::assertThemeOutput() to allow...

Issue #1706878 by tim.plunkett: Add WebTestBase::assertThemeOutput() to allow modules to test theme function output.
parent 00fbe484
......@@ -2290,6 +2290,32 @@ 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) An assertion message.
*/
protected function assertThemeOutput($callback, array $variables = array(), $expected, $message = '') {
$output = theme($callback, $variables);
$this->verbose('Variables:' . '<pre>' . check_plain(var_export($variables, TRUE)) . '</pre>'
. '<hr />' . 'Result:' . '<pre>' . check_plain(var_export($output, TRUE)) . '</pre>'
. '<hr />' . 'Expected:' . '<pre>' . check_plain(var_export($expected, TRUE)) . '</pre>'
. '<hr />' . $output
);
if (!$message) {
$message = '%callback rendered correctly.';
}
$message = format_string($message, array('%callback' => 'theme_' . $callback . '()'));
$this->assertIdentical($output, $expected, $message);
}
/**
* Asserts that a field exists in the current page by the given XPath.
*
......
......@@ -143,32 +143,6 @@ function testLinks() {
$this->assertThemeOutput('links', $variables, $expected);
}
/**
* 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) An assertion message.
*/
protected function assertThemeOutput($callback, array $variables = array(), $expected, $message = '') {
$output = theme($callback, $variables);
$this->verbose('Variables:' . '<pre>' . check_plain(var_export($variables, TRUE)) . '</pre>'
. '<hr />' . 'Result:' . '<pre>' . check_plain(var_export($output, TRUE)) . '</pre>'
. '<hr />' . 'Expected:' . '<pre>' . check_plain(var_export($expected, TRUE)) . '</pre>'
. '<hr />' . $output
);
if (!$message) {
$message = '%callback rendered correctly.';
}
$message = t($message, array('%callback' => 'theme_' . $callback . '()'));
$this->assertIdentical($output, $expected, $message);
}
/**
* Test the use of drupal_pre_render_links() on a nested array of links.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment