Projet

Général

Profil

Paste
Télécharger (4,69 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / update.test @ db2d93dd

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for the update system.
6
 */
7

    
8
/**
9
 * Tests for the update dependency ordering system.
10
 */
11
class UpdateDependencyOrderingTestCase extends DrupalWebTestCase {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Update dependency ordering',
15
      'description' => 'Test that update functions are run in the proper order.',
16
      'group' => 'Update API',
17
    );
18
  }
19

    
20
  function setUp() {
21
    parent::setUp('update_test_1', 'update_test_2', 'update_test_3');
22
    require_once DRUPAL_ROOT . '/includes/update.inc';
23
  }
24

    
25
  /**
26
   * Test that updates within a single module run in the correct order.
27
   */
28
  function testUpdateOrderingSingleModule() {
29
    $starting_updates = array(
30
      'update_test_1' => 7000,
31
    );
32
    $expected_updates = array(
33
      'update_test_1_update_7000',
34
      'update_test_1_update_7001',
35
      'update_test_1_update_7002',
36
    );
37
    $actual_updates = array_keys(update_resolve_dependencies($starting_updates));
38
    $this->assertEqual($expected_updates, $actual_updates, 'Updates within a single module run in the correct order.');
39
  }
40

    
41
  /**
42
   * Test that dependencies between modules are resolved correctly.
43
   */
44
  function testUpdateOrderingModuleInterdependency() {
45
    $starting_updates = array(
46
      'update_test_2' => 7000,
47
      'update_test_3' => 7000,
48
    );
49
    $update_order = array_keys(update_resolve_dependencies($starting_updates));
50
    // Make sure that each dependency is satisfied.
51
    $first_dependency_satisfied = array_search('update_test_2_update_7000', $update_order) < array_search('update_test_3_update_7000', $update_order);
52
    $this->assertTrue($first_dependency_satisfied, 'The dependency of the second module on the first module is respected by the update function order.');
53
    $second_dependency_satisfied = array_search('update_test_3_update_7000', $update_order) < array_search('update_test_2_update_7001', $update_order);
54
    $this->assertTrue($second_dependency_satisfied, 'The dependency of the first module on the second module is respected by the update function order.');
55
  }
56
}
57

    
58
/**
59
 * Tests for missing update dependencies.
60
 */
61
class UpdateDependencyMissingTestCase extends DrupalWebTestCase {
62
  public static function getInfo() {
63
    return array(
64
      'name' => 'Missing update dependencies',
65
      'description' => 'Test that missing update dependencies are correctly flagged.',
66
      'group' => 'Update API',
67
    );
68
  }
69

    
70
  function setUp() {
71
    // Only install update_test_2.module, even though its updates have a
72
    // dependency on update_test_3.module.
73
    parent::setUp('update_test_2');
74
    require_once DRUPAL_ROOT . '/includes/update.inc';
75
  }
76

    
77
  function testMissingUpdate() {
78
    $starting_updates = array(
79
      'update_test_2' => 7000,
80
    );
81
    $update_graph = update_resolve_dependencies($starting_updates);
82
    $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.");
83
    $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.");
84
    $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.");
85
  }
86
}
87

    
88
/**
89
 * Tests for the invocation of hook_update_dependencies().
90
 */
91
class UpdateDependencyHookInvocationTestCase extends DrupalWebTestCase {
92
  public static function getInfo() {
93
    return array(
94
      'name' => 'Update dependency hook invocation',
95
      'description' => 'Test that the hook invocation for determining update dependencies works correctly.',
96
      'group' => 'Update API',
97
    );
98
  }
99

    
100
  function setUp() {
101
    parent::setUp('update_test_1', 'update_test_2');
102
    require_once DRUPAL_ROOT . '/includes/update.inc';
103
  }
104

    
105
  /**
106
   * Test the structure of the array returned by hook_update_dependencies().
107
   */
108
  function testHookUpdateDependencies() {
109
    $update_dependencies = update_retrieve_dependencies();
110
    $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.');
111
    $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.');
112
    $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.');
113
  }
114
}
115