public function EntityToTableRendererTest::testViewDisplays in Reference Table Formatter 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/EntityToTableRendererTest.php \Drupal\Tests\reference_table_formatter\Kernel\EntityToTableRendererTest::testViewDisplays()
Tests interactions with view modes and displays of referenced entities.
File
- tests/
src/ Kernel/ EntityToTableRendererTest.php, line 234
Class
- EntityToTableRendererTest
- Tests reference table formatter entity to table renderer.
Namespace
Drupal\Tests\reference_table_formatter\KernelCode
public function testViewDisplays() {
$this->displayRepository
->getViewDisplay('node', 't_shirt', 'default')
->setComponent('field_color')
->save();
$base_settings = [
'show_entity_label' => FALSE,
'empty_cell_value' => '',
'hide_header' => FALSE,
];
$table = $this->renderer
->executeInRenderContext(new RenderContext(), function () use ($base_settings) {
return $this->tableRenderer
->getTable('node', 't_shirt', $this->nodes, [
'view_mode' => 'does_not_exist',
] + $base_settings);
});
$this
->assertArrayHasKey('field_color', $table['#header'], 'Use default view mode as fallback.');
$this->displayRepository
->getViewDisplay('node', 't_shirt', 'default')
->delete();
// Check that no error is raised even if there is no default view mode.
$this->renderer
->executeInRenderContext(new RenderContext(), function () use ($base_settings) {
return $this->tableRenderer
->getTable('node', 't_shirt', $this->nodes, [
'view_mode' => 'does_not_exist',
] + $base_settings);
});
}