function UpdatePathTestBase::testDatabaseLoaded

Same name and namespace in other branches
  1. 10 core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php \Drupal\FunctionalTests\Update\UpdatePathTestBase::testDatabaseLoaded()

Tests that the database was properly loaded.

2 calls to UpdatePathTestBase::testDatabaseLoaded()
UpdatePathTestBaseFilledTest::testDatabaseProperlyLoaded in core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathTestBaseFilledTest.php
Tests that the database was properly loaded.
UpdatePathTestBaseTest::testDatabaseProperlyLoaded in core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php
Tests that the database was properly loaded.
1 method overrides UpdatePathTestBase::testDatabaseLoaded()
Mysql8RequirePrimaryKeyUpdateTest::testDatabaseLoaded in core/modules/mysql/tests/src/Functional/Mysql8RequirePrimaryKeyUpdateTest.php
Tests updates.

File

core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php, line 239

Class

UpdatePathTestBase
Provides a base class for writing an update test.

Namespace

Drupal\FunctionalTests\Update

Code

protected function testDatabaseLoaded() {
    // Set a value in the cache to prove caches are cleared.
    \Drupal::service('cache.default')->set(__CLASS__, 'Test');
    
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    foreach ([
        'user' => 10000,
        'node' => 8700,
        'system' => 10201,
        'update_test_schema' => 8000,
    ] as $module => $schema) {
        $this->assertEquals($schema, $update_registry->getInstalledVersion($module), "Module {$module} schema is {$schema}");
    }
    // Ensure that all {router} entries can be unserialized. If they cannot be
    // unserialized a notice will be thrown by PHP.
    $result = \Drupal::database()->select('router', 'r')
        ->fields('r', [
        'name',
        'route',
    ])
        ->execute()
        ->fetchAllKeyed(0, 1);
    // For the purpose of fetching the notices and displaying more helpful error
    // messages, let's override the error handler temporarily.
    set_error_handler(function ($severity, $message, $filename, $lineno) {
        throw new \ErrorException($message, 0, $severity, $filename, $lineno);
    });
    foreach ($result as $route_name => $route) {
        try {
            unserialize($route);
        } catch (\Exception $e) {
            $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
        }
    }
    restore_error_handler();
    // Before accessing the site we need to run updates first or the site might
    // be broken.
    $this->runUpdates();
    $this->assertEquals('standard', \Drupal::config('core.extension')->get('profile'));
    $this->assertEquals('Site-Install', \Drupal::config('system.site')->get('name'));
    $this->drupalGet('<front>');
    $this->assertSession()
        ->pageTextContains('Site-Install');
    // Ensure that the database tasks have been run during set up. Neither MySQL
    // nor SQLite make changes that are testable.
    $database = $this->container
        ->get('database');
    if ($database->driver() == 'pgsql') {
        $this->assertEquals('on', $database->query("SHOW standard_conforming_strings")
            ->fetchField());
        $this->assertEquals('escape', $database->query("SHOW bytea_output")
            ->fetchField());
    }
    // Ensure the test runners cache has been cleared.
    $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__));
}

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