Commit 38110948 authored by xjm's avatar xjm

Issue #2995076 by mikelutz, benjamindamron, mradcliffe, xjm, samuel.mortenson,...

Issue #2995076 by mikelutz, benjamindamron, mradcliffe, xjm, samuel.mortenson, tedbow: Let UpdateTestBase check for multiple status messages

(cherry picked from commit cd9f5a7d)
parent e7862f1e
......@@ -445,14 +445,14 @@ public function testHookUpdateStatusAlter() {
* The module version the site is using.
* @param string[] $expected_security_releases
* The security releases, if any, that the status report should recommend.
* @param bool $update_available
* Whether an update should be available.
* @param string $expected_update_message_type
* The type of update message expected.
* @param string $fixture
* The fixture file to use.
*
* @dataProvider securityUpdateAvailabilityProvider
*/
public function testSecurityUpdateAvailability($module_version, array $expected_security_releases, $update_available, $fixture) {
public function testSecurityUpdateAvailability($module_version, array $expected_security_releases, $expected_update_message_type, $fixture) {
$system_info = [
'#all' => [
'version' => '8.0.0',
......@@ -465,7 +465,7 @@ public function testSecurityUpdateAvailability($module_version, array $expected_
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$this->refreshUpdateStatus(['drupal' => '0.0', 'aaa_update_test' => $fixture]);
$this->assertSecurityUpdates('aaa_update_test', $expected_security_releases, $update_available, 'table.update:nth-of-type(2)');
$this->assertSecurityUpdates('aaa_update_test', $expected_security_releases, $expected_update_message_type, 'table.update:nth-of-type(2)');
}
/**
......@@ -505,7 +505,7 @@ public function securityUpdateAvailabilityProvider() {
'8.x-1.0, 8.x-1.2' => [
'module_patch_version' => '8.x-1.0',
'expected_security_releases' => ['8.x-1.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.8.x-1.2',
],
// Two security releases available for module major release 1.
......@@ -514,7 +514,7 @@ public function securityUpdateAvailabilityProvider() {
'8.x-1.0, 8.x-1.1 8.x-1.2' => [
'module_patch_version' => '8.x-1.0',
'expected_security_releases' => ['8.x-1.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.8.x-1.1_8.x-1.2',
],
// Security release available for module major release 2.
......@@ -522,13 +522,13 @@ public function securityUpdateAvailabilityProvider() {
'8.x-2.0, 8.x-2.2' => [
'module_patch_version' => '8.x-2.0',
'expected_security_releases' => ['8.x-2.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.8.x-2.2_1.x_secure',
],
'8.x-2.2, 8.x-1.2 8.x-2.2' => [
'module_patch_version' => '8.x-2.2',
'expected_security_releases' => [],
'update_available' => FALSE,
'expected_update_message_type' => static::UPDATE_NONE,
'fixture' => 'sec.8.x-1.2_8.x-2.2',
],
// Security release available for module major release 1.
......@@ -536,7 +536,7 @@ public function securityUpdateAvailabilityProvider() {
'8.x-1.0, 8.x-1.2 8.x-2.2' => [
'module_patch_version' => '8.x-1.0',
'expected_security_releases' => ['8.x-1.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.8.x-1.2_8.x-2.2',
],
// No security release available for module major release 1 but 1.x
......@@ -545,7 +545,7 @@ public function securityUpdateAvailabilityProvider() {
'8.x-1.0, 8.x-2.2, not insecure' => [
'module_patch_version' => '8.x-1.0',
'expected_security_releases' => [],
'update_available' => TRUE,
'expected_update_message_type' => static::UPDATE_AVAILABLE,
'fixture' => 'sec.8.x-2.2_1.x_secure',
],
// @todo In https://www.drupal.org/node/2865920 add test cases:
......
......@@ -165,17 +165,17 @@ public function testMajorUpdateAvailable() {
* The patch version to set the site to for testing.
* @param string[] $expected_security_releases
* The security releases, if any, that the status report should recommend.
* @param bool $update_available
* Whether an update is available.
* @param string $expected_update_message_type
* The type of update message expected.
* @param string $fixture
* The test fixture that contains the test XML.
*
* @dataProvider securityUpdateAvailabilityProvider
*/
public function testSecurityUpdateAvailability($site_patch_version, array $expected_security_releases, $update_available, $fixture) {
public function testSecurityUpdateAvailability($site_patch_version, array $expected_security_releases, $expected_update_message_type, $fixture) {
$this->setSystemInfo("8.$site_patch_version");
$this->refreshUpdateStatus(['drupal' => $fixture]);
$this->assertSecurityUpdates('drupal-8', $expected_security_releases, $update_available, 'table.update');
$this->assertSecurityUpdates('drupal-8', $expected_security_releases, $expected_update_message_type, 'table.update');
}
/**
......@@ -239,7 +239,7 @@ public function securityUpdateAvailabilityProvider() {
'0.0, 0.2' => [
'site_patch_version' => '0.0',
'expected_security_releases' => ['0.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.0.2',
],
// Two security releases available for site minor release 0.
......@@ -248,7 +248,7 @@ public function securityUpdateAvailabilityProvider() {
'0.0, 0.1 0.2' => [
'site_patch_version' => '0.0',
'expected_security_releases' => ['0.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.0.1_0.2',
],
// Security release available for site minor release 1.
......@@ -256,7 +256,7 @@ public function securityUpdateAvailabilityProvider() {
'1.0, 1.2' => [
'site_patch_version' => '1.0',
'expected_security_releases' => ['1.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.1.2',
],
// Security release available for site minor release 0.
......@@ -264,7 +264,7 @@ public function securityUpdateAvailabilityProvider() {
'0.0, 0.2 1.2' => [
'site_patch_version' => '0.0',
'expected_security_releases' => ['0.2', '1.2', '2.0-rc2'],
'update_available' => TRUE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.0.2-rc2',
],
// No newer security release for site minor 1.
......@@ -272,7 +272,7 @@ public function securityUpdateAvailabilityProvider() {
'1.2, 0.2 1.2' => [
'site_patch_version' => '1.2',
'expected_security_releases' => [],
'update_available' => FALSE,
'expected_update_message_type' => static::UPDATE_NONE,
// @todo Change to use fixture 'sec.0.2-rc2' in
// https://www.drupal.org/node/2804155. Currently this case would fail
// because 8.2.0-rc2 would be the recommend security release.
......@@ -283,14 +283,14 @@ public function securityUpdateAvailabilityProvider() {
'0.0, 1.2, insecure' => [
'site_patch_version' => '0.0',
'expected_security_releases' => ['1.2'],
'update_available' => FALSE,
'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
'fixture' => 'sec.1.2_insecure',
],
// Site on 2.0-rc2 which is a security release.
'2.0-rc2, 0.2 1.2' => [
'site_patch_version' => '2.0-rc2',
'expected_security_releases' => [],
'update_available' => FALSE,
'expected_update_message_type' => static::UPDATE_NONE,
'fixture' => 'sec.0.2-rc2',
],
];
......@@ -310,7 +310,7 @@ public function securityUpdateAvailabilityProvider() {
$test_cases["Pre-release:$pre_release, no security update"] = [
'site_patch_version' => $pre_release,
'expected_security_releases' => [],
'update_available' => $pre_release === '2.0-rc2' ? FALSE : TRUE,
'expected_update_message_type' => $pre_release === '2.0-rc2' ? static::UPDATE_NONE : static::UPDATE_AVAILABLE,
'fixture' => 'sec.0.2-rc2-b',
];
}
......
......@@ -25,6 +25,21 @@
*/
abstract class UpdateTestBase extends BrowserTestBase {
/**
* Denotes a security update will be required in the test case.
*/
const SECURITY_UPDATE_REQUIRED = 'SECURITY_UPDATE_REQUIRED';
/**
* Denotes an update will be available in the test case.
*/
const UPDATE_AVAILABLE = 'UPDATE_AVAILABLE';
/**
* Denotes no update will be available in the test case.
*/
const UPDATE_NONE = 'UPDATE_NONE';
protected function setUp() {
parent::setUp();
......@@ -84,14 +99,16 @@ protected function standardTests() {
/**
* Asserts the expected security updates are displayed correctly on the page.
*
* @param string $project_path_part
* The project path part needed for the download and release links.
* @param string[] $expected_security_releases
* The security releases, if any, that the status report should recommend.
* @param bool $update_available
* Whether an update should be available.
* @param $update_element_css_locator
* @param string $expected_update_message_type
* The type of update message expected.
* @param string $update_element_css_locator
* The CSS locator for the page element that contains the security updates.
*/
protected function assertSecurityUpdates($project, array $expected_security_releases, $update_available, $update_element_css_locator) {
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();
......@@ -105,13 +122,20 @@ protected function assertSecurityUpdates($project, array $expected_security_rele
if ($expected_security_releases) {
$expected_download_urls = [];
$expected_release_urls = [];
foreach ($expected_security_releases as $expected_security_release) {
$assert_session->elementTextNotContains('css', $update_element_css_locator, 'Up to date');
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-$expected_url_version-release";
$download_url = "http://example.com/$project-$expected_url_version.tar.gz";
$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.
......@@ -119,7 +143,6 @@ protected function assertSecurityUpdates($project, array $expected_security_rele
$this->assertTrue(in_array($download_url, $all_security_download_urls), "Release $download_url is a security download link.");
$assert_session->linkByHrefExists($release_url);
$assert_session->linkByHrefExists($download_url);
$assert_session->responseContains('error.svg', 'Error icon was found.');
}
// Ensure no other links are shown as security releases.
$this->assertEquals([], array_diff($all_security_release_urls, $expected_release_urls));
......@@ -130,14 +153,17 @@ protected function assertSecurityUpdates($project, array $expected_security_rele
$this->assertEquals([], $all_security_release_urls);
$this->assertEquals([], $all_security_download_urls);
$assert_session->pageTextNotContains('Security update required!');
if ($update_available) {
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');
}
else {
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);
}
}
}
......
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