You are here

class EntityViewsDataTest in Drupal 10

Tests entity views data.

@coversDefaultClass \Drupal\views\EntityViewsData @group views

Hierarchy

Expanded class hierarchy of EntityViewsDataTest

File

core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php, line 21

Namespace

Drupal\Tests\views\Kernel\Entity
View source
class EntityViewsDataTest extends KernelTestBase {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The base entity type definition, which some tests modify.
   *
   * Uses a custom class which allows changing entity keys.
   *
   * @var \Drupal\Tests\views\Kernel\Entity\TestEntityType
   */
  protected $baseEntityType;

  /**
   * The common base fields for test entity types.
   *
   * @var \Drupal\Core\Field\BaseFieldDefinition[]
   */
  protected $commonBaseFields;

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'user',
    'system',
    'field',
    'text',
    'filter',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->entityTypeManager = $this->container
      ->get('entity_type.manager');

    // A common entity type definition. Tests may change this prior to passing
    // it to setUpEntityType().
    $this->baseEntityType = new TestEntityType([
      // A normal entity type would have its class picked up during discovery,
      // but as we're mocking this without an annotation we have to specify it.
      'class' => ViewsTestEntity::class,
      'base_table' => 'entity_test',
      'id' => 'entity_test',
      'label' => 'Entity test',
      'entity_keys' => [
        'uuid' => 'uuid',
        'id' => 'id',
        'langcode' => 'langcode',
        'bundle' => 'type',
        'revision' => 'revision_id',
      ],
      'handlers' => [
        'views_data' => EntityViewsData::class,
      ],
      'provider' => 'entity_test',
      'list_cache_contexts' => [
        'entity_test_list_cache_context',
      ],
    ]);

    // Base fields for the test entity types.
    $this->commonBaseFields['name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setDescription(t('The name of the test entity.'))
      ->setTranslatable(TRUE)
      ->setSetting('max_length', 32);
    $this->commonBaseFields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Authored on'))
      ->setDescription(t('Time the entity was created'))
      ->setTranslatable(TRUE);
    $this->commonBaseFields['user_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('User ID'))
      ->setDescription(t('The ID of the associated user.'))
      ->setSetting('target_type', 'user')
      ->setSetting('handler', 'default')
      ->setDefaultValue([
      0 => [
        'target_id' => 1,
      ],
    ])
      ->setTranslatable(TRUE);

    // Add a description field. This example comes from the taxonomy Term
    // entity.
    $this->commonBaseFields['description'] = BaseFieldDefinition::create('text_long')
      ->setLabel('Description')
      ->setDescription('A description of the term.')
      ->setTranslatable(TRUE);

    // Add a URL field; this example is from the Comment entity.
    $this->commonBaseFields['homepage'] = BaseFieldDefinition::create('uri')
      ->setLabel('Homepage')
      ->setDescription("The comment author's home page address.")
      ->setTranslatable(TRUE)
      ->setSetting('max_length', 255);

    // A base field with cardinality > 1
    $this->commonBaseFields['string'] = BaseFieldDefinition::create('string')
      ->setLabel('Strong')
      ->setTranslatable(TRUE)
      ->setCardinality(2);

    // Set up the basic 'entity_test' entity type. This is used by several
    // tests; others customize it and the base fields.
    $this
      ->setUpEntityType($this->baseEntityType, $this->commonBaseFields);
  }

  /**
   * 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.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $definition
   *   An entity type definition to add to the entity type manager.
   * @param \Drupal\Core\Field\BaseFieldDefinition[] $base_fields
   *   An array of base field definitions
   */
  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);
    }
  }

  /**
   * Tests base tables.
   */
  public function testBaseTables() {
    $data = $this->entityTypeManager
      ->getHandler('entity_test', 'views_data')
      ->getViewsData();
    $this
      ->assertEquals('entity_test', $data['entity_test']['table']['entity type']);
    $this
      ->assertEquals(FALSE, $data['entity_test']['table']['entity revision']);
    $this
      ->assertEquals('Entity test', $data['entity_test']['table']['group']);
    $this
      ->assertEquals('entity_test', $data['entity_test']['table']['provider']);
    $this
      ->assertEquals('id', $data['entity_test']['table']['base']['field']);
    $this
      ->assertEquals([
      'entity_test_list_cache_context',
    ], $data['entity_test']['table']['base']['cache_contexts']);
    $this
      ->assertEquals('Entity test', $data['entity_test']['table']['base']['title']);

    // TODO: change these to assertArrayNotHasKey().
    $this
      ->assertFalse(isset($data['entity_test']['table']['defaults']));
    $this
      ->assertFalse(isset($data['entity_test_mul_property_data']));
    $this
      ->assertFalse(isset($data['revision_table']));
    $this
      ->assertFalse(isset($data['revision_data_table']));
  }

  /**
   * Tests data_table support.
   */
  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']));
  }

  /**
   * Tests revision table without data table support.
   */
  public function testRevisionTableWithoutDataTable() {
    $entity_type = $this->baseEntityType
      ->set('revision_table', 'entity_test_mulrev_revision')
      ->set('revision_data_table', NULL)
      ->set('id', 'entity_test_mulrev')
      ->setKey('revision', 'revision_id');
    $this
      ->setUpEntityType($entity_type);
    $data = $this->entityTypeManager
      ->getHandler('entity_test_mulrev', 'views_data')
      ->getViewsData();
    $this
      ->assertEquals('Entity test revisions', $data['entity_test_mulrev_revision']['table']['base']['title']);
    $this
      ->assertEquals('revision_id', $data['entity_test_mulrev_revision']['table']['base']['field']);
    $this
      ->assertEquals(FALSE, $data['entity_test']['table']['entity revision']);
    $this
      ->assertEquals('entity_test_mulrev', $data['entity_test_mulrev_revision']['table']['entity type']);
    $this
      ->assertEquals(TRUE, $data['entity_test_mulrev_revision']['table']['entity revision']);
    $this
      ->assertEquals('entity_test_mulrev', $data['entity_test_mulrev_revision']['table']['entity type']);
    $this
      ->assertEquals(TRUE, $data['entity_test_mulrev_revision']['table']['entity revision']);
    $this
      ->assertEquals('Entity test revision', $data['entity_test_mulrev_revision']['table']['group']);
    $this
      ->assertEquals('entity_test', $data['entity_test']['table']['provider']);

    // Ensure the join information is set up properly.
    // Tests the join definition between the base and the revision table.
    $revision_data = $data['entity_test_mulrev_revision'];
    $this
      ->assertCount(1, $revision_data['table']['join']);
    $this
      ->assertEquals([
      'entity_test' => [
        'left_field' => 'revision_id',
        'field' => 'revision_id',
        'type' => 'INNER',
      ],
    ], $revision_data['table']['join']);
    $this
      ->assertFalse(isset($data['data_table']));
    $this
      ->assertEquals('entity_test', $revision_data['id']['relationship']['base']);
    $this
      ->assertEquals('id', $revision_data['id']['relationship']['base field']);
    $this
      ->assertEquals('entity_test', $revision_data['revision_id']['relationship']['base']);
    $this
      ->assertEquals('revision_id', $revision_data['revision_id']['relationship']['base field']);
  }

  /**
   * Tests revision table with data table support.
   */
  public function testRevisionTableWithRevisionDataTableAndDataTable() {
    $entity_type = $this->baseEntityType
      ->set('data_table', 'entity_test_mul_property_data')
      ->set('revision_table', 'entity_test_mulrev_revision')
      ->set('revision_data_table', 'entity_test_mulrev_property_revision')
      ->set('id', 'entity_test_mulrev')
      ->set('translatable', TRUE)
      ->setKey('revision', 'revision_id');
    $this
      ->setUpEntityType($entity_type);
    $data = $this->entityTypeManager
      ->getHandler('entity_test_mulrev', 'views_data')
      ->getViewsData();
    $this
      ->assertEquals('Entity test revisions', $data['entity_test_mulrev_property_revision']['table']['base']['title']);
    $this
      ->assertEquals('revision_id', $data['entity_test_mulrev_property_revision']['table']['base']['field']);
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['table']['base']));
    $this
      ->assertEquals('entity_test_mulrev', $data['entity_test_mulrev_property_revision']['table']['entity type']);
    $this
      ->assertEquals('Entity test revision', $data['entity_test_mulrev_revision']['table']['group']);
    $this
      ->assertEquals('entity_test', $data['entity_test']['table']['provider']);

    // Ensure the join information is set up properly.
    // Tests the join definition between the base and the revision table.
    $revision_field_data = $data['entity_test_mulrev_property_revision'];
    $this
      ->assertCount(1, $revision_field_data['table']['join']);
    $this
      ->assertEquals([
      'entity_test_mul_property_data' => [
        'left_field' => 'revision_id',
        'field' => 'revision_id',
        'type' => 'INNER',
      ],
    ], $revision_field_data['table']['join']);
    $revision_base_data = $data['entity_test_mulrev_revision'];
    $this
      ->assertCount(2, $revision_base_data['table']['join']);
    $this
      ->assertEquals([
      'entity_test_mulrev_property_revision' => [
        'left_field' => 'revision_id',
        'field' => 'revision_id',
        'type' => 'INNER',
      ],
      'entity_test_mul_property_data' => [
        'left_field' => 'revision_id',
        'field' => 'revision_id',
      ],
    ], $revision_base_data['table']['join']);
    $this
      ->assertFalse(isset($data['data_table']));
    $this
      ->assertEquals('entity_test_mul_property_data', $revision_field_data['id']['relationship']['base']);
    $this
      ->assertEquals('id', $revision_field_data['id']['relationship']['base field']);
    $this
      ->assertEquals('entity_test_mul_property_data', $revision_field_data['revision_id']['relationship']['base']);
    $this
      ->assertEquals('revision_id', $revision_field_data['revision_id']['relationship']['base field']);
  }

  /**
   * Tests revision table with data table support.
   */
  public function testRevisionTableWithRevisionDataTable() {
    $entity_type = $this->baseEntityType
      ->set('revision_table', 'entity_test_mulrev_revision')
      ->set('revision_data_table', 'entity_test_mulrev_property_revision')
      ->set('id', 'entity_test_mulrev')
      ->set('translatable', TRUE)
      ->setKey('revision', 'revision_id');
    $this
      ->setUpEntityType($entity_type);
    $data = $this->entityTypeManager
      ->getHandler('entity_test_mulrev', 'views_data')
      ->getViewsData();
    $this
      ->assertEquals('Entity test revisions', $data['entity_test_mulrev_property_revision']['table']['base']['title']);
    $this
      ->assertEquals('revision_id', $data['entity_test_mulrev_property_revision']['table']['base']['field']);
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['table']['base']));
    $this
      ->assertEquals('entity_test_mulrev', $data['entity_test_mulrev_property_revision']['table']['entity type']);
    $this
      ->assertEquals('Entity test revision', $data['entity_test_mulrev_revision']['table']['group']);
    $this
      ->assertEquals('entity_test', $data['entity_test']['table']['provider']);

    // Ensure the join information is set up properly.
    // Tests the join definition between the base and the revision table.
    $revision_field_data = $data['entity_test_mulrev_property_revision'];
    $this
      ->assertCount(1, $revision_field_data['table']['join']);
    $this
      ->assertEquals([
      'entity_test_mulrev_field_data' => [
        'left_field' => 'revision_id',
        'field' => 'revision_id',
        'type' => 'INNER',
      ],
    ], $revision_field_data['table']['join']);
    $revision_base_data = $data['entity_test_mulrev_revision'];
    $this
      ->assertCount(2, $revision_base_data['table']['join']);
    $this
      ->assertEquals([
      'entity_test_mulrev_property_revision' => [
        'left_field' => 'revision_id',
        'field' => 'revision_id',
        'type' => 'INNER',
      ],
      'entity_test_mulrev_field_data' => [
        'left_field' => 'revision_id',
        'field' => 'revision_id',
      ],
    ], $revision_base_data['table']['join']);
    $this
      ->assertFalse(isset($data['data_table']));
    $this
      ->assertEquals('entity_test_mulrev_field_data', $revision_field_data['id']['relationship']['base']);
    $this
      ->assertEquals('id', $revision_field_data['id']['relationship']['base field']);
    $this
      ->assertEquals('entity_test_mulrev_field_data', $revision_field_data['revision_id']['relationship']['base']);
    $this
      ->assertEquals('revision_id', $revision_field_data['revision_id']['relationship']['base field']);
  }

  /**
   * Tests fields on the base table.
   */
  public function testBaseTableFields() {
    $data = $this->entityTypeManager
      ->getHandler('entity_test', 'views_data')
      ->getViewsData();
    $this
      ->assertNumericField($data['entity_test']['id']);
    $this
      ->assertViewsDataField($data['entity_test']['id'], 'id');
    $this
      ->assertUuidField($data['entity_test']['uuid']);
    $this
      ->assertViewsDataField($data['entity_test']['uuid'], 'uuid');
    $this
      ->assertStringField($data['entity_test']['type']);
    $this
      ->assertEquals('type', $data['entity_test']['type']['entity field']);
    $this
      ->assertLanguageField($data['entity_test']['langcode']);
    $this
      ->assertViewsDataField($data['entity_test']['langcode'], 'langcode');
    $this
      ->assertEquals('Original language', $data['entity_test']['langcode']['title']);
    $this
      ->assertStringField($data['entity_test']['name']);
    $this
      ->assertViewsDataField($data['entity_test']['name'], 'name');
    $this
      ->assertLongTextField($data['entity_test'], 'description');
    $this
      ->assertViewsDataField($data['entity_test']['description__value'], 'description');
    $this
      ->assertViewsDataField($data['entity_test']['description__format'], 'description');
    $this
      ->assertUriField($data['entity_test']['homepage']);
    $this
      ->assertViewsDataField($data['entity_test']['homepage'], 'homepage');
    $this
      ->assertEntityReferenceField($data['entity_test']['user_id']);
    $this
      ->assertViewsDataField($data['entity_test']['user_id'], 'user_id');
    $relationship = $data['entity_test']['user_id']['relationship'];
    $this
      ->assertEquals('users_field_data', $relationship['base']);
    $this
      ->assertEquals('uid', $relationship['base field']);

    // The string field name should be used as the 'entity field' but the actual
    // field should reflect what the column mapping is using for multi-value
    // base fields NOT just the field name. The actual column name returned from
    // mappings in the test mocks is 'value'.
    $this
      ->assertStringField($data['entity_test__string']['string_value']);
    $this
      ->assertViewsDataField($data['entity_test__string']['string_value'], 'string');
    $this
      ->assertEquals([
      'left_field' => 'id',
      'field' => 'entity_id',
      'extra' => [
        [
          'field' => 'deleted',
          'value' => 0,
          'numeric' => TRUE,
        ],
      ],
    ], $data['entity_test__string']['table']['join']['entity_test']);
  }

  /**
   * Tests fields on the data table.
   */
  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']);
  }

  /**
   * Tests fields on the revision table.
   */
  public function testRevisionTableFields() {
    $entity_type = $this->baseEntityType
      ->set('id', 'entity_test_mulrev')
      ->set('base_table', 'entity_test_mulrev')
      ->set('revision_table', 'entity_test_mulrev_revision')
      ->set('data_table', 'entity_test_mulrev_property_data')
      ->set('revision_data_table', 'entity_test_mulrev_property_revision')
      ->set('translatable', TRUE);
    $base_field_definitions = $this->commonBaseFields;
    $base_field_definitions['name']
      ->setRevisionable(TRUE);
    $base_field_definitions['description']
      ->setRevisionable(TRUE);
    $base_field_definitions['homepage']
      ->setRevisionable(TRUE);
    $base_field_definitions['user_id']
      ->setRevisionable(TRUE);
    $base_field_definitions['non_rev_field'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Non Revisionable Field'))
      ->setDescription(t('A non-revisionable test field.'))
      ->setRevisionable(FALSE)
      ->setTranslatable(TRUE)
      ->setCardinality(1)
      ->setReadOnly(TRUE);
    $base_field_definitions['non_mul_field'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Non translatable'))
      ->setDescription(t('A non-translatable string field'))
      ->setRevisionable(TRUE);
    $this
      ->setUpEntityType($entity_type, $base_field_definitions);
    $data = $this->entityTypeManager
      ->getHandler('entity_test_mulrev', 'views_data')
      ->getViewsData();

    // Check the base fields.
    $this
      ->assertFalse(isset($data['entity_test_mulrev']['id']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev']['type']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev']['revision_id']));
    $this
      ->assertUuidField($data['entity_test_mulrev']['uuid']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev']['uuid'], 'uuid');

    // Also ensure that field_data only fields don't appear on the base table.
    $this
      ->assertFalse(isset($data['entity_test_mulrev']['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']['homepage']));

    // $this->assertFalse(isset($data['entity_test_mulrev']['langcode']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev']['user_id']));

    // Check the revision fields. The revision ID should only appear in the data
    // table.
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['revision_id']));

    // Also ensure that field_data only fields don't appear on the revision table.
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['id']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['name']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['description']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['description__value']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['description__format']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['homepage']));
    $this
      ->assertFalse(isset($data['entity_test_mulrev_revision']['user_id']));

    // Check the data fields.
    $this
      ->assertNumericField($data['entity_test_mulrev_property_data']['id']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['id'], 'id');
    $this
      ->assertNumericField($data['entity_test_mulrev_property_data']['revision_id']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['revision_id'], 'revision_id');
    $this
      ->assertLanguageField($data['entity_test_mulrev_property_data']['langcode']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['langcode'], 'langcode');
    $this
      ->assertStringField($data['entity_test_mulrev_property_data']['name']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['name'], 'name');
    $this
      ->assertLongTextField($data['entity_test_mulrev_property_data'], 'description');
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['description__value'], 'description');
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['description__format'], 'description');
    $this
      ->assertUriField($data['entity_test_mulrev_property_data']['homepage']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['homepage'], 'homepage');
    $this
      ->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_data']['user_id'], 'user_id');
    $relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship'];
    $this
      ->assertEquals('users_field_data', $relationship['base']);
    $this
      ->assertEquals('uid', $relationship['base field']);

    // Check the property data fields.
    $this
      ->assertNumericField($data['entity_test_mulrev_property_revision']['id']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_revision']['id'], 'id');
    $this
      ->assertEquals('entity_test_mulrev_property_data', $data['entity_test_mulrev_property_revision']['id']['relationship']['base']);
    $this
      ->assertEquals('id', $data['entity_test_mulrev_property_revision']['id']['relationship']['base field']);
    $this
      ->assertEquals('entity_test_mulrev_property_data', $data['entity_test_mulrev_property_revision']['revision_id']['relationship']['base']);
    $this
      ->assertEquals('revision_id', $data['entity_test_mulrev_property_revision']['revision_id']['relationship']['base field']);
    $this
      ->assertLanguageField($data['entity_test_mulrev_property_revision']['langcode']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_revision']['langcode'], 'langcode');
    $this
      ->assertEquals('Translation language', $data['entity_test_mulrev_property_revision']['langcode']['title']);
    $this
      ->assertStringField($data['entity_test_mulrev_property_revision']['name']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_revision']['name'], 'name');
    $this
      ->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description');
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_revision']['description__value'], 'description');
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_revision']['description__format'], 'description');
    $this
      ->assertUriField($data['entity_test_mulrev_property_revision']['homepage']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_revision']['homepage'], 'homepage');
    $this
      ->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_property_revision']['user_id'], 'user_id');
    $relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship'];
    $this
      ->assertEquals('users_field_data', $relationship['base']);
    $this
      ->assertEquals('uid', $relationship['base field']);
    $this
      ->assertStringField($data['entity_test_mulrev__string']['string_value']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev__string']['string_value'], 'string');
    $this
      ->assertEquals([
      'left_field' => 'id',
      'field' => 'entity_id',
      'extra' => [
        [
          'field' => 'deleted',
          'value' => 0,
          'numeric' => TRUE,
        ],
      ],
    ], $data['entity_test_mulrev__string']['table']['join']['entity_test_mulrev_property_data']);
    $this
      ->assertStringField($data['entity_test_mulrev_revision__string']['string_value']);
    $this
      ->assertViewsDataField($data['entity_test_mulrev_revision__string']['string_value'], 'string');
    $this
      ->assertEquals([
      'left_field' => 'revision_id',
      'field' => 'entity_id',
      'extra' => [
        [
          'field' => 'deleted',
          'value' => 0,
          'numeric' => TRUE,
        ],
      ],
    ], $data['entity_test_mulrev_revision__string']['table']['join']['entity_test_mulrev_property_revision']);
  }

  /**
   * Tests generic stuff per field.
   *
   * @param array $data
   *   The views data to check.
   * @param string $field_name
   *   The entity field name.
   *
   * @internal
   */
  protected function assertViewsDataField(array $data, string $field_name) : void {
    $this
      ->assertEquals($field_name, $data['entity field']);
  }

  /**
   * Tests views data for a string field.
   *
   * @param array $data
   *   The views data to check.
   *
   * @internal
   */
  protected function assertStringField(array $data) : void {
    $this
      ->assertEquals('field', $data['field']['id']);
    $this
      ->assertEquals('string', $data['filter']['id']);
    $this
      ->assertEquals('string', $data['argument']['id']);
    $this
      ->assertEquals('standard', $data['sort']['id']);
  }

  /**
   * Tests views data for a URI field.
   *
   * @param array $data
   *   The views data to check.
   *
   * @internal
   */
  protected function assertUriField(array $data) : void {
    $this
      ->assertEquals('field', $data['field']['id']);
    $this
      ->assertEquals('string', $data['field']['default_formatter']);
    $this
      ->assertEquals('string', $data['filter']['id']);
    $this
      ->assertEquals('string', $data['argument']['id']);
    $this
      ->assertEquals('standard', $data['sort']['id']);
  }

  /**
   * Tests views data for a long text field.
   *
   * @param array $data
   *   The views data for the table this field is in.
   * @param string $field_name
   *   The name of the field being checked.
   *
   * @internal
   */
  protected function assertLongTextField(array $data, string $field_name) : void {
    $value_field = $data[$field_name . '__value'];
    $this
      ->assertEquals('field', $value_field['field']['id']);
    $this
      ->assertEquals($field_name . '__format', $value_field['field']['format']);
    $this
      ->assertEquals('string', $value_field['filter']['id']);
    $this
      ->assertEquals('string', $value_field['argument']['id']);
    $this
      ->assertEquals('standard', $value_field['sort']['id']);
    $this
      ->assertStringField($data[$field_name . '__format']);
  }

  /**
   * Tests views data for a UUID field.
   *
   * @param array $data
   *   The views data to check.
   *
   * @internal
   */
  protected function assertUuidField(array $data) : void {

    // @todo Can we provide additional support for UUIDs in views?
    $this
      ->assertEquals('field', $data['field']['id']);
    $this
      ->assertFalse($data['field']['click sortable']);
    $this
      ->assertEquals('string', $data['filter']['id']);
    $this
      ->assertEquals('string', $data['argument']['id']);
    $this
      ->assertEquals('standard', $data['sort']['id']);
  }

  /**
   * Tests views data for a numeric field.
   *
   * @param array $data
   *   The views data to check.
   *
   * @internal
   */
  protected function assertNumericField(array $data) : void {
    $this
      ->assertEquals('field', $data['field']['id']);
    $this
      ->assertEquals('numeric', $data['filter']['id']);
    $this
      ->assertEquals('numeric', $data['argument']['id']);
    $this
      ->assertEquals('standard', $data['sort']['id']);
  }

  /**
   * Tests views data for a language field.
   *
   * @param array $data
   *   The views data to check.
   *
   * @internal
   */
  protected function assertLanguageField(array $data) : void {
    $this
      ->assertEquals('field', $data['field']['id']);
    $this
      ->assertEquals('language', $data['filter']['id']);
    $this
      ->assertEquals('language', $data['argument']['id']);
    $this
      ->assertEquals('standard', $data['sort']['id']);
  }

  /**
   * Tests views data for an entity reference field.
   *
   * @internal
   */
  protected function assertEntityReferenceField(array $data) : void {
    $this
      ->assertEquals('field', $data['field']['id']);
    $this
      ->assertEquals('numeric', $data['filter']['id']);
    $this
      ->assertEquals('numeric', $data['argument']['id']);
    $this
      ->assertEquals('standard', $data['sort']['id']);
  }

  /**
   * Tests views data for a bundle field.
   *
   * @internal
   */
  protected function assertBundleField(array $data) : void {
    $this
      ->assertEquals('field', $data['field']['id']);
    $this
      ->assertEquals('bundle', $data['filter']['id']);
    $this
      ->assertEquals('string', $data['argument']['id']);
    $this
      ->assertEquals('standard', $data['sort']['id']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertContentTrait::$content protected property The current raw content.
AssertContentTrait::$drupalSettings protected property The drupalSettings value from the current raw $content.
AssertContentTrait::$elements protected property The XML structure parsed from the current raw $content. 1
AssertContentTrait::$plainTextContent protected property The plain-text content of raw $content (text nodes).
AssertContentTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertContentTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertContentTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertContentTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertContentTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertContentTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertContentTrait::assertLink protected function Passes if a link with the specified label is found.
AssertContentTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertContentTrait::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
AssertContentTrait::assertNoEscaped protected function Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertNoField protected function Asserts that a field does not exist with the given name or ID.
AssertContentTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertContentTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertContentTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertContentTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertContentTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertContentTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertContentTrait::assertNoLinkByHrefInMainRegion protected function Passes if a link containing a given href is not found in the main region.
AssertContentTrait::assertNoOption protected function Asserts that a select option in the current page does not exist.
AssertContentTrait::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
AssertContentTrait::assertNoPattern protected function Triggers a pass if the perl regex pattern is not found in raw content.
AssertContentTrait::assertNoRaw protected function Passes if the raw text is NOT found on the loaded page, fail otherwise.
AssertContentTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertNoTitle protected function Pass if the page title is not the given string.
AssertContentTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertContentTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertContentTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionSelectedWithDrupalSelector protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionWithDrupalSelector protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertContentTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertContentTrait::assertText protected function Passes if the page (with HTML stripped) contains the text.
AssertContentTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertContentTrait::assertTextPattern protected function Asserts that a Perl regex pattern is found in the plain-text content.
AssertContentTrait::assertThemeOutput protected function Asserts themed output.
AssertContentTrait::assertTitle protected function Pass if the page title is the given string.
AssertContentTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertContentTrait::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
AssertContentTrait::buildXPathQuery protected function Builds an XPath query.
AssertContentTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertContentTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
AssertContentTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertContentTrait::getDrupalSettings protected function Gets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::getRawContent protected function Gets the current raw content.
AssertContentTrait::getSelectedItem protected function Get the selected value from a select field.
AssertContentTrait::getTextContent protected function Retrieves the plain-text content from the current raw content.
AssertContentTrait::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
AssertContentTrait::removeWhiteSpace protected function Removes all white-space between HTML tags from the raw content.
AssertContentTrait::setDrupalSettings protected function Sets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::setRawContent protected function Sets the raw content (e.g. HTML).
AssertContentTrait::xpath protected function Performs an xpath search on the contents of the internal browser.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
EntityViewsDataTest::$baseEntityType protected property The base entity type definition, which some tests modify.
EntityViewsDataTest::$commonBaseFields protected property The common base fields for test entity types.
EntityViewsDataTest::$entityTypeManager protected property The entity type manager.
EntityViewsDataTest::$modules protected static property Modules to enable. Overrides KernelTestBase::$modules
EntityViewsDataTest::assertBundleField protected function Tests views data for a bundle field.
EntityViewsDataTest::assertEntityReferenceField protected function Tests views data for an entity reference field.
EntityViewsDataTest::assertLanguageField protected function Tests views data for a language field.
EntityViewsDataTest::assertLongTextField protected function Tests views data for a long text field.
EntityViewsDataTest::assertNumericField protected function Tests views data for a numeric field.
EntityViewsDataTest::assertStringField protected function Tests views data for a string field.
EntityViewsDataTest::assertUriField protected function Tests views data for a URI field.
EntityViewsDataTest::assertUuidField protected function Tests views data for a UUID field.
EntityViewsDataTest::assertViewsDataField protected function Tests generic stuff per field.
EntityViewsDataTest::setUp protected function Overrides KernelTestBase::setUp
EntityViewsDataTest::setUpEntityType protected function Mocks an entity type and its base fields.
EntityViewsDataTest::testBaseTableFields public function Tests fields on the base table.
EntityViewsDataTest::testBaseTables public function Tests base tables.
EntityViewsDataTest::testDataTable public function Tests data_table support.
EntityViewsDataTest::testDataTableFields public function Tests fields on the data table.
EntityViewsDataTest::testRevisionTableFields public function Tests fields on the revision table.
EntityViewsDataTest::testRevisionTableWithoutDataTable public function Tests revision table without data table support.
EntityViewsDataTest::testRevisionTableWithRevisionDataTable public function Tests revision table with data table support.
EntityViewsDataTest::testRevisionTableWithRevisionDataTableAndDataTable public function Tests revision table with data table support.
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
KernelTestBase::$backupGlobals protected property Back up and restore any global variables that may be changed by tests.
KernelTestBase::$backupStaticAttributes protected property Back up and restore static class properties that may be changed by tests.
KernelTestBase::$backupStaticAttributesBlacklist protected property Contains a few static class properties for performance.
KernelTestBase::$classLoader protected property
KernelTestBase::$configImporter protected property @todo Move into Config test base class. 3
KernelTestBase::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
KernelTestBase::$container protected property
KernelTestBase::$databasePrefix protected property
KernelTestBase::$preserveGlobalState protected property Do not forward any global state from the parent process to the processes that run the actual tests.
KernelTestBase::$root protected property The app root.
KernelTestBase::$runTestInSeparateProcess protected property Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property.
KernelTestBase::$siteDirectory protected property
KernelTestBase::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 4
KernelTestBase::$vfsRoot protected property The virtual filesystem root directory.
KernelTestBase::assertPostConditions protected function 1
KernelTestBase::bootEnvironment protected function Bootstraps a basic test environment.
KernelTestBase::bootKernel private function Bootstraps a kernel for a test.
KernelTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
KernelTestBase::disableModules protected function Disables modules for this test.
KernelTestBase::enableModules protected function Enables modules for this test.
KernelTestBase::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
KernelTestBase::getDatabaseConnectionInfo protected function Returns the Database connection info to be used for this test. 2
KernelTestBase::getDatabasePrefix public function
KernelTestBase::getExtensionsForModules private function Returns Extension objects for $modules to enable.
KernelTestBase::getModulesToEnable private static function Returns the modules to enable for this test.
KernelTestBase::initFileCache protected function Initializes the FileCache component.
KernelTestBase::installConfig protected function Installs default configuration for a given list of modules.
KernelTestBase::installEntitySchema protected function Installs the storage schema for a specific entity type.
KernelTestBase::installSchema protected function Installs database tables from a module schema definition.
KernelTestBase::prepareTemplate protected function
KernelTestBase::register public function Registers test-specific services. Overrides ServiceProviderInterface::register 14
KernelTestBase::render protected function Renders a render array.
KernelTestBase::setInstallProfile protected function Sets the install profile and rebuilds the container to update it.
KernelTestBase::setSetting protected function Sets an in-memory Settings variable.
KernelTestBase::setUpBeforeClass public static function
KernelTestBase::setUpFilesystem protected function Sets up the filesystem, so things like the file directory. 1
KernelTestBase::stop protected function Stops test execution.
KernelTestBase::tearDown protected function 3
KernelTestBase::tearDownCloseDatabaseConnection public function @after
KernelTestBase::vfsDump protected function Dumps the current state of the virtual filesystem to STDOUT.
KernelTestBase::__sleep public function Prevents serializing any properties.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case.
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.