public function SqlContentEntityStorageSchemaTest::testGetSchemaTranslatable in Drupal 8
Tests the schema for non-revisionable, translatable entities.
@covers ::__construct @covers ::getEntitySchemaTables @covers ::initializeDataTable @covers ::addTableDefaults @covers ::getEntityIndexName @covers ::processDataTable
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ Sql/ SqlContentEntityStorageSchemaTest.php, line 515
Class
- SqlContentEntityStorageSchemaTest
- @coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema @group Entity
Namespace
Drupal\Tests\Core\Entity\SqlCode
public function testGetSchemaTranslatable() {
$this->entityType = new ContentEntityType([
'id' => 'entity_test',
'entity_keys' => [
'id' => 'id',
'langcode' => 'langcode',
],
'translatable' => TRUE,
]);
$this->storage
->expects($this
->any())
->method('getDataTable')
->will($this
->returnValue('entity_test_field_data'));
$this
->setUpStorageDefinition('langcode', [
'columns' => [
'value' => [
'type' => 'varchar',
],
],
]);
$this
->setUpStorageDefinition('default_langcode', [
'columns' => [
'value' => [
'type' => 'int',
'size' => 'tiny',
],
],
]);
$expected = [
'entity_test' => [
'description' => 'The base table for entity_test entities.',
'fields' => [
'id' => [
'type' => 'serial',
'not null' => TRUE,
],
'langcode' => [
'type' => 'varchar',
'not null' => TRUE,
],
],
'primary key' => [
'id',
],
'unique keys' => [],
'indexes' => [],
'foreign keys' => [],
],
'entity_test_field_data' => [
'description' => 'The data table for entity_test entities.',
'fields' => [
'id' => [
'type' => 'int',
'not null' => TRUE,
],
'langcode' => [
'type' => 'varchar',
'not null' => TRUE,
],
'default_langcode' => [
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
],
],
'primary key' => [
'id',
'langcode',
],
'unique keys' => [],
'indexes' => [
'entity_test__id__default_langcode__langcode' => [
0 => 'id',
1 => 'default_langcode',
2 => 'langcode',
],
],
'foreign keys' => [
'entity_test' => [
'table' => 'entity_test',
'columns' => [
'id' => 'id',
],
],
],
],
];
$this
->setUpStorageSchema($expected);
$table_mapping = new TestSqlContentDefaultTableMapping($this->entityType, $this->storageDefinitions);
$non_data_fields = array_keys($this->storageDefinitions);
unset($non_data_fields[array_search('default_langcode', $non_data_fields)]);
$table_mapping
->setFieldNames('entity_test', $non_data_fields);
$table_mapping
->setFieldNames('entity_test_field_data', array_keys($this->storageDefinitions));
$this->storageSchema
->expects($this
->any())
->method('getTableMapping')
->will($this
->returnValue($table_mapping));
$this
->assertNull($this->storageSchema
->onEntityTypeCreate($this->entityType));
}