public function RenderedEntityTest::testRenderedEntityWithField in Entity API 8.0
Tests the rendered entity output with the body field configured to show.
File
- src/
Tests/ Plugin/ views/ field/ RenderedEntityTest.php, line 155 - 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\fieldCode
public function testRenderedEntityWithField() {
\Drupal::currentUser()
->setAccount($this->user);
// Show the body on the node.x.foobar view mode.
EntityViewDisplay::load('entity_test.entity_test.foobar')
->setComponent('test_field', [
'type' => 'string',
'label' => 'above',
])
->save();
// The view should 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
->assertTrue($search_result, "The text 'Test {$i}' found in the view.");
}
$this
->assertConfigDependencies($view->storage);
$this
->assertCacheabilityMetadata($build);
}