- <?php
- * @file
- * Tests for the update system.
- */
-
- * Tests for the update dependency ordering system.
- */
- class UpdateDependencyOrderingTestCase extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('update_test_1', 'update_test_2', 'update_test_3');
- require_once BACKDROP_ROOT . '/core/includes/update.inc';
- }
-
-
- * Test that updates within a single module run in the correct order.
- */
- function testUpdateOrderingSingleModule() {
- $starting_updates = array(
- 'update_test_1' => 1000,
- );
- $expected_updates = array(
- 'update_test_1_update_1000',
- 'update_test_1_update_1001',
- 'update_test_1_update_1002',
- );
- $actual_updates = array_keys(update_resolve_dependencies($starting_updates));
- $this->assertEqual($expected_updates, $actual_updates, 'Updates within a single module run in the correct order.');
- }
-
-
- * Test that dependencies between modules are resolved correctly.
- */
- function testUpdateOrderingModuleInterdependency() {
- $starting_updates = array(
- 'update_test_2' => 1000,
- 'update_test_3' => 1000,
- );
- $update_order = array_keys(update_resolve_dependencies($starting_updates));
-
- $first_dependency_satisfied = array_search('update_test_2_update_1000', $update_order) < array_search('update_test_3_update_1000', $update_order);
- $this->assertTrue($first_dependency_satisfied, 'The dependency of the second module on the first module is respected by the update function order.');
- $second_dependency_satisfied = array_search('update_test_3_update_1000', $update_order) < array_search('update_test_2_update_1001', $update_order);
- $this->assertTrue($second_dependency_satisfied, 'The dependency of the first module on the second module is respected by the update function order.');
- }
- }
-
- * Tests for missing update dependencies.
- */
- class UpdateDependencyMissingTestCase extends BackdropWebTestCase {
- function setUp() {
-
-
- parent::setUp('update_test_2');
- require_once BACKDROP_ROOT . '/core/includes/update.inc';
- }
-
- function testMissingUpdate() {
- $starting_updates = array(
- 'update_test_2' => 1000,
- );
- $update_graph = update_resolve_dependencies($starting_updates);
- $this->assertTrue($update_graph['update_test_2_update_1000']['allowed'], "The module's first update function is allowed to run, since it does not have any missing dependencies.");
- $this->assertFalse($update_graph['update_test_2_update_1001']['allowed'], "The module's second update function is not allowed to run, since it has a direct dependency on a missing update.");
- $this->assertFalse($update_graph['update_test_2_update_1002']['allowed'], "The module's third update function is not allowed to run, since it has an indirect dependency on a missing update.");
- }
- }
-
- * Tests for the invocation of hook_update_dependencies().
- */
- class UpdateDependencyHookInvocationTestCase extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('update_test_1', 'update_test_2');
- require_once BACKDROP_ROOT . '/core/includes/update.inc';
- }
-
-
- * Test the structure of the array returned by hook_update_dependencies().
- */
- function testHookUpdateDependencies() {
- $update_dependencies = update_retrieve_dependencies();
- $this->assertTrue($update_dependencies['system'][1000]['update_test_1'] == 1000, 'An update function that has a dependency on two separate modules has the first dependency recorded correctly.');
- $this->assertTrue($update_dependencies['system'][1000]['update_test_2'] == 1001, 'An update function that has a dependency on two separate modules has the second dependency recorded correctly.');
- $this->assertTrue($update_dependencies['system'][1001]['update_test_1'] == 1002, 'An update function that depends on more than one update from the same module only has the dependency on the higher-numbered update function recorded.');
- }
- }
-
-
- * Tests for ensuring updates from Drupal 7 execute properly.
- */
- class UpdateDrupal7TestCase extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('update_d7_test_1', 'update_d7_test_2');
- require_once BACKDROP_ROOT . '/core/includes/update.inc';
- }
-
-
- * Tests that updates will be executed in the correct order.
- */
- function testAvailableUpdates() {
-
-
- $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.');
-
-
- $list = update_get_update_list();
- $this->assertIdentical($list, array(), 'No available updates after enabling D7 update modules on a fresh install.');
-
-
- $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.');
-
-
-
- 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.');
-
-
-
-
-
- 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.');
-
-
-
- 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.');
-
-
-
-
- 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.');
- }
- }