3 namespace Drupal\system\Tests\Update;
6 use Drupal\simpletest\WebTestBase;
9 * Tests that update hooks are properly run.
13 class UpdateSchemaTest extends WebTestBase {
18 public static $modules = ['update_test_schema'];
21 * @var \Drupal\user\UserInterface
35 protected function setUp() {
38 require_once \Drupal::root() . '/core/includes/update.inc';
39 $this->user = $this->drupalCreateUser(['administer software updates', 'access site in maintenance mode']);
40 $this->updateUrl = Url::fromRoute('system.db_update');
44 * Tests that update hooks are properly run.
46 public function testUpdateHooks() {
47 // Verify that the 8000 schema is in place.
48 $this->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8000);
49 $this->assertFalse(db_index_exists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');
51 // Increment the schema version.
52 \Drupal::state()->set('update_test_schema_version', 8001);
54 $this->drupalLogin($this->user);
55 $this->drupalGet($this->updateUrl, ['external' => TRUE]);
56 $this->clickLink(t('Continue'));
57 $this->assertRaw('Schema version 8001.');
58 // Run the update hooks.
59 $this->clickLink(t('Apply pending updates'));
61 // Ensure schema has changed.
62 $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
63 // Ensure the index was added for column a.
64 $this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');