1 field_ui.test FieldUIManageDisplayTestCase::assertNodeViewTextHelper(Node $node, $view_mode, $text, $message, $not_exists)

Asserts that a string is (not) found in the rendered node in a display mode.

This helper function is used by assertNodeViewText() and assertNodeViewNoText().

Parameters

Node $node: The node.

$view_mode: The display 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.

Return value

TRUE on pass, FALSE on fail.:

File

core/modules/field_ui/tests/field_ui.test, line 752
Tests for field_ui.module.

Class

FieldUIManageDisplayTestCase
Tests the functionality of the 'Manage displays' screens.

Code

function assertNodeViewTextHelper(Node $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->backdropGetContent();

  // Render a cloned node, so that we do not alter the original.
  $clone = clone $node;
  $element = node_view($clone, $view_mode);
  $output = backdrop_render($element);
  $this->verbose(t('Rendered node - display mode: @view_mode', array('@view_mode' => $view_mode)) . '<hr />' . $output);

  // Assign content so that BackdropWebTestCase functions can be used.
  $this->backdropSetContent($output);
  $method = ($not_exists ? 'assertNoText' : 'assertText');
  $return = $this->{$method}((string) $text, $message);

  // Restore previous content.
  $this->backdropSetContent($old_content);

  return $return;
}