You are here

public function ManageDisplayTest::assertNodeViewTextHelper in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertNodeViewTextHelper()

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

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

Parameters

\Drupal\Core\Entity\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.

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

File

core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php, line 273

Class

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

Namespace

Drupal\Tests\field_ui\Functional

Code

public 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::service('entity_field.manager')
    ->clearCachedFieldDefinitions();

  // Render a cloned node, so that we do not alter the original.
  $clone = clone $node;
  $element = \Drupal::entityTypeManager()
    ->getViewBuilder('node')
    ->view($clone, $view_mode);
  $output = (string) \Drupal::service('renderer')
    ->renderRoot($element);
  if ($not_exists) {
    $this
      ->assertStringNotContainsString((string) $text, $output, $message);
  }
  else {
    $this
      ->assertStringContainsString((string) $text, $output, $message);
  }
}