public function DefaultTableMappingTest::testGetFieldTableName in Drupal 9
Same name and namespace in other branches
- 8 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 356
Class
- DefaultTableMappingTest
- @coversDefaultClass \Drupal\Core\Entity\Sql\DefaultTableMapping @group Entity
Namespace
Drupal\Tests\Core\Entity\SqlCode
public function testGetFieldTableName($table_names, $expected) {
$field_name = 'test';
$columns = [
'test',
];
$definition = $this
->setUpDefinition($field_name, $columns);
$definition
->expects($this
->any())
->method('getColumns')
->willReturn($columns);
$this->entityType
->expects($this
->any())
->method('getBaseTable')
->willReturn(isset($table_names['base']) ? $table_names['base'] : 'entity_test');
$this->entityType
->expects($this
->any())
->method('getDataTable')
->willReturn(isset($table_names['data']) ? $table_names['data'] : FALSE);
$this->entityType
->expects($this
->any())
->method('getRevisionTable')
->willReturn(isset($table_names['revision']) ? $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'));
}