function SqlTest::setupEntityTypes
Same name in other branches
- 8.9.x core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::setupEntityTypes()
- 10 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::setupEntityTypes()
- 11.x core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::setupEntityTypes()
Sets up some test entity types and corresponding views data.
Parameters
\Drupal\Core\Entity\EntityInterface[][] $entities_by_type: Test entities keyed by entity type and entity ID.
\Drupal\Core\Entity\EntityInterface[][] $entity_revisions_by_type: Test entities keyed by entity type and revision ID.
Return value
\Prophecy\Prophecy\ObjectProphecy
7 calls to SqlTest::setupEntityTypes()
- SqlTest::testLoadEntitiesWithEmptyResult in core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php - @covers ::loadEntities @covers ::assignEntitiesToResult
- SqlTest::testLoadEntitiesWithNonEntityRelationship in core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php - @covers ::loadEntities @covers ::assignEntitiesToResult
- SqlTest::testLoadEntitiesWithNoRelationshipAndNoRevision in core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php - @covers ::loadEntities @covers ::assignEntitiesToResult
- SqlTest::testLoadEntitiesWithRelationship in core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php - @covers ::loadEntities @covers ::assignEntitiesToResult
- SqlTest::testLoadEntitiesWithRelationshipAndRevision in core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php - @covers ::loadEntities @covers ::assignEntitiesToResult
File
-
core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php, line 152
Class
- SqlTest
- @coversDefaultClass \Drupal\views\Plugin\views\query\Sql
Namespace
Drupal\Tests\views\Unit\Plugin\queryCode
protected function setupEntityTypes($entities_by_type = [], $entity_revisions_by_type = []) {
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
$entity_type0 = new EntityType([
'label' => 'First',
'id' => 'first',
'base_table' => 'entity_first',
'revision_table' => 'entity_first__revision',
'entity_keys' => [
'id' => 'id',
'revision' => 'vid',
],
]);
$entity_type1 = new EntityType([
'label' => 'second',
'id' => 'second',
'base_table' => 'entity_second',
'revision_table' => 'entity_second__revision',
'entity_keys' => [
'id' => 'id',
'revision' => 'vid',
],
]);
$entity_type_manager->getDefinitions()
->willReturn([
'first' => $entity_type0,
'second' => $entity_type1,
'base_table' => 'entity_second',
]);
$entity_type_manager->getDefinition('first')
->willReturn($entity_type0);
$entity_type_manager->getDefinition('second')
->willReturn($entity_type1);
// Setup the views data corresponding to the entity types.
$views_data = $this->prophesize(ViewsData::class);
$views_data->get('entity_first')
->willReturn([
'table' => [
'entity type' => 'first',
'entity revision' => FALSE,
],
]);
$views_data->get('entity_first__revision')
->willReturn([
'table' => [
'entity type' => 'first',
'entity revision' => TRUE,
],
]);
$views_data->get('entity_second')
->willReturn([
'table' => [
'entity type' => 'second',
'entity revision' => FALSE,
],
]);
$views_data->get('entity_second__revision')
->willReturn([
'table' => [
'entity type' => 'second',
'entity revision' => TRUE,
],
]);
$views_data->get('entity_first_field_data')
->willReturn([
'table' => [
'entity type' => 'first',
'entity revision' => FALSE,
],
]);
$this->setupViewsData($views_data->reveal());
// Setup the loading of entities and entity revisions.
$entity_storages = [
'first' => $this->prophesize(EntityStorageInterface::class),
'second' => $this->prophesize(EntityStorageInterface::class),
];
foreach ($entities_by_type as $entity_type_id => $entities) {
foreach ($entities as $entity_id => $entity) {
$entity_storages[$entity_type_id]->load($entity_id)
->willReturn($entity);
}
$entity_storages[$entity_type_id]->loadMultiple(array_keys($entities))
->willReturn($entities);
}
foreach ($entity_revisions_by_type as $entity_type_id => $entity_revisions) {
foreach ($entity_revisions as $revision_id => $revision) {
$entity_storages[$entity_type_id]->loadRevision($revision_id)
->willReturn($revision);
}
}
$entity_type_manager->getStorage('first')
->willReturn($entity_storages['first']);
$entity_type_manager->getStorage('second')
->willReturn($entity_storages['second']);
$this->setupEntityTypeManager($entity_type_manager->reveal());
return $entity_type_manager;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.