summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/update.test
blob: c4d3828473355033dd62be045c8ed3a138ac4ef5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// $Id$

/**
 * @file
 * Tests for the update system.
 */

/**
 * Tests for the update dependency ordering system.
 */
class UpdateDependencyOrderingTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => '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 . '/includes/update.inc';
  }

  /**
   * Test that updates within a single module run in the correct order.
   */
  function testUpdateOrderingSingleModule() {
    $starting_updates = array(
      'update_test_1' => 7000,
    );
    $expected_updates = array(
      'update_test_1_update_7000',
      'update_test_1_update_7001',
      'update_test_1_update_7002',
    );
    $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' => 7000,
      'update_test_3' => 7000,
    );
    $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_7000', $update_order) < array_search('update_test_3_update_7000', $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_7000', $update_order) < array_search('update_test_2_update_7001', $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 DrupalWebTestCase {
  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 . '/includes/update.inc';
  }

  function testMissingUpdate() {
    $starting_updates = array(
      'update_test_2' => 7000,
    );
    $update_graph = update_resolve_dependencies($starting_updates);
    $this->assertTrue($update_graph['update_test_2_update_7000']['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_7001']['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_7002']['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 DrupalWebTestCase {
  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 . '/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'][7000]['update_test_1'] == 7000, t('An update function that has a dependency on two separate modules has the first dependency recorded correctly.'));
    $this->assertTrue($update_dependencies['system'][7000]['update_test_2'] == 7001, t('An update function that has a dependency on two separate modules has the second dependency recorded correctly.'));
    $this->assertTrue($update_dependencies['system'][7001]['update_test_1'] == 7002, 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.'));
  }
}