public function FieldRenderedEntityTest::testRenderedEntityWithField in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php \Drupal\Tests\views\Kernel\Handler\FieldRenderedEntityTest::testRenderedEntityWithField()
- 9 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 187
Class
- FieldRenderedEntityTest
- Tests the core Drupal\views\Plugin\views\field\RenderedEntity handler.
Namespace
Drupal\Tests\views\Kernel\HandlerCode
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);
}