class UpdateSchemaTest
Same name in this branch
- 9 core/tests/Drupal/KernelTests/Core/Extension/UpdateSchemaTest.php \Drupal\KernelTests\Core\Extension\UpdateSchemaTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateSchemaTest
- 11.x core/tests/Drupal/KernelTests/Core/Extension/UpdateSchemaTest.php \Drupal\KernelTests\Core\Extension\UpdateSchemaTest
- 10 core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateSchemaTest
- 10 core/tests/Drupal/KernelTests/Core/Extension/UpdateSchemaTest.php \Drupal\KernelTests\Core\Extension\UpdateSchemaTest
- 8.9.x core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateSchemaTest
Tests that update hooks are properly run.
@group Update
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\UpdateSystem\UpdateSchemaTest uses \Drupal\Tests\RequirementsPageTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of UpdateSchemaTest
File
-
core/
modules/ system/ tests/ src/ Functional/ UpdateSystem/ UpdateSchemaTest.php, line 15
Namespace
Drupal\Tests\system\Functional\UpdateSystemView source
class UpdateSchemaTest extends BrowserTestBase {
use RequirementsPageTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'update_test_schema',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* The update URL.
*
* @var string
*/
protected $updateUrl;
/**
* {@inheritdoc}
*/
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');
}
/**
* Tests that update hooks are properly run.
*/
public function testUpdateHooks() {
$connection = Database::getConnection();
/** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
$update_registry = \Drupal::service('update.update_hook_registry');
// Verify that the 8000 schema is in place.
$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.');
// Increment the schema version.
\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.');
// Run the update hooks.
$this->clickLink('Apply pending updates');
$this->checkForMetaRefresh();
// Ensure schema has changed.
$this->resetAll();
/** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
$update_registry = \Drupal::service('update.update_hook_registry');
$this->assertEquals(8001, $update_registry->getInstalledVersion('update_test_schema'));
// Ensure the index was added for column a.
$this->assertTrue($connection->schema()
->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.