function UpdatePostUpdateTest::testPostUpdate
Same name in other branches
- 8.9.x core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdatePostUpdateTest::testPostUpdate()
- 10 core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdatePostUpdateTest::testPostUpdate()
- 11.x core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdatePostUpdateTest::testPostUpdate()
Tests hook_post_update_NAME().
File
-
core/
modules/ system/ tests/ src/ Functional/ UpdateSystem/ UpdatePostUpdateTest.php, line 76
Class
- UpdatePostUpdateTest
- Tests hook_post_update().
Namespace
Drupal\Tests\system\Functional\UpdateSystemCode
public function testPostUpdate() {
$this->runUpdates();
$this->assertSession()
->responseContains('<h3>Update first</h3>');
$this->assertSession()
->pageTextContains('First update');
$this->assertSession()
->responseContains('<h3>Update second</h3>');
$this->assertSession()
->pageTextContains('Second update');
$this->assertSession()
->responseContains('<h3>Update test1</h3>');
$this->assertSession()
->pageTextContains('Test1 update');
$this->assertSession()
->responseContains('<h3>Update test0</h3>');
$this->assertSession()
->pageTextContains('Test0 update');
$this->assertSession()
->responseContains('<h3>Update test_batch</h3>');
$this->assertSession()
->pageTextContains('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_test0',
'update_test_postupdate_post_update_test1',
'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->assertSame($updates, \Drupal::state()->get('post_update_test_execution', []));
// 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->assertEquals(1, $existing_updates[$expected_update], new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", [
'@expected_update' => $expected_update,
]));
}
$this->drupalGet('update.php/selection');
$this->updateRequirementsProblem();
$this->drupalGet('update.php/selection');
$this->assertSession()
->pageTextContains('No pending updates.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.