You are here

public function FieldRenderedEntityTest::testRenderedEntityWithField in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php \Drupal\Tests\views\Kernel\Handler\FieldRenderedEntityTest::testRenderedEntityWithField()

Tests the rendered entity output with the test field configured to show.

File

core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php, line 182

Class

FieldRenderedEntityTest
Tests the core Drupal\views\Plugin\views\field\RenderedEntity handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testRenderedEntityWithField() {
  \Drupal::currentUser()
    ->setAccount($this->user);

  // Show the test_field on the entity_test.entity_test.foobar view display.
  EntityViewDisplay::load('entity_test.entity_test.foobar')
    ->setComponent('test_field', [
    'type' => 'string',
    'label' => 'above',
  ])
    ->save();
  $view = Views::getView('test_field_entity_test_rendered');
  $build = [
    '#type' => 'view',
    '#name' => 'test_field_entity_test_rendered',
    '#view' => $view,
    '#display_id' => 'default',
  ];
  $renderer = \Drupal::service('renderer');
  $renderer
    ->renderPlain($build);
  for ($i = 1; $i <= 3; $i++) {
    $view_field = $view->style_plugin
      ->getField($i - 1, 'rendered_entity');
    $search_result = strpos($view_field, "Test {$i}") !== FALSE;
    $this
      ->assertTrue($search_result, "The text 'Test {$i}' found in the view.");
  }
  $this
    ->assertConfigDependencies($view->storage);
  $this
    ->assertCacheabilityMetadata($build);
}