summaryrefslogtreecommitdiffstats
path: root/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php
blob: 6bd15345251a8eaf5fbd9987869dc2ebe117cdf0 (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
<?php

/**
 * @file
 * Definition of Drupal\system\Tests\Update\DependencyOrderingTest.
 */

namespace Drupal\system\Tests\Update;

use Drupal\simpletest\WebTestBase;

/**
 * Tests for the update dependency ordering system.
 */
class DependencyOrderingTest extends WebTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('update_test_1', 'update_test_2', 'update_test_3');

  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();
    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.'));
  }
}