function SqlContentEntityStorageSchemaTest::testGetSchemaRevisionableTranslatable

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

Tests the schema for revisionable, translatable entities.

@covers ::__construct @covers ::getEntitySchemaTables @covers ::initializeDataTable @covers ::addTableDefaults @covers ::getEntityIndexName @covers ::initializeRevisionDataTable @covers ::processRevisionDataTable

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php, line 627

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetSchemaRevisionableTranslatable() {
    $this->entityType = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityType')
        ->setConstructorArgs([
        [
            'id' => 'entity_test',
            'entity_keys' => [
                'id' => 'id',
                'revision' => 'revision_id',
                'langcode' => 'langcode',
            ],
            'revision_data_table' => 'entity_test_revision_field_data',
        ],
    ])
        ->setMethods([
        'isRevisionable',
        'isTranslatable',
        'getRevisionMetadataKeys',
    ])
        ->getMock();
    $this->entityType
        ->expects($this->any())
        ->method('isRevisionable')
        ->will($this->returnValue(TRUE));
    $this->entityType
        ->expects($this->any())
        ->method('isTranslatable')
        ->will($this->returnValue(TRUE));
    $this->storage
        ->expects($this->exactly(30))
        ->method('getRevisionTable')
        ->will($this->returnValue('entity_test_revision'));
    $this->setUpStorageDefinition('revision_id', [
        'columns' => [
            'value' => [
                'type' => 'int',
            ],
        ],
    ]);
    $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,
                ],
                'revision_id' => [
                    'type' => 'int',
                    'not null' => FALSE,
                ],
                'langcode' => [
                    'type' => 'varchar',
                    'not null' => TRUE,
                ],
            ],
            'primary key' => [
                'id',
            ],
            'unique keys' => [
                'entity_test__revision_id' => [
                    'revision_id',
                ],
            ],
            'indexes' => [],
            'foreign keys' => [
                'entity_test__revision' => [
                    'table' => 'entity_test_revision',
                    'columns' => [
                        'revision_id' => 'revision_id',
                    ],
                ],
            ],
        ],
        'entity_test_revision' => [
            'description' => 'The revision table for entity_test entities.',
            'fields' => [
                'id' => [
                    'type' => 'int',
                    'not null' => TRUE,
                ],
                'revision_id' => [
                    'type' => 'serial',
                    'not null' => TRUE,
                ],
                'langcode' => [
                    'type' => 'varchar',
                    'not null' => TRUE,
                ],
            ],
            'primary key' => [
                'revision_id',
            ],
            'unique keys' => [],
            'indexes' => [
                'entity_test__id' => [
                    'id',
                ],
            ],
            'foreign keys' => [
                'entity_test__revisioned' => [
                    'table' => 'entity_test',
                    'columns' => [
                        'id' => 'id',
                    ],
                ],
            ],
        ],
        'entity_test_field_data' => [
            'description' => 'The data table for entity_test entities.',
            'fields' => [
                'id' => [
                    'type' => 'int',
                    'not null' => TRUE,
                ],
                'revision_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__revision_id' => [
                    'revision_id',
                ],
                'entity_test__id__default_langcode__langcode' => [
                    0 => 'id',
                    1 => 'default_langcode',
                    2 => 'langcode',
                ],
            ],
            'foreign keys' => [
                'entity_test' => [
                    'table' => 'entity_test',
                    'columns' => [
                        'id' => 'id',
                    ],
                ],
            ],
        ],
        'entity_test_revision_field_data' => [
            'description' => 'The revision data table for entity_test entities.',
            'fields' => [
                'id' => [
                    'type' => 'int',
                    'not null' => TRUE,
                ],
                'revision_id' => [
                    'type' => 'int',
                    'not null' => TRUE,
                ],
                'langcode' => [
                    'type' => 'varchar',
                    'not null' => TRUE,
                ],
                'default_langcode' => [
                    'type' => 'int',
                    'size' => 'tiny',
                    'not null' => TRUE,
                ],
            ],
            'primary key' => [
                'revision_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',
                    ],
                ],
                'entity_test__revision' => [
                    'table' => 'entity_test_revision',
                    'columns' => [
                        'revision_id' => 'revision_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_revision', $non_data_fields);
    $table_mapping->setFieldNames('entity_test_field_data', array_keys($this->storageDefinitions));
    $table_mapping->setFieldNames('entity_test_revision_field_data', array_keys($this->storageDefinitions));
    $this->storageSchema
        ->expects($this->any())
        ->method('getTableMapping')
        ->will($this->returnValue($table_mapping));
    $this->storageSchema
        ->onEntityTypeCreate($this->entityType);
}

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