update.test 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the update system.
  5. */
  6. /**
  7. * Tests for the update dependency ordering system.
  8. */
  9. class UpdateDependencyOrderingTestCase extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Update dependency ordering',
  13. 'description' => 'Test that update functions are run in the proper order.',
  14. 'group' => 'Update API',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp('update_test_1', 'update_test_2', 'update_test_3');
  19. require_once DRUPAL_ROOT . '/includes/update.inc';
  20. }
  21. /**
  22. * Test that updates within a single module run in the correct order.
  23. */
  24. function testUpdateOrderingSingleModule() {
  25. $starting_updates = array(
  26. 'update_test_1' => 7000,
  27. );
  28. $expected_updates = array(
  29. 'update_test_1_update_7000',
  30. 'update_test_1_update_7001',
  31. 'update_test_1_update_7002',
  32. );
  33. $actual_updates = array_keys(update_resolve_dependencies($starting_updates));
  34. $this->assertEqual($expected_updates, $actual_updates, 'Updates within a single module run in the correct order.');
  35. }
  36. /**
  37. * Test that dependencies between modules are resolved correctly.
  38. */
  39. function testUpdateOrderingModuleInterdependency() {
  40. $starting_updates = array(
  41. 'update_test_2' => 7000,
  42. 'update_test_3' => 7000,
  43. );
  44. $update_order = array_keys(update_resolve_dependencies($starting_updates));
  45. // Make sure that each dependency is satisfied.
  46. $first_dependency_satisfied = array_search('update_test_2_update_7000', $update_order) < array_search('update_test_3_update_7000', $update_order);
  47. $this->assertTrue($first_dependency_satisfied, 'The dependency of the second module on the first module is respected by the update function order.');
  48. $second_dependency_satisfied = array_search('update_test_3_update_7000', $update_order) < array_search('update_test_2_update_7001', $update_order);
  49. $this->assertTrue($second_dependency_satisfied, 'The dependency of the first module on the second module is respected by the update function order.');
  50. }
  51. }
  52. /**
  53. * Tests for missing update dependencies.
  54. */
  55. class UpdateDependencyMissingTestCase extends DrupalWebTestCase {
  56. public static function getInfo() {
  57. return array(
  58. 'name' => 'Missing update dependencies',
  59. 'description' => 'Test that missing update dependencies are correctly flagged.',
  60. 'group' => 'Update API',
  61. );
  62. }
  63. function setUp() {
  64. // Only install update_test_2.module, even though its updates have a
  65. // dependency on update_test_3.module.
  66. parent::setUp('update_test_2');
  67. require_once DRUPAL_ROOT . '/includes/update.inc';
  68. }
  69. function testMissingUpdate() {
  70. $starting_updates = array(
  71. 'update_test_2' => 7000,
  72. );
  73. $update_graph = update_resolve_dependencies($starting_updates);
  74. $this->assertTrue($update_graph['update_test_2_update_7000']['allowed'], "The module's first update function is allowed to run, since it does not have any missing dependencies.");
  75. $this->assertFalse($update_graph['update_test_2_update_7001']['allowed'], "The module's second update function is not allowed to run, since it has a direct dependency on a missing update.");
  76. $this->assertFalse($update_graph['update_test_2_update_7002']['allowed'], "The module's third update function is not allowed to run, since it has an indirect dependency on a missing update.");
  77. }
  78. }
  79. /**
  80. * Tests for the invocation of hook_update_dependencies().
  81. */
  82. class UpdateDependencyHookInvocationTestCase extends DrupalWebTestCase {
  83. public static function getInfo() {
  84. return array(
  85. 'name' => 'Update dependency hook invocation',
  86. 'description' => 'Test that the hook invocation for determining update dependencies works correctly.',
  87. 'group' => 'Update API',
  88. );
  89. }
  90. function setUp() {
  91. parent::setUp('update_test_1', 'update_test_2');
  92. require_once DRUPAL_ROOT . '/includes/update.inc';
  93. }
  94. /**
  95. * Test the structure of the array returned by hook_update_dependencies().
  96. */
  97. function testHookUpdateDependencies() {
  98. $update_dependencies = update_retrieve_dependencies();
  99. $this->assertTrue($update_dependencies['system'][7000]['update_test_1'] == 7000, 'An update function that has a dependency on two separate modules has the first dependency recorded correctly.');
  100. $this->assertTrue($update_dependencies['system'][7000]['update_test_2'] == 7001, 'An update function that has a dependency on two separate modules has the second dependency recorded correctly.');
  101. $this->assertTrue($update_dependencies['system'][7001]['update_test_1'] == 7002, '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.');
  102. }
  103. }