You are here

public function UpdateSchemaTest::testUpdateHooks in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateSchemaTest::testUpdateHooks()
  2. 10 core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateSchemaTest::testUpdateHooks()

Tests that update hooks are properly run.

File

core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php, line 58

Class

UpdateSchemaTest
Tests that update hooks are properly run.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testUpdateHooks() {
  $connection = Database::getConnection();

  // Verify that the 8000 schema is in place.
  $this
    ->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8000);
  $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(t('Continue'));
  $this
    ->assertRaw('Schema version 8001.');

  // Run the update hooks.
  $this
    ->clickLink(t('Apply pending updates'));
  $this
    ->checkForMetaRefresh();

  // Ensure schema has changed.
  $this
    ->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);

  // 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.');

  // Test the update_set_schema() utility function.
  require_once $this->root . '/core/includes/update.inc';
  update_set_schema('update_test_schema', 8003);

  // Ensure schema has changed.
  $this
    ->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8003);
}