Issue #2581459 by alexpott: UpdatePostUpdateTest is extremely fragile to change and does not test batches in post updates

8.0.x
effulgentsia 2015-10-09 11:33:46 -07:00
parent 1cd13a8f53
commit d5bd2eca3b
2 changed files with 41 additions and 10 deletions

View File

@ -7,6 +7,8 @@
namespace Drupal\system\Tests\Update; namespace Drupal\system\Tests\Update;
use Drupal\Component\Render\FormattableMarkup;
/** /**
* Tests hook_post_update(). * Tests hook_post_update().
* *
@ -32,7 +34,7 @@ class UpdatePostUpdateTest extends UpdatePathTestBase {
// Ensure that normal and post_update updates are merged together on the // Ensure that normal and post_update updates are merged together on the
// selection page. // 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 @@ class UpdatePostUpdateTest extends UpdatePathTestBase {
$this->assertRaw('Test1 update'); $this->assertRaw('Test1 update');
$this->assertRaw('<h3>Update test0</h3>'); $this->assertRaw('<h3>Update test0</h3>');
$this->assertRaw('Test0 update'); $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 = [ $updates = [
'update_test_postupdate_post_update_first', 'update_test_postupdate_post_update_first',
'update_test_postupdate_post_update_second', 'update_test_postupdate_post_update_second',
'update_test_postupdate_post_update_test1', 'update_test_postupdate_post_update_test1',
'update_test_postupdate_post_update_test0', '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', [])); $this->assertIdentical($updates, \Drupal::state()->get('post_update_test_execution', []));
$key_value = \Drupal::keyValue('post_update'); // Test post_update key value stores contains a list of the update functions
$updates = array_merge([ // that have run.
'block_post_update_disable_blocks_with_missing_contexts', $existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_updates'));
'field_post_update_save_custom_storage_property', $expected_updates = [
'field_post_update_entity_reference_handler_setting', 'update_test_postupdate_post_update_first',
'system_post_update_recalculate_configuration_entity_dependencies', 'update_test_postupdate_post_update_second',
'views_post_update_update_cacheability_metadata', 'update_test_postupdate_post_update_test1',
], $updates); 'update_test_postupdate_post_update_test0',
$this->assertEqual($updates, $key_value->get('existing_updates')); '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->drupalGet('update.php/selection');
$this->assertText('No pending updates.'); $this->assertText('No pending updates.');

View File

@ -43,3 +43,22 @@ function update_test_postupdate_post_update_test0() {
return 'Test0 update'; 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';
}