db backup prior to drupal security update
[yaffs-website] / web / core / modules / system / src / Tests / Update / DependencyOrderingTest.php
1 <?php
2
3 namespace Drupal\system\Tests\Update;
4
5 use Drupal\simpletest\WebTestBase;
6
7 /**
8  * Tests that update functions are run in the proper order.
9  *
10  * @group Update
11  */
12 class DependencyOrderingTest extends WebTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['update_test_0', 'update_test_1', 'update_test_2', 'update_test_3'];
20
21   protected function setUp() {
22     parent::setUp();
23     require_once \Drupal::root() . '/core/includes/update.inc';
24   }
25
26   /**
27    * Test that updates within a single module run in the correct order.
28    */
29   public function testUpdateOrderingSingleModule() {
30     $starting_updates = [
31       'update_test_1' => 8001,
32     ];
33     $expected_updates = [
34       'update_test_1_update_8001',
35       'update_test_1_update_8002',
36       'update_test_1_update_8003',
37     ];
38     $actual_updates = array_keys(update_resolve_dependencies($starting_updates));
39     $this->assertEqual($expected_updates, $actual_updates, 'Updates within a single module run in the correct order.');
40   }
41
42   /**
43    * Test that dependencies between modules are resolved correctly.
44    */
45   public function testUpdateOrderingModuleInterdependency() {
46     $starting_updates = [
47       'update_test_2' => 8001,
48       'update_test_3' => 8001,
49     ];
50     $update_order = array_keys(update_resolve_dependencies($starting_updates));
51     // Make sure that each dependency is satisfied.
52     $first_dependency_satisfied = array_search('update_test_2_update_8001', $update_order) < array_search('update_test_3_update_8001', $update_order);
53     $this->assertTrue($first_dependency_satisfied, 'The dependency of the second module on the first module is respected by the update function order.');
54     $second_dependency_satisfied = array_search('update_test_3_update_8001', $update_order) < array_search('update_test_2_update_8002', $update_order);
55     $this->assertTrue($second_dependency_satisfied, 'The dependency of the first module on the second module is respected by the update function order.');
56   }
57
58 }