function EntitySchemaTest::testIdentifierSchema

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php \Drupal\KernelTests\Core\Entity\EntitySchemaTest::testIdentifierSchema()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php \Drupal\KernelTests\Core\Entity\EntitySchemaTest::testIdentifierSchema()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php \Drupal\KernelTests\Core\Entity\EntitySchemaTest::testIdentifierSchema()

Tests the installed storage schema for identifier fields.

File

core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php, line 377

Class

EntitySchemaTest
Tests the default entity storage schema handler.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testIdentifierSchema() : void {
    $this->installEntitySchema('entity_test_rev');
    $key_value_store = \Drupal::keyValue('entity.storage_schema.sql');
    $id_schema = $key_value_store->get('entity_test_rev.field_schema_data.id', []);
    $revision_id_schema = $key_value_store->get('entity_test_rev.field_schema_data.revision_id', []);
    $expected_id_schema = [
        'entity_test_rev' => [
            'fields' => [
                'id' => [
                    'type' => 'serial',
                    'unsigned' => TRUE,
                    'size' => 'normal',
                    'not null' => TRUE,
                ],
            ],
        ],
        'entity_test_rev_revision' => [
            'fields' => [
                'id' => [
                    'type' => 'int',
                    'unsigned' => TRUE,
                    'size' => 'normal',
                    'not null' => TRUE,
                ],
            ],
        ],
    ];
    $this->assertEquals($expected_id_schema, $id_schema);
    $expected_revision_id_schema = [
        'entity_test_rev' => [
            'fields' => [
                'revision_id' => [
                    'type' => 'int',
                    'unsigned' => TRUE,
                    'size' => 'normal',
                    'not null' => FALSE,
                ],
            ],
        ],
        'entity_test_rev_revision' => [
            'fields' => [
                'revision_id' => [
                    'type' => 'serial',
                    'unsigned' => TRUE,
                    'size' => 'normal',
                    'not null' => TRUE,
                ],
            ],
        ],
    ];
    $this->assertEquals($expected_revision_id_schema, $revision_id_schema);
}

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