You are here

public function FieldRenderedEntityTest::testRenderedEntityWithoutField 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::testRenderedEntityWithoutField()

Tests the default rendered entity output.

File

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

Class

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

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testRenderedEntityWithoutField() {
  \Drupal::currentUser()
    ->setAccount($this->user);
  EntityViewDisplay::load('entity_test.entity_test.foobar')
    ->removeComponent('test_field')
    ->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
      ->assertFalse($search_result, "The text 'Test {$i}' not found in the view.");
  }
  $this
    ->assertConfigDependencies($view->storage);
  $this
    ->assertCacheabilityMetadata($build);
}