function UpdateContribTest::testHookUpdateStatusAlter
Same name in other branches
- 9 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testHookUpdateStatusAlter()
- 8.9.x core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testHookUpdateStatusAlter()
- 11.x core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testHookUpdateStatusAlter()
Checks that hook_update_status_alter() works to change a status.
We provide the same external data as if aaa_update_test 8.x-1.0 were installed and that was the latest release. Then we use hook_update_status_alter() to try to mark this as missing a security update, then assert if we see the appropriate warnings on the right pages.
File
-
core/
modules/ update/ tests/ src/ Functional/ UpdateContribTest.php, line 497
Class
- UpdateContribTest
- Tests how the Update Manager handles contributed modules and themes.
Namespace
Drupal\Tests\update\FunctionalCode
public function testHookUpdateStatusAlter() : void {
$update_admin_user = $this->drupalCreateUser([
'administer site configuration',
'administer software updates',
]);
$this->drupalLogin($update_admin_user);
$this->mockInstalledExtensionsInfo([
'aaa_update_test' => [
'project' => 'aaa_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
],
]);
$this->mockDefaultExtensionsInfo([
'version' => '8.0.0',
]);
$update_test_config = $this->config('update_test.settings');
$update_status = [
'aaa_update_test' => [
'status' => UpdateManagerInterface::NOT_SECURE,
],
];
$update_test_config->set('update_status', $update_status)
->save();
$this->refreshUpdateStatus([
'drupal' => '8.0.0',
'aaa_update_test' => '1_0',
]);
$this->assertSession()
->responseContains('<h3>Modules</h3>');
$this->assertSession()
->pageTextContains('Security update required!');
$this->assertSession()
->linkExists('AAA Update test');
$this->assertSession()
->linkByHrefExists('http://example.com/project/aaa_update_test');
// Visit the reports page again without the altering and make sure the
// status is back to normal.
$update_test_config->set('update_status', [])
->save();
$this->drupalGet('admin/reports/updates');
$this->assertSession()
->responseContains('<h3>Modules</h3>');
$this->assertSession()
->pageTextNotContains('Security update required!');
$this->assertSession()
->linkExists('AAA Update test');
$this->assertSession()
->linkByHrefExists('http://example.com/project/aaa_update_test');
// Turn the altering back on and visit the Update manager UI.
$update_test_config->set('update_status', $update_status)
->save();
$this->drupalGet('admin/modules/update');
$this->assertSession()
->pageTextContains('Security update');
// Turn the altering back off and visit the Update manager UI.
$update_test_config->set('update_status', [])
->save();
$this->drupalGet('admin/modules/update');
$this->assertSession()
->pageTextNotContains('Security update');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.