protected function UpdateTestBase::assertSecurityUpdates in Drupal 8
Same name and namespace in other branches
- 9 core/modules/update/tests/src/Functional/UpdateTestBase.php \Drupal\Tests\update\Functional\UpdateTestBase::assertSecurityUpdates()
- 10 core/modules/update/tests/src/Functional/UpdateTestBase.php \Drupal\Tests\update\Functional\UpdateTestBase::assertSecurityUpdates()
Asserts the expected security updates are displayed correctly on the page.
Parameters
string $project_path_part: The project path part needed for the download and release links.
string[] $expected_security_releases: The security releases, if any, that the status report should recommend.
string $expected_update_message_type: The type of update message expected.
string $update_element_css_locator: The CSS locator for the page element that contains the security updates.
2 calls to UpdateTestBase::assertSecurityUpdates()
- UpdateContribTest::testSecurityUpdateAvailability in core/
modules/ update/ tests/ src/ Functional/ UpdateContribTest.php - Tests update status of security releases.
- UpdateCoreTest::testSecurityUpdateAvailability in core/
modules/ update/ tests/ src/ Functional/ UpdateCoreTest.php - Tests the Update Manager module when a security update is available.
File
- core/
modules/ update/ tests/ src/ Functional/ UpdateTestBase.php, line 126
Class
- UpdateTestBase
- Defines some shared functions used by all update tests.
Namespace
Drupal\Tests\update\FunctionalCode
protected function assertSecurityUpdates($project_path_part, array $expected_security_releases, $expected_update_message_type, $update_element_css_locator) {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->standardTests();
$assert_session
->elementTextNotContains('css', $update_element_css_locator, 'Not supported');
$all_security_release_urls = array_map(function ($link) {
return $link
->getAttribute('href');
}, $page
->findAll('css', "{$update_element_css_locator} .version-security a[href\$='-release']"));
$all_security_download_urls = array_map(function ($link) {
return $link
->getAttribute('href');
}, $page
->findAll('css', "{$update_element_css_locator} .version-security a[href\$='.tar.gz']"));
if ($expected_security_releases) {
$expected_download_urls = [];
$expected_release_urls = [];
if ($expected_update_message_type === static::SECURITY_UPDATE_REQUIRED) {
$assert_session
->elementTextNotContains('css', $update_element_css_locator, 'Update available');
$assert_session
->elementTextContains('css', $update_element_css_locator, 'Security update required!');
$assert_session
->responseContains('error.svg', 'Error icon was found.');
}
else {
$assert_session
->elementTextContains('css', $update_element_css_locator, 'Update available');
$assert_session
->elementTextNotContains('css', $update_element_css_locator, 'Security update required!');
}
$assert_session
->elementTextNotContains('css', $update_element_css_locator, 'Up to date');
foreach ($expected_security_releases as $expected_security_release) {
$expected_url_version = str_replace('.', '-', $expected_security_release);
$release_url = "http://example.com/{$project_path_part}-{$expected_url_version}-release";
$download_url = "http://example.com/{$project_path_part}-{$expected_url_version}.tar.gz";
$expected_release_urls[] = $release_url;
$expected_download_urls[] = $download_url;
// Ensure the expected links are security links.
$this
->assertContains($release_url, $all_security_release_urls, "Release {$release_url} is a security release link.");
$this
->assertContains($download_url, $all_security_download_urls, "Release {$download_url} is a security download link.");
$assert_session
->linkByHrefExists($release_url);
$assert_session
->linkByHrefExists($download_url);
}
// Ensure no other links are shown as security releases.
$this
->assertEquals([], array_diff($all_security_release_urls, $expected_release_urls));
$this
->assertEquals([], array_diff($all_security_download_urls, $expected_download_urls));
}
else {
// Ensure there were no security links.
$this
->assertEquals([], $all_security_release_urls);
$this
->assertEquals([], $all_security_download_urls);
$assert_session
->pageTextNotContains('Security update required!');
if ($expected_update_message_type === static::UPDATE_AVAILABLE) {
$assert_session
->elementTextContains('css', $update_element_css_locator, 'Update available');
$assert_session
->elementTextNotContains('css', $update_element_css_locator, 'Up to date');
}
elseif ($expected_update_message_type === static::UPDATE_NONE) {
$assert_session
->elementTextNotContains('css', $update_element_css_locator, 'Update available');
$assert_session
->elementTextContains('css', $update_element_css_locator, 'Up to date');
}
else {
$this
->fail('Unexpected value for $expected_update_message_type: ' . $expected_update_message_type);
}
}
}