Commit d5bd2eca authored by effulgentsia's avatar effulgentsia

Issue #2581459 by alexpott: UpdatePostUpdateTest is extremely fragile to...

Issue #2581459 by alexpott: UpdatePostUpdateTest is extremely fragile to change and does not test batches in post updates
parent 1cd13a8f
......@@ -7,6 +7,8 @@
namespace Drupal\system\Tests\Update;
use Drupal\Component\Render\FormattableMarkup;
/**
* Tests hook_post_update().
*
......@@ -32,7 +34,7 @@ protected function doSelectionTest() {
// Ensure that normal and post_update updates are merged together on the
// selection page.
$this->assertRaw('<ul><li>8001 - Normal update_N() function. </li><li>First update.</li><li>Second update.</li><li>Test1 update.</li><li>Test0 update.</li></ul>');
$this->assertRaw('<ul><li>8001 - Normal update_N() function. </li><li>First update.</li><li>Second update.</li><li>Test1 update.</li><li>Test0 update.</li><li>Testing batch processing in post updates update.</li></ul>');
}
/**
......@@ -49,24 +51,34 @@ public function testPostUpdate() {
$this->assertRaw('Test1 update');
$this->assertRaw('<h3>Update test0</h3>');
$this->assertRaw('Test0 update');
$this->assertRaw('<h3>Update test_batch</h3>');
$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.');
......
......@@ -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';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment