You are here

function ManageDisplayTest::assertNodeViewTextHelper in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/Tests/ManageDisplayTest.php \Drupal\field_ui\Tests\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

EntityInterface $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 core/modules/field_ui/src/Tests/ManageDisplayTest.php
Asserts that a string is not found in the rendered node in a view mode.
ManageDisplayTest::assertNodeViewText in core/modules/field_ui/src/Tests/ManageDisplayTest.php
Asserts that a string is found in the rendered node in a view mode.

File

core/modules/field_ui/src/Tests/ManageDisplayTest.php, line 466
Contains \Drupal\field_ui\Tests\ManageDisplayTest.

Class

ManageDisplayTest
Tests the Field UI "Manage display" and "Manage form display" screens.

Namespace

Drupal\field_ui\Tests

Code

function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $text, $message, $not_exists) {

  // Make sure caches on the tester side are refreshed after changes
  // submitted on the tested side.
  \Drupal::entityManager()
    ->clearCachedFieldDefinitions();

  // Save current content so that we can restore it when we're done.
  $old_content = $this
    ->getRawContent();

  // Render a cloned node, so that we do not alter the original.
  $clone = clone $node;
  $element = node_view($clone, $view_mode);
  $output = \Drupal::service('renderer')
    ->renderRoot($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
    ->setRawContent($output);
  $method = $not_exists ? 'assertNoText' : 'assertText';
  $return = $this
    ->{$method}((string) $text, $message);

  // Restore previous content.
  $this
    ->setRawContent($old_content);
  return $return;
}