public function EntityViewsDataTest::testDataTable in Drupal 10
Tests data_table support.
File
- core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php, line 194
Class
- EntityViewsDataTest
- Tests entity views data.
Namespace
Drupal\Tests\views\Kernel\EntityCode
public function testDataTable() {
$entity_type = $this->baseEntityType
->set('data_table', 'entity_test_mul_property_data')
->set('id', 'entity_test_mul')
->set('translatable', TRUE)
->setKey('label', 'label');
$this
->setUpEntityType($entity_type);
// Tests the join definition between the base and the data table.
$data = $this->entityTypeManager
->getHandler('entity_test_mul', 'views_data')
->getViewsData();
// TODO: change the base table in the entity type definition to match the
// changed entity ID.
$base_views_data = $data['entity_test'];
// Ensure that the base table is set to the data table.
$this
->assertEquals('id', $data['entity_test_mul_property_data']['table']['base']['field']);
$this
->assertEquals('Entity test', $data['entity_test_mul_property_data']['table']['base']['title']);
$this
->assertFalse(isset($data['entity_test']['table']['base']));
$this
->assertEquals('entity_test_mul', $data['entity_test_mul_property_data']['table']['entity type']);
$this
->assertEquals(FALSE, $data['entity_test_mul_property_data']['table']['entity revision']);
$this
->assertEquals('Entity test', $data['entity_test_mul_property_data']['table']['group']);
$this
->assertEquals('entity_test', $data['entity_test']['table']['provider']);
$this
->assertEquals([
'field' => 'label',
'table' => 'entity_test_mul_property_data',
], $data['entity_test_mul_property_data']['table']['base']['defaults']);
// Ensure the join information is set up properly.
$this
->assertCount(1, $base_views_data['table']['join']);
$this
->assertEquals([
'entity_test_mul_property_data' => [
'left_field' => 'id',
'field' => 'id',
'type' => 'INNER',
],
], $base_views_data['table']['join']);
$this
->assertFalse(isset($data['revision_table']));
$this
->assertFalse(isset($data['revision_data_table']));
}