1.20.x update.test | UpdateDrupal7TestCase::testAvailableUpdates() |
Tests that updates will be executed in the correct order.
File
- modules/
simpletest/ tests/ update.test, line 105 - Tests for the update system.
Class
- UpdateDrupal7TestCase
- Tests for ensuring updates from Drupal 7 execute properly.
Code
function testAvailableUpdates() {
// Check that update numbers are ordered correctly.
// 7xxx, then 0 - 6999.
$schema_versions = backdrop_get_schema_versions('update_d7_test_1');
$expected_versions = array(
'7000', '7001', '7002',
'1000', '1001', '1002', '1003',
);
$this->assertIdentical($schema_versions, $expected_versions, 'Modules with Drupal 7 update numbers properly order updates.');
// No updates should be needed initially.
$list = update_get_update_list();
$this->assertIdentical($list, array(), 'No available updates after enabling D7 update modules on a fresh install.');
// And the current schema should be 1003.
$installed_schema = backdrop_get_installed_schema_version('update_d7_test_1');
$this->assertIdentical($installed_schema, '1003', 'Newly installed module with D7 updates starts at Backdrop 1xxx schema number.');
// Updates starting in the 7xxx should finish the needed 7xxx updates, then
// then run from 1000.
backdrop_set_installed_schema_version('update_d7_test_1', '7000');
$list = update_get_update_list();
$expected_list['pending_keys'] = array(
7001, 7002,
1000, 1001, 1002, 1003,
);
$expected_list['start'] = '7001';
$this->assertEqual(array_keys($list['update_d7_test_1']['pending']), $expected_list['pending_keys'], 'Updates starting from 7000 are in the expected order.');
$this->assertEqual($list['update_d7_test_1']['start'], $expected_list['start'], 'Updates will start at the right number.');
// If the last installed schema is 8xxx, start updates from the matching
// 1xxx update. e.g. update 8001 is followed by 1002. This logic exists only
// to ease HEAD-to-HEAD Backdrop updates during the Backdrop 1.x cycle, when
// updates were renamed from 8xxx to 1xxx. See update_get_update_list().
backdrop_set_installed_schema_version('update_d7_test_1', '8001');
$list = update_get_update_list();
$expected_list['pending_keys'] = array(
1002, 1003,
);
$expected_list['start'] = '1002';
$this->assertEqual(array_keys($list['update_d7_test_1']['pending']), $expected_list['pending_keys'], 'Updates starting from 8001 are in the expected order.');
$this->assertEqual($list['update_d7_test_1']['start'], $expected_list['start'], 'Updates will start at the right number.');
// Check that update numbers are ordered correctly when the last update is
// a 7xxx update in hook_update_last_removed().
backdrop_set_installed_schema_version('update_d7_test_2', '7002');
$list = update_get_update_list();
$expected_list['pending_keys'] = array(
1000, 1001, 1002,
);
$expected_list['start'] = '1000';
$this->assertEqual(array_keys($list['update_d7_test_2']['pending']), $expected_list['pending_keys'], 'Updates are in the expected order when the last removed schema is 7xxx.');
$this->assertEqual($list['update_d7_test_2']['start'], $expected_list['start'], 'Updates will start at the right number.');
// Check that updates are not allowed when the last installed version of
// a Drupal 7 module does not meet the required schema in
// hook_update_last_removed().
backdrop_set_installed_schema_version('update_d7_test_2', '7001');
$list = update_get_update_list();
$this->assertFalse(isset($list['update_d7_test_2']['pending']), 'Updates are not allowed if a Drupal 7 required schema is not met.');
$this->assertTrue(!empty($list['update_d7_test_2']['warning']), 'Update warning provided when a Drupal 7 required schema is not met.');
}