db backup prior to drupal security update
[yaffs-website] / web / core / modules / system / src / Tests / Update / UpdateSchemaTest.php
1 <?php
2
3 namespace Drupal\system\Tests\Update;
4
5 use Drupal\Core\Url;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9  * Tests that update hooks are properly run.
10  *
11  * @group Update
12  */
13 class UpdateSchemaTest extends WebTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['update_test_schema'];
19
20   /**
21    * @var \Drupal\user\UserInterface
22    */
23   protected $user;
24
25   /**
26    * The update URL.
27    *
28    * @var string
29    */
30   protected $updateUrl;
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function setUp() {
36     parent::setUp();
37
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');
41   }
42
43   /**
44    * Tests that update hooks are properly run.
45    */
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.');
50
51     // Increment the schema version.
52     \Drupal::state()->set('update_test_schema_version', 8001);
53
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'));
60
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.');
65   }
66
67 }