diff --git a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php
index 67b2ba2a9af8..85f3247ffcc7 100644
--- a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php
+++ b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php
@@ -7,6 +7,8 @@
namespace Drupal\system\Tests\Update;
+use Drupal\Component\Render\FormattableMarkup;
+
/**
* Tests hook_post_update().
*
@@ -32,7 +34,7 @@ class UpdatePostUpdateTest extends UpdatePathTestBase {
// Ensure that normal and post_update updates are merged together on the
// selection page.
- $this->assertRaw('
- 8001 - Normal update_N() function.
- First update.
- Second update.
- Test1 update.
- Test0 update.
');
+ $this->assertRaw('- 8001 - Normal update_N() function.
- First update.
- Second update.
- Test1 update.
- Test0 update.
- Testing batch processing in post updates update.
');
}
/**
@@ -49,24 +51,34 @@ class UpdatePostUpdateTest extends UpdatePathTestBase {
$this->assertRaw('Test1 update');
$this->assertRaw('Update test0
');
$this->assertRaw('Test0 update');
+ $this->assertRaw('Update test_batch
');
+ $this->assertRaw('Test post update batches');
+ // Test state value set by each post update.
$updates = [
'update_test_postupdate_post_update_first',
'update_test_postupdate_post_update_second',
'update_test_postupdate_post_update_test1',
'update_test_postupdate_post_update_test0',
+ 'update_test_postupdate_post_update_test_batch-1',
+ 'update_test_postupdate_post_update_test_batch-2',
+ 'update_test_postupdate_post_update_test_batch-3',
];
$this->assertIdentical($updates, \Drupal::state()->get('post_update_test_execution', []));
- $key_value = \Drupal::keyValue('post_update');
- $updates = array_merge([
- 'block_post_update_disable_blocks_with_missing_contexts',
- 'field_post_update_save_custom_storage_property',
- 'field_post_update_entity_reference_handler_setting',
- 'system_post_update_recalculate_configuration_entity_dependencies',
- 'views_post_update_update_cacheability_metadata',
- ], $updates);
- $this->assertEqual($updates, $key_value->get('existing_updates'));
+ // Test post_update key value stores contains a list of the update functions
+ // that have run.
+ $existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_updates'));
+ $expected_updates = [
+ 'update_test_postupdate_post_update_first',
+ 'update_test_postupdate_post_update_second',
+ 'update_test_postupdate_post_update_test1',
+ 'update_test_postupdate_post_update_test0',
+ 'update_test_postupdate_post_update_test_batch',
+ ];
+ foreach ($expected_updates as $expected_update) {
+ $this->assertEqual($existing_updates[$expected_update], 1, new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", ['@expected_update' => $expected_update]));
+ }
$this->drupalGet('update.php/selection');
$this->assertText('No pending updates.');
diff --git a/core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.post_update.php b/core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.post_update.php
index e914cac8c02d..ece8b7e8b387 100644
--- a/core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.post_update.php
+++ b/core/modules/system/tests/modules/update_test_postupdate/update_test_postupdate.post_update.php
@@ -43,3 +43,22 @@ function update_test_postupdate_post_update_test0() {
return 'Test0 update';
}
+
+/**
+ * Testing batch processing in post updates update.
+ */
+function update_test_postupdate_post_update_test_batch(&$sandbox = NULL) {
+ if (!isset($sandbox['steps'])) {
+ $sandbox['current_step'] = 0;
+ $sandbox['steps'] = 3;
+ }
+
+ $sandbox['current_step']++;
+
+ $execution = \Drupal::state()->get('post_update_test_execution', []);
+ $execution[] = __FUNCTION__ . '-' . $sandbox['current_step'];
+ \Drupal::state()->set('post_update_test_execution', $execution);
+
+ $sandbox['#finished'] = $sandbox['current_step'] / $sandbox['steps'];
+ return 'Test post update batches';
+}