You are here

public function UpdatePathLastRemovedTest::testLastRemovedVersion in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdatePathLastRemovedTest::testLastRemovedVersion()

Tests that a module with a too old schema version can not be updated.

File

core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php, line 57

Class

UpdatePathLastRemovedTest
Tests that modules can define their last removed update function.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testLastRemovedVersion() {

  /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
  $update_registry = \Drupal::service('update.update_hook_registry');
  $update_registry
    ->setInstalledVersion('update_test_last_removed', 8000);
  $update_registry
    ->setInstalledVersion('system', 8804);

  // Access the update page with a schema version that is too old for system
  // and the test module, only the generic core message should be shown.
  $this
    ->drupalLogin($this->updateUser);
  $this
    ->drupalGet($this->updateUrl);
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->pageTextContains('Requirements problem');
  $assert_session
    ->pageTextContains('The version of Drupal you are trying to update from is too old');
  $assert_session
    ->pageTextContains('Updating to Drupal 9 is only supported from Drupal version 8.8.0 or higher. If you are trying to update from an older version, first update to the latest version of Drupal 8');
  $assert_session
    ->pageTextNotContains('Unsupported schema version: Update test with hook_update_last_removed() implementation');
  $assert_session
    ->linkNotExists('Continue');

  // Update the installed version of system and then assert that now,
  // the test module is shown instead.
  $update_registry
    ->setInstalledVersion('system', 8805);
  $this
    ->drupalGet($this->updateUrl);
  $assert_session
    ->pageTextNotContains('The version of Drupal you are trying to update from is too old');
  $assert_session
    ->pageTextContains('Unsupported schema version: Update test with hook_update_last_removed() implementation');
  $assert_session
    ->pageTextContains('The installed version of the Update test with hook_update_last_removed() implementation module is too old to update. Update to an intermediate version first (last removed version: 8002, installed version: 8000).');
  $assert_session
    ->linkNotExists('Continue');

  // Set the expected schema version for the node and test module, updates are
  // successful now.
  $update_registry
    ->setInstalledVersion('update_test_last_removed', 8002);
  $this
    ->runUpdates();

  /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
  $update_registry = \Drupal::service('update.update_hook_registry');
  $this
    ->assertEquals(8003, $update_registry
    ->getInstalledVersion('update_test_last_removed'));
}