function NoPreExistingSchemaUpdateTest::testNoPreExistingSchema

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\NoPreExistingSchemaUpdateTest::testNoPreExistingSchema()
  2. 8.9.x core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\NoPreExistingSchemaUpdateTest::testNoPreExistingSchema()
  3. 10 core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\NoPreExistingSchemaUpdateTest::testNoPreExistingSchema()

Tests the system module updates with no dependencies installed.

File

core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php, line 52

Class

NoPreExistingSchemaUpdateTest
Tries to update a module which has no pre-existing schema.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testNoPreExistingSchema() : void {
    $schema = \Drupal::service('update.update_hook_registry')->getAllInstalledVersions();
    $this->assertArrayNotHasKey('update_test_no_preexisting', $schema);
    $this->assertFalse(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));
    $update_url = Url::fromRoute('system.db_update');
    require_once $this->root . '/core/includes/update.inc';
    // The site might be broken at the time so logging in using the UI might
    // not work, so we use the API itself.
    $this->writeSettings([
        'settings' => [
            'update_free_access' => (object) [
                'value' => TRUE,
                'required' => TRUE,
            ],
        ],
    ]);
    $this->drupalGet($update_url);
    $this->assertSession()
        ->pageTextContains('Schema information for module update_test_no_preexisting was missing from the database. You should manually review the module updates and your database to check if any updates have been skipped up to, and including, update_test_no_preexisting_update_8001().');
    $this->updateRequirementsProblem();
    $schema = \Drupal::service('update.update_hook_registry')->getAllInstalledVersions();
    $this->assertArrayHasKey('update_test_no_preexisting', $schema);
    $this->assertEquals('8001', $schema['update_test_no_preexisting']);
    // The schema version has been fixed, but the update was never run.
    $this->assertFalse(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));
}

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