function UpdatePathTestBaseTest::testUpdateHookN

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php \Drupal\FunctionalTests\Update\UpdatePathTestBaseTest::testUpdateHookN()
  2. 8.9.x core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php \Drupal\FunctionalTests\Update\UpdatePathTestBaseTest::testUpdateHookN()
  3. 11.x core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php \Drupal\FunctionalTests\Update\UpdatePathTestBaseTest::testUpdateHookN()

Tests that updates are properly run.

File

core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php, line 42

Class

UpdatePathTestBaseTest
Tests the update path base class.

Namespace

Drupal\FunctionalTests\Update

Code

public function testUpdateHookN() : void {
  $connection = Database::getConnection();
  // Increment the schema version.
  \Drupal::state()->set('update_test_schema_version', 8001);
  $this->runUpdates();
  // Ensure that after running the updates the update functions have been
  // loaded. If they have not then the tests carried out in
  // \Drupal\Tests\UpdatePathTestTrait::runUpdates() can result in false
  // positives.
  $this->assertTrue(function_exists('update_test_semver_update_n_update_8001'), 'The update_test_semver_update_n_update_8001() has been loaded');
  $select = $connection->select('watchdog');
  $select->orderBy('wid', 'DESC');
  $select->range(0, 5);
  $select->fields('watchdog', [
    'message',
  ]);
  $container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) {
    return str_contains($row->message, 'Container cannot be saved to cache.');
  });
  $this->assertEquals([], $container_cannot_be_saved_messages);
  // Ensure schema has changed.
  /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
  $update_registry = \Drupal::service('update.update_hook_registry');
  $this->assertEquals(8001, $update_registry->getInstalledVersion('update_test_schema'));
  $this->assertEquals(8001, $update_registry->getInstalledVersion('update_test_semver_update_n'));
  // 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.');
  // Ensure update_test_semver_update_n_update_8001 was run.
  $this->assertEquals('Yes, I was run. Thanks for testing!', \Drupal::state()->get('update_test_semver_update_n_update_8001'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.