function SqlContentEntityStorageSchemaTest::testGetSchemaRevisionable

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

Tests the schema for revisionable, non-translatable entities.

@covers ::__construct @covers ::getEntitySchemaTables @covers ::initializeBaseTable @covers ::initializeRevisionTable @covers ::addTableDefaults @covers ::getEntityIndexName @covers ::processRevisionTable @covers ::processIdentifierSchema

File

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

Class

SqlContentEntityStorageSchemaTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Sql%21SqlContentEntityStorageSchema.php/class/SqlContentEntityStorageSchema/8.9.x" title="Defines a schema handler that supports revisionable, translatable entities." class="local">\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema</a> @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetSchemaRevisionable() {
    $this->entityType = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityType')
        ->setConstructorArgs([
        [
            'id' => 'entity_test',
            'entity_keys' => [
                'id' => 'id',
                'revision' => 'revision_id',
            ],
        ],
    ])
        ->setMethods([
        'getRevisionMetadataKeys',
    ])
        ->getMock();
    $this->entityType
        ->expects($this->any())
        ->method('getRevisionMetadataKeys')
        ->will($this->returnValue([]));
    $this->storage
        ->expects($this->exactly(9))
        ->method('getRevisionTable')
        ->will($this->returnValue('entity_test_revision'));
    $this->setUpStorageDefinition('revision_id', [
        'columns' => [
            'value' => [
                'type' => 'int',
            ],
        ],
    ]);
    $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,
                ],
            ],
            '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,
                ],
            ],
            'primary key' => [
                'revision_id',
            ],
            'unique keys' => [],
            'indexes' => [
                'entity_test__id' => [
                    'id',
                ],
            ],
            'foreign keys' => [
                'entity_test__revisioned' => [
                    'table' => 'entity_test',
                    'columns' => [
                        'id' => 'id',
                    ],
                ],
            ],
        ],
    ];
    $this->setUpStorageSchema($expected);
    $table_mapping = new TestSqlContentDefaultTableMapping($this->entityType, $this->storageDefinitions);
    $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions));
    $table_mapping->setFieldNames('entity_test_revision', 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.