function SqlContentEntityStorageSchemaTest::testGetSchemaTranslatable

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

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 513

Class

SqlContentEntityStorageSchemaTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

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')
        ->willReturn('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')
        ->willReturn($table_mapping);
    $this->assertNull($this->storageSchema
        ->onEntityTypeCreate($this->entityType));
}

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