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