Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / UpdatePostUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
7
8 /**
9  * Tests hook_post_update().
10  *
11  * @group Update
12  * @group legacy
13  */
14 class UpdatePostUpdateTest extends UpdatePathTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function setDatabaseDumpFiles() {
20     $this->databaseDumpFiles = [
21       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
22       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.update-test-postupdate-enabled.php',
23     ];
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function doSelectionTest() {
30     parent::doSelectionTest();
31
32     // Ensure that normal and post_update updates are merged together on the
33     // selection page.
34     $this->assertRaw('<ul><li>8001 -   Normal update_N() function. </li><li>First update.</li><li>Second update.</li><li>Test0 update.</li><li>Test1 update.</li><li>Testing batch processing in post updates update.</li></ul>');
35   }
36
37   /**
38    * Tests hook_post_update_NAME().
39    */
40   public function testPostUpdate() {
41     $this->runUpdates();
42
43     $this->assertRaw('<h3>Update first</h3>');
44     $this->assertRaw('First update');
45     $this->assertRaw('<h3>Update second</h3>');
46     $this->assertRaw('Second update');
47     $this->assertRaw('<h3>Update test1</h3>');
48     $this->assertRaw('Test1 update');
49     $this->assertRaw('<h3>Update test0</h3>');
50     $this->assertRaw('Test0 update');
51     $this->assertRaw('<h3>Update test_batch</h3>');
52     $this->assertRaw('Test post update batches');
53
54     // Test state value set by each post update.
55     $updates = [
56       'update_test_postupdate_post_update_first',
57       'update_test_postupdate_post_update_second',
58       'update_test_postupdate_post_update_test0',
59       'update_test_postupdate_post_update_test1',
60       'update_test_postupdate_post_update_test_batch-1',
61       'update_test_postupdate_post_update_test_batch-2',
62       'update_test_postupdate_post_update_test_batch-3',
63     ];
64     $this->assertIdentical($updates, \Drupal::state()->get('post_update_test_execution', []));
65
66     // Test post_update key value stores contains a list of the update functions
67     // that have run.
68     $existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_updates'));
69     $expected_updates = [
70       'update_test_postupdate_post_update_first',
71       'update_test_postupdate_post_update_second',
72       'update_test_postupdate_post_update_test1',
73       'update_test_postupdate_post_update_test0',
74       'update_test_postupdate_post_update_test_batch',
75     ];
76     foreach ($expected_updates as $expected_update) {
77       $this->assertEqual($existing_updates[$expected_update], 1, new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", ['@expected_update' => $expected_update]));
78     }
79
80     $this->drupalGet('update.php/selection');
81     $this->assertText('No pending updates.');
82   }
83
84 }