function DefaultTableMappingTest::testGetFieldTableName

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php \Drupal\Tests\Core\Entity\Sql\DefaultTableMappingTest::testGetFieldTableName()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php \Drupal\Tests\Core\Entity\Sql\DefaultTableMappingTest::testGetFieldTableName()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php \Drupal\Tests\Core\Entity\Sql\DefaultTableMappingTest::testGetFieldTableName()

Tests DefaultTableMapping::getFieldTableName().

@covers ::getFieldTableName

@dataProvider providerTestGetFieldTableName

Parameters

string[] $table_names: An associative array of table names that should hold the field columns, where keys can be 'base', 'data' and 'revision'.

string $expected: The expected table name.

File

core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php, line 358

Class

DefaultTableMappingTest
@coversDefaultClass \Drupal\Core\Entity\Sql\DefaultTableMapping @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetFieldTableName($table_names, $expected) : void {
    $field_name = 'test';
    $columns = [
        'test',
    ];
    $definition = $this->setUpDefinition($field_name, $columns);
    $definition->expects($this->any())
        ->method('getColumns')
        ->willReturn($columns);
    $definition->expects($this->any())
        ->method('getTargetEntityTypeId')
        ->willReturn('entity_test');
    $this->entityType
        ->expects($this->any())
        ->method('getBaseTable')
        ->willReturn($table_names['base'] ?? 'entity_test');
    $this->entityType
        ->expects($this->any())
        ->method('getDataTable')
        ->willReturn($table_names['data'] ?? FALSE);
    $this->entityType
        ->expects($this->any())
        ->method('getRevisionTable')
        ->willReturn($table_names['revision'] ?? FALSE);
    $this->entityType
        ->expects($this->any())
        ->method('isTranslatable')
        ->willReturn(isset($table_names['data']));
    $this->entityType
        ->expects($this->any())
        ->method('isRevisionable')
        ->willReturn(isset($table_names['revision']));
    $this->entityType
        ->expects($this->any())
        ->method('getRevisionMetadataKeys')
        ->willReturn([]);
    $table_mapping = new TestDefaultTableMapping($this->entityType, [
        $field_name => $definition,
    ]);
    // Add the field to all the defined tables to ensure the correct one is
    // picked.
    foreach ($table_names as $table_name) {
        $table_mapping->setFieldNames($table_name, [
            $field_name,
        ]);
    }
    $this->assertEquals($expected, $table_mapping->getFieldTableName('test'));
}

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