function UidUpdateToSerialTest::testDatabaseLoaded

Tests user_update_9301().

File

core/modules/user/tests/src/Functional/UidUpdateToSerialTest.php, line 27

Class

UidUpdateToSerialTest
Tests user_update_9301().

Namespace

Drupal\Tests\user\Functional

Code

public function testDatabaseLoaded() {
    $key_value_store = \Drupal::keyValue('entity.storage_schema.sql');
    $id_schema = $key_value_store->get('user.field_schema_data.uid', []);
    $this->assertSame('int', $id_schema['users']['fields']['uid']['type']);
    $this->runUpdates();
    $key_value_store = \Drupal::keyValue('entity.storage_schema.sql');
    $id_schema = $key_value_store->get('user.field_schema_data.uid', []);
    $this->assertSame('serial', $id_schema['users']['fields']['uid']['type']);
    $connection = \Drupal::database();
    if ($connection->driver() == 'pgsql') {
        $seq_name = $connection->makeSequenceName('users', 'uid');
        $seq_owner = $connection->query("SELECT d.refobjid::regclass as table_name, a.attname as field_name\n        FROM pg_depend d\n        JOIN pg_attribute a ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid\n        WHERE d.objid = :seq_name::regclass\n        AND d.refobjsubid > 0\n        AND d.classid = 'pg_class'::regclass", [
            ':seq_name' => 'public.' . $seq_name,
        ])
            ->fetchObject();
        $this->assertEquals($connection->tablePrefix('users') . 'users', $seq_owner->table_name);
        $this->assertEquals('uid', $seq_owner->field_name);
        $seq_last_value = $connection->query("SELECT last_value FROM {$seq_name}")
            ->fetchField();
        $maximum_uid = $connection->query('SELECT MAX([uid]) FROM {users}')
            ->fetchField();
        $this->assertEquals($maximum_uid + 1, $seq_last_value);
    }
}

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