UpdatePathLastRemovedTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\UpdateSystem;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UpdatePathTestTrait;
class UpdatePathLastRemovedTest extends BrowserTestBase {
use UpdatePathTestTrait;
protected static $modules = [
'update_test_last_removed',
];
protected $defaultTheme = 'stark';
protected $updateUrl;
protected $updateUser;
protected function setUp() : void {
parent::setUp();
require_once $this->root . '/core/includes/update.inc';
$this->updateUrl = Url::fromRoute('system.db_update');
$this->updateUser = $this
->drupalCreateUser([
'administer software updates',
]);
}
public function testLastRemovedVersion() {
$update_registry = \Drupal::service('update.update_hook_registry');
$update_registry
->setInstalledVersion('update_test_last_removed', 8000);
$update_registry
->setInstalledVersion('system', 8804);
$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_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');
$update_registry
->setInstalledVersion('update_test_last_removed', 8002);
$this
->runUpdates();
$update_registry = \Drupal::service('update.update_hook_registry');
$this
->assertEquals(8003, $update_registry
->getInstalledVersion('update_test_last_removed'));
}
}