function UpdatePathTestBase::runUpdates

Same name in this branch
  1. 8.9.x core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php \Drupal\FunctionalTests\Update\UpdatePathTestBase::runUpdates()
Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php \Drupal\FunctionalTests\Update\UpdatePathTestBase::runUpdates()
  2. 10 core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php \Drupal\FunctionalTests\Update\UpdatePathTestBase::runUpdates()
  3. 11.x core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php \Drupal\FunctionalTests\Update\UpdatePathTestBase::runUpdates()

Helper function to run pending database updates.

File

core/modules/system/src/Tests/Update/UpdatePathTestBase.php, line 236

Class

UpdatePathTestBase
Provides a base class for writing an update test.

Namespace

Drupal\system\Tests\Update

Code

protected function runUpdates() {
  if (!$this->zlibInstalled) {
    $this->fail('Missing zlib requirement for update tests.');
    return FALSE;
  }
  // The site might be broken at the time so logging in using the UI might
  // not work, so we use the API itself.
  drupal_rewrite_settings([
    'settings' => [
      'update_free_access' => (object) [
        'value' => TRUE,
        'required' => TRUE,
      ],
    ],
  ]);
  $this->drupalGet($this->updateUrl);
  $this->clickLink(t('Continue'));
  $this->doSelectionTest();
  // Run the update hooks.
  $this->clickLink(t('Apply pending updates'));
  // Ensure there are no failed updates.
  if ($this->checkFailedUpdates) {
    $this->assertNoRaw('<strong>' . t('Failed:') . '</strong>');
    // Ensure that there are no pending updates.
    foreach ([
      'update',
      'post_update',
    ] as $update_type) {
      switch ($update_type) {
        case 'update':
          $all_updates = update_get_update_list();
          break;

        case 'post_update':
          $all_updates = \Drupal::service('update.post_update_registry')->getPendingUpdateInformation();
          break;

      }
      foreach ($all_updates as $module => $updates) {
        if (!empty($updates['pending'])) {
          foreach (array_keys($updates['pending']) as $update_name) {
            $this->fail("The {$update_name}() update function from the {$module} module did not run.");
          }
        }
      }
    }
    // Reset the static cache of drupal_get_installed_schema_version() so that
    // more complex update path testing works.
    drupal_static_reset('drupal_get_installed_schema_version');
    // The config schema can be incorrect while the update functions are being
    // executed. But once the update has been completed, it needs to be valid
    // again. Assert the schema of all configuration objects now.
    $names = $this->container
      ->get('config.storage')
      ->listAll();
    /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
    $typed_config = $this->container
      ->get('config.typed');
    $typed_config->clearCachedDefinitions();
    foreach ($names as $name) {
      $config = $this->config($name);
      $this->assertConfigSchema($typed_config, $name, $config->get());
    }
    // Ensure that the update hooks updated all entity schema.
    $needs_updates = \Drupal::entityDefinitionUpdateManager()->needsUpdates();
    $this->assertFalse($needs_updates, 'After all updates ran, entity schema is up to date.');
    if ($needs_updates) {
      foreach (\Drupal::entityDefinitionUpdateManager()->getChangeSummary() as $entity_type_id => $summary) {
        foreach ($summary as $message) {
          $this->fail($message);
        }
      }
    }
  }
}

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