UpdateSchemaTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\UpdateSystem;
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
class UpdateSchemaTest extends BrowserTestBase {
use RequirementsPageTrait;
protected static $modules = [
'update_test_schema',
];
protected $defaultTheme = 'stark';
protected $user;
protected $updateUrl;
protected function setUp() : void {
parent::setUp();
require_once $this->root . '/core/includes/update.inc';
$this->user = $this
->drupalCreateUser([
'administer software updates',
'access site in maintenance mode',
]);
$this->updateUrl = Url::fromRoute('system.db_update');
}
public function testUpdateHooks() {
$connection = Database::getConnection();
$update_registry = \Drupal::service('update.update_hook_registry');
$this
->assertEquals(8000, $update_registry
->getInstalledVersion('update_test_schema'));
$this
->assertFalse($connection
->schema()
->indexExists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');
\Drupal::state()
->set('update_test_schema_version', 8001);
$this
->drupalLogin($this->user);
$this
->drupalGet($this->updateUrl, [
'external' => TRUE,
]);
$this
->updateRequirementsProblem();
$this
->clickLink('Continue');
$this
->assertSession()
->pageTextContains('Schema version 8001.');
$this
->clickLink('Apply pending updates');
$this
->checkForMetaRefresh();
$this
->resetAll();
$update_registry = \Drupal::service('update.update_hook_registry');
$this
->assertEquals(8001, $update_registry
->getInstalledVersion('update_test_schema'));
$this
->assertTrue($connection
->schema()
->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
}
}