3 namespace Drupal\Tests\system\Functional\Update;
5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
9 * Tests hook_post_update().
13 class UpdatePostUpdateTest extends UpdatePathTestBase {
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',
28 protected function doSelectionTest() {
29 parent::doSelectionTest();
31 // Ensure that normal and post_update updates are merged together on the
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>');
37 * Tests hook_post_update_NAME().
39 public function testPostUpdate() {
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');
53 // Test state value set by each post update.
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',
63 $this->assertIdentical($updates, \Drupal::state()->get('post_update_test_execution', []));
65 // Test post_update key value stores contains a list of the update functions
67 $existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_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',
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]));
79 $this->drupalGet('update.php/selection');
80 $this->assertText('No pending updates.');