public function EntityViewBuilderTest::testNoTemplate in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php \Drupal\KernelTests\Core\Entity\EntityViewBuilderTest::testNoTemplate()
Tests that viewing an entity without template does not specify #theme.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityViewBuilderTest.php, line 330
Class
- EntityViewBuilderTest
- Tests the entity view builder.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testNoTemplate() {
// Ensure that an entity type without explicit view builder uses the
// default.
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type = $entity_type_manager
->getDefinition('entity_test_base_field_display');
$this
->assertTrue($entity_type
->hasViewBuilderClass());
$this
->assertEquals(EntityViewBuilder::class, $entity_type
->getViewBuilderClass());
// Ensure that an entity without matching template does not have a #theme
// key.
$entity = $this
->createTestEntity('entity_test');
$build = $entity_type_manager
->getViewBuilder('entity_test')
->view($entity);
$this
->assertEquals($entity, $build['#entity_test']);
$this
->assertArrayNotHasKey('#theme', $build);
}