public function SqlTest::testLoadEntitiesWithNonEntityRelationship in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testLoadEntitiesWithNonEntityRelationship()
@covers ::loadEntities @covers ::assignEntitiesToResult
File
- core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php, line 391
Class
- SqlTest
- @coversDefaultClass \Drupal\views\Plugin\views\query\Sql
Namespace
Drupal\Tests\views\Unit\Plugin\queryCode
public function testLoadEntitiesWithNonEntityRelationship() {
// We don't use prophecy, because prophecy enforces methods.
$view = $this
->getMockBuilder(ViewExecutable::class)
->disableOriginalConstructor()
->getMock();
$this
->setupViewWithRelationships($view, 'entity_first_field_data');
$view_entity = $this
->prophesize(ViewEntityInterface::class);
$view_entity
->get('base_table')
->willReturn('entity_first');
$view_entity
->get('base_field')
->willReturn('id');
$view->storage = $view_entity
->reveal();
$entities = [
'first' => [
1 => $this
->prophesize(EntityInterface::class)
->reveal(),
2 => $this
->prophesize(EntityInterface::class)
->reveal(),
],
];
$entity_type_manager = $this
->setupEntityTypes($entities);
$date_sql = $this
->prophesize(DateSqlInterface::class);
$messenger = $this
->prophesize(MessengerInterface::class);
$query = new Sql([], 'sql', [], $entity_type_manager
->reveal(), $date_sql
->reveal(), $messenger
->reveal());
$query->view = $view;
$result = [];
$result[] = new ResultRow([
'id' => 1,
]);
$result[] = new ResultRow([
'id' => 2,
]);
$query
->addField('entity_first', 'id', 'id');
$query
->loadEntities($result);
$entity_information = $query
->getEntityTableInfo();
$this
->assertSame($entities['first'][1], $result[0]->_entity);
$this
->assertSame($entities['first'][2], $result[1]->_entity);
$this
->assertEquals([], $result[0]->_relationship_entities);
$this
->assertEquals([], $result[1]->_relationship_entities);
// This is an entity table and should be in $entity_information.
$this
->assertContains('first', array_keys($entity_information));
// This is not an entity table and should not be in $entity_information.
$this
->assertNotContains('entity_first_field_data__entity_first_field_data', array_keys($entity_information));
}