Asserts that a string is (not) found in the rendered nodein a view mode.
This helper function is used by assertNodeViewText() and assertNodeViewNoText().
$node: The node.
$view_mode: The view mode in which the node should be displayed.
$text: Plain text to look for.
$message: Message to display.
$not_exists: TRUE if this text should not exist, FALSE if it should.
TRUE on pass, FALSE on fail.
function assertNodeViewTextHelper($node, $view_mode, $text, $message, $not_exists) {
// Make sure caches on the tester side are refreshed after changes
// submitted on the tested side.
field_info_cache_clear();
// Save current content so that we can restore it when we're done.
$old_content = $this
->drupalGetContent();
// Render a cloned node, so that we do not alter the original.
$clone = clone $node;
$element = node_view($clone, $view_mode);
$output = drupal_render($element);
$this
->verbose(t('Rendered node - view mode: @view_mode', array(
'@view_mode' => $view_mode,
)) . '<hr />' . $output);
// Assign content so that DrupalWebTestCase functions can be used.
$this
->drupalSetContent($output);
$method = $not_exists ? 'assertNoText' : 'assertText';
$return = $this
->{$method}((string) $text, $message);
// Restore previous content.
$this
->drupalSetContent($old_content);
return $return;
}