public function EntityViewsDataTest::testDataTableFields in Drupal 10
Tests fields on the data table.
File
- core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php, line 433
Class
- EntityViewsDataTest
- Tests entity views data.
Namespace
Drupal\Tests\views\Kernel\EntityCode
public function testDataTableFields() {
$entity_test_type = new ConfigEntityType([
'class' => ConfigEntityBase::class,
'id' => 'entity_test_bundle',
'entity_keys' => [
'id' => 'type',
'label' => 'name',
],
]);
$this
->setUpEntityType($entity_test_type);
$entity_type = $this->baseEntityType
->set('data_table', 'entity_test_mul_property_data')
->set('base_table', 'entity_test_mul')
->set('translatable', TRUE)
->set('id', 'entity_test_mul')
->set('bundle_entity_type', 'entity_test_bundle')
->setKey('bundle', 'type');
$base_field_definitions = $this->commonBaseFields;
$base_field_definitions['type'] = BaseFieldDefinition::create('entity_reference')
->setLabel('entity test type')
->setSetting('target_type', 'entity_test_bundle');
$this
->setUpEntityType($entity_type, $base_field_definitions);
$data = $this->entityTypeManager
->getHandler('entity_test_mul', 'views_data')
->getViewsData();
// Check the base fields.
$this
->assertFalse(isset($data['entity_test_mul']['id']));
$this
->assertFalse(isset($data['entity_test_mul']['type']));
$this
->assertUuidField($data['entity_test_mul']['uuid']);
$this
->assertViewsDataField($data['entity_test_mul']['uuid'], 'uuid');
$this
->assertFalse(isset($data['entity_test_mul']['type']['relationship']));
// Also ensure that field_data only fields don't appear on the base table.
$this
->assertFalse(isset($data['entity_test_mul']['name']));
$this
->assertFalse(isset($data['entity_test_mul']['description']));
$this
->assertFalse(isset($data['entity_test_mul']['description__value']));
$this
->assertFalse(isset($data['entity_test_mul']['description__format']));
$this
->assertFalse(isset($data['entity_test_mul']['user_id']));
$this
->assertFalse(isset($data['entity_test_mul']['homepage']));
// Check the data fields.
$this
->assertNumericField($data['entity_test_mul_property_data']['id']);
$this
->assertViewsDataField($data['entity_test_mul_property_data']['id'], 'id');
$this
->assertBundleField($data['entity_test_mul_property_data']['type']);
$this
->assertViewsDataField($data['entity_test_mul_property_data']['type'], 'type');
$this
->assertLanguageField($data['entity_test_mul_property_data']['langcode']);
$this
->assertViewsDataField($data['entity_test_mul_property_data']['langcode'], 'langcode');
$this
->assertEquals('Translation language', $data['entity_test_mul_property_data']['langcode']['title']);
$this
->assertStringField($data['entity_test_mul_property_data']['name']);
$this
->assertViewsDataField($data['entity_test_mul_property_data']['name'], 'name');
$this
->assertLongTextField($data['entity_test_mul_property_data'], 'description');
$this
->assertViewsDataField($data['entity_test_mul_property_data']['description__value'], 'description');
$this
->assertViewsDataField($data['entity_test_mul_property_data']['description__format'], 'description');
$this
->assertUriField($data['entity_test_mul_property_data']['homepage']);
$this
->assertViewsDataField($data['entity_test_mul_property_data']['homepage'], 'homepage');
$this
->assertEntityReferenceField($data['entity_test_mul_property_data']['user_id']);
$this
->assertViewsDataField($data['entity_test_mul_property_data']['user_id'], 'user_id');
$relationship = $data['entity_test_mul_property_data']['user_id']['relationship'];
$this
->assertEquals('users_field_data', $relationship['base']);
$this
->assertEquals('uid', $relationship['base field']);
$this
->assertStringField($data['entity_test_mul__string']['string_value']);
$this
->assertViewsDataField($data['entity_test_mul__string']['string_value'], 'string');
$this
->assertEquals([
'left_field' => 'id',
'field' => 'entity_id',
'extra' => [
[
'field' => 'deleted',
'value' => 0,
'numeric' => TRUE,
],
],
], $data['entity_test_mul__string']['table']['join']['entity_test_mul_property_data']);
}