You are here

public function NoPreExistingSchemaUpdateTest::testNoPreExistingSchema in Drupal 9

Same name and namespace in other branches
  1. 8 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 47

Class

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

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testNoPreExistingSchema() {
  $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
    ->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));
  $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().');
}