function EntityViewsDataTest::setUpEntityType
Same name in other branches
- 10 core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php \Drupal\Tests\views\Kernel\Entity\EntityViewsDataTest::setUpEntityType()
- 11.x core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php \Drupal\Tests\views\Kernel\Entity\EntityViewsDataTest::setUpEntityType()
Mocks an entity type and its base fields.
This works by:
- inserting the entity type definition into the entity type manager's cache
- setting the base fields on the ViewsTestEntity class as a static property for its baseFieldsDefinitions() method to use.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $definition: An entity type definition to add to the entity type manager.
\Drupal\Core\Field\BaseFieldDefinition[] $base_fields: An array of base field definitions
7 calls to EntityViewsDataTest::setUpEntityType()
- EntityViewsDataTest::setUp in core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php - EntityViewsDataTest::testDataTable in core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php - Tests data_table support.
- EntityViewsDataTest::testDataTableFields in core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php - Tests fields on the data table.
- EntityViewsDataTest::testRevisionTableFields in core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php - Tests fields on the revision table.
- EntityViewsDataTest::testRevisionTableWithoutDataTable in core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php - Tests revision table without data table support.
File
-
core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php, line 150
Class
- EntityViewsDataTest
- Tests entity views data.
Namespace
Drupal\Tests\views\Kernel\EntityCode
protected function setUpEntityType(EntityTypeInterface $definition, array $base_fields = []) {
// Replace the cache backend in the entity type manager so it returns
// our test entity type in addition to the existing ones.
$definitions = $this->entityTypeManager
->getDefinitions();
$definitions[$definition->id()] = $definition;
$cache_backend = $this->prophesize(CacheBackendInterface::class);
$cache_data = new \StdClass();
$cache_data->data = $definitions;
$cache_backend->get('entity_type')
->willReturn($cache_data);
$this->entityTypeManager
->setCacheBackend($cache_backend->reveal(), 'entity_type', [
'entity_types',
]);
$this->entityTypeManager
->clearCachedDefinitions();
if ($base_fields) {
ViewsTestEntity::setMockedBaseFieldDefinitions($definition->id(), $base_fields);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.