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