From c1ecf4f6c80be9949327d82c481cf29c5bcfe1fe Mon Sep 17 00:00:00 2001 From: catch Date: Tue, 12 Jun 2012 10:58:32 +0900 Subject: [PATCH] Issue #1598618 by aspilicious, Rob Loach: Convert update.test to PSR-0. --- .../Update/DependencyHookInvocationTest.php | 38 ++++++ .../Tests/Update/DependencyMissingTest.php | 40 ++++++ .../Tests/Update/DependencyOrderingTest.php | 60 +++++++++ core/modules/system/tests/update.test | 117 ------------------ 4 files changed, 138 insertions(+), 117 deletions(-) create mode 100644 core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php create mode 100644 core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php create mode 100644 core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php delete mode 100644 core/modules/system/tests/update.test diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php new file mode 100644 index 00000000000..8ec1fca6470 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php @@ -0,0 +1,38 @@ + 'Update dependency hook invocation', + 'description' => 'Test that the hook invocation for determining update dependencies works correctly.', + 'group' => 'Update API', + ); + } + + function setUp() { + parent::setUp('update_test_1', 'update_test_2'); + require_once DRUPAL_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'][8000]['update_test_1'] == 8000, t('An update function that has a dependency on two separate modules has the first dependency recorded correctly.')); + $this->assertTrue($update_dependencies['system'][8000]['update_test_2'] == 8001, t('An update function that has a dependency on two separate modules has the second dependency recorded correctly.')); + $this->assertTrue($update_dependencies['system'][8001]['update_test_1'] == 8002, t('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.')); + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php new file mode 100644 index 00000000000..e2c94f28a44 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php @@ -0,0 +1,40 @@ + 'Missing update dependencies', + 'description' => 'Test that missing update dependencies are correctly flagged.', + 'group' => 'Update API', + ); + } + + function setUp() { + // Only install update_test_2.module, even though its updates have a + // dependency on update_test_3.module. + parent::setUp('update_test_2'); + require_once DRUPAL_ROOT . '/core/includes/update.inc'; + } + + function testMissingUpdate() { + $starting_updates = array( + 'update_test_2' => 8000, + ); + $update_graph = update_resolve_dependencies($starting_updates); + $this->assertTrue($update_graph['update_test_2_update_8000']['allowed'], t("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_8001']['allowed'], t("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_8002']['allowed'], t("The module's third update function is not allowed to run, since it has an indirect dependency on a missing update.")); + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php new file mode 100644 index 00000000000..099b36b9c19 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php @@ -0,0 +1,60 @@ + 'Update dependency ordering', + 'description' => 'Test that update functions are run in the proper order.', + 'group' => 'Update API', + ); + } + + function setUp() { + parent::setUp('update_test_1', 'update_test_2', 'update_test_3'); + require_once DRUPAL_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' => 8000, + ); + $expected_updates = array( + 'update_test_1_update_8000', + 'update_test_1_update_8001', + 'update_test_1_update_8002', + ); + $actual_updates = array_keys(update_resolve_dependencies($starting_updates)); + $this->assertEqual($expected_updates, $actual_updates, t('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' => 8000, + 'update_test_3' => 8000, + ); + $update_order = array_keys(update_resolve_dependencies($starting_updates)); + // Make sure that each dependency is satisfied. + $first_dependency_satisfied = array_search('update_test_2_update_8000', $update_order) < array_search('update_test_3_update_8000', $update_order); + $this->assertTrue($first_dependency_satisfied, t('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_8000', $update_order) < array_search('update_test_2_update_8001', $update_order); + $this->assertTrue($second_dependency_satisfied, t('The dependency of the first module on the second module is respected by the update function order.')); + } +} diff --git a/core/modules/system/tests/update.test b/core/modules/system/tests/update.test deleted file mode 100644 index 72bc61a383b..00000000000 --- a/core/modules/system/tests/update.test +++ /dev/null @@ -1,117 +0,0 @@ - 'Update dependency ordering', - 'description' => 'Test that update functions are run in the proper order.', - 'group' => 'Update API', - ); - } - - function setUp() { - parent::setUp('update_test_1', 'update_test_2', 'update_test_3'); - require_once DRUPAL_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' => 8000, - ); - $expected_updates = array( - 'update_test_1_update_8000', - 'update_test_1_update_8001', - 'update_test_1_update_8002', - ); - $actual_updates = array_keys(update_resolve_dependencies($starting_updates)); - $this->assertEqual($expected_updates, $actual_updates, t('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' => 8000, - 'update_test_3' => 8000, - ); - $update_order = array_keys(update_resolve_dependencies($starting_updates)); - // Make sure that each dependency is satisfied. - $first_dependency_satisfied = array_search('update_test_2_update_8000', $update_order) < array_search('update_test_3_update_8000', $update_order); - $this->assertTrue($first_dependency_satisfied, t('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_8000', $update_order) < array_search('update_test_2_update_8001', $update_order); - $this->assertTrue($second_dependency_satisfied, t('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 WebTestBase { - public static function getInfo() { - return array( - 'name' => 'Missing update dependencies', - 'description' => 'Test that missing update dependencies are correctly flagged.', - 'group' => 'Update API', - ); - } - - function setUp() { - // Only install update_test_2.module, even though its updates have a - // dependency on update_test_3.module. - parent::setUp('update_test_2'); - require_once DRUPAL_ROOT . '/core/includes/update.inc'; - } - - function testMissingUpdate() { - $starting_updates = array( - 'update_test_2' => 8000, - ); - $update_graph = update_resolve_dependencies($starting_updates); - $this->assertTrue($update_graph['update_test_2_update_8000']['allowed'], t("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_8001']['allowed'], t("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_8002']['allowed'], t("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 WebTestBase { - public static function getInfo() { - return array( - 'name' => 'Update dependency hook invocation', - 'description' => 'Test that the hook invocation for determining update dependencies works correctly.', - 'group' => 'Update API', - ); - } - - function setUp() { - parent::setUp('update_test_1', 'update_test_2'); - require_once DRUPAL_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'][8000]['update_test_1'] == 8000, t('An update function that has a dependency on two separate modules has the first dependency recorded correctly.')); - $this->assertTrue($update_dependencies['system'][8000]['update_test_2'] == 8001, t('An update function that has a dependency on two separate modules has the second dependency recorded correctly.')); - $this->assertTrue($update_dependencies['system'][8001]['update_test_1'] == 8002, t('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.')); - } -} -