function ManageDisplayTest::assertNodeViewTextHelper

Asserts that a string is (not) found in the rendered nodein a view mode.

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

Parameters

Node $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.

Return value

TRUE on pass, FALSE on fail.

2 calls to ManageDisplayTest::assertNodeViewTextHelper()
ManageDisplayTest::assertNodeViewNoText in drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
Asserts that a string is not found in the rendered node in a view mode.
ManageDisplayTest::assertNodeViewText in drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
Asserts that a string is found in the rendered node in a view mode.

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php, line 273
Definition of Drupal\field_ui\Tests\ManageDisplayTest.

Class

ManageDisplayTest
Tests the functionality of the 'Manage display' screens.

Namespace

Drupal\field_ui\Tests

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
    ->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 WebTestBase 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;
}