public function UpdatePathTestBaseTest::testUpdateHookN in Drupal 9
Same name and namespace in other branches
- 8 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 87
Class
- UpdatePathTestBaseTest
- Tests the update path base class.
Namespace
Drupal\FunctionalTests\UpdateCode
public function testUpdateHookN() {
$connection = Database::getConnection();
// Increment the schema version.
\Drupal::state()
->set('update_test_schema_version', 8001);
$this
->runUpdates();
$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 strpos($row->message, 'Container cannot be saved to cache.') !== FALSE;
});
$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'));
}