You are here

public function RenderedEntityTest::testRenderedEntityWithoutField in Entity API 8.0

Tests the default rendered entity output.

File

src/Tests/Plugin/views/field/RenderedEntityTest.php, line 125
Contains \Drupal\entity\Tests\Plugin\views\field\RenderedEntityTest.

Class

RenderedEntityTest
Tests the Drupal\entity\Plugin\views\field\RenderedEntity handler.

Namespace

Drupal\entity\Tests\Plugin\views\field

Code

public function testRenderedEntityWithoutField() {
  \Drupal::currentUser()
    ->setAccount($this->user);
  EntityViewDisplay::load('entity_test.entity_test.foobar')
    ->removeComponent('test_field')
    ->save();

  // The view should not display the body field.
  $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);
}