function SqlContentEntityStorageTest::testGetTableMappingTranslatableWithFields

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testGetTableMappingTranslatableWithFields()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testGetTableMappingTranslatableWithFields()
  3. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testGetTableMappingTranslatableWithFields()

Tests getTableMapping() with a translatable entity type with fields.

@covers ::__construct @covers ::getTableMapping

@dataProvider providerTestGetTableMappingSimple

Parameters

string[] $entity_keys: A map of entity keys to use for the mocked entity type.

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 771

Class

SqlContentEntityStorageTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Sql%21SqlContentEntityStorage.php/class/SqlContentEntityStorage/11.x" title="A content entity database storage implementation." class="local">\Drupal\Core\Entity\Sql\SqlContentEntityStorage</a> @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetTableMappingTranslatableWithFields(array $entity_keys) : void {
    // This allows to re-use the data provider.
    $entity_keys['langcode'] = 'langcode';
    $base_field_names = [
        'title',
        'description',
        'owner',
    ];
    $field_names = array_merge(array_values(array_filter($entity_keys)), $base_field_names);
    $this->fieldDefinitions = $this->mockFieldDefinitions($field_names);
    $this->entityType
        ->expects($this->atLeastOnce())
        ->method('isTranslatable')
        ->willReturn(TRUE);
    $this->entityType
        ->expects($this->atLeastOnce())
        ->method('getDataTable')
        ->willReturn('entity_test_field_data');
    $this->entityType
        ->expects($this->any())
        ->method('getKey')
        ->willReturnMap([
        [
            'id',
            $entity_keys['id'],
        ],
        [
            'uuid',
            $entity_keys['uuid'],
        ],
        [
            'bundle',
            $entity_keys['bundle'],
        ],
        [
            'langcode',
            $entity_keys['langcode'],
        ],
    ]);
    $this->setUpEntityStorage();
    $mapping = $this->entityStorage
        ->getTableMapping();
    $expected = [
        'entity_test',
        'entity_test_field_data',
    ];
    $this->assertEquals($expected, $mapping->getTableNames());
    $expected = array_values(array_filter($entity_keys));
    $actual = $mapping->getFieldNames('entity_test');
    $this->assertEquals($expected, $actual);
    // The UUID is not stored on the data table.
    $expected = array_merge(array_filter([
        $entity_keys['id'],
        $entity_keys['bundle'],
        $entity_keys['langcode'],
    ]), $base_field_names);
    $actual = $mapping->getFieldNames('entity_test_field_data');
    $this->assertEquals($expected, $actual);
    $expected = [];
    $actual = $mapping->getExtraColumns('entity_test');
    $this->assertEquals($expected, $actual);
    $actual = $mapping->getExtraColumns('entity_test_field_data');
    $this->assertEquals($expected, $actual);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.