diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 51fcdb0..d7bef10 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -197,7 +197,6 @@ function system_requirements($phase) { if ($phase === 'update') { $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => DRUPAL_MINIMUM_PHP]); $requirements['php']['severity'] = REQUIREMENT_WARNING; - return $requirements; } elseif (!$is_test_site) { $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => DRUPAL_MINIMUM_PHP]); diff --git a/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php b/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php index da215d4..a52274e 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php @@ -5,6 +5,7 @@ use Drupal\Core\Url; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\UpdateUiTrait; /** * Tests the update script access and functionality. @@ -13,6 +14,8 @@ */ class UpdateScriptTest extends BrowserTestBase { + use UpdateUiTrait; + /** * Modules to enable. * @@ -99,6 +102,7 @@ public function testRequirements() { // If there are no requirements warnings or errors, we expect to be able to // go through the update process uninterrupted. $this->drupalGet($this->updateUrl, ['external' => TRUE]); + $this->updateRequirementsProblem(); $this->clickLink(t('Continue')); $this->assertText(t('No pending updates.'), 'End of update process was reached.'); // Confirm that all caches were cleared. @@ -110,6 +114,7 @@ public function testRequirements() { // First, run this test with pending updates to make sure they can be run // successfully. + $this->drupalLogin($this->updateUser); $update_script_test_config->set('requirement_type', REQUIREMENT_WARNING)->save(); drupal_set_installed_schema_version('update_script_test', drupal_get_installed_schema_version('update_script_test') - 1); $this->drupalGet($this->updateUrl, ['external' => TRUE]); @@ -177,6 +182,7 @@ public function testNoUpdateFunctionality() { // Click through update.php with 'administer software updates' permission. $this->drupalLogin($this->updateUser); $this->drupalGet($this->updateUrl, ['external' => TRUE]); + $this->updateRequirementsProblem(); $this->clickLink(t('Continue')); $this->assertText(t('No pending updates.')); $this->assertNoLink('Administration pages'); @@ -188,6 +194,7 @@ public function testNoUpdateFunctionality() { $admin_user = $this->drupalCreateUser(['administer software updates', 'access administration pages']); $this->drupalLogin($admin_user); $this->drupalGet($this->updateUrl, ['external' => TRUE]); + $this->updateRequirementsProblem(); $this->clickLink(t('Continue')); $this->assertText(t('No pending updates.')); $this->assertLink('Administration pages'); @@ -220,6 +227,7 @@ public function testSuccessfulUpdateFunctionality() { $admin_user = $this->drupalCreateUser(['administer software updates', 'access administration pages', 'access site reports', 'access site in maintenance mode']); $this->drupalLogin($admin_user); $this->drupalGet($this->updateUrl, ['external' => TRUE]); + $this->updateRequirementsProblem(); $this->clickLink(t('Continue')); $this->clickLink(t('Apply pending updates')); $this->checkForMetaRefresh(); @@ -287,6 +295,7 @@ public function testSuccessfulMultilingualUpdateFunctionality() { // Click through update.php with 'access administration pages' and // 'access site reports' permissions. $this->drupalGet($this->updateUrl, ['external' => TRUE]); + $this->updateRequirementsProblem(); $this->clickLink(t('Continue')); $this->clickLink(t('Apply pending updates')); $this->checkForMetaRefresh(); @@ -319,6 +328,7 @@ protected function runUpdates($maintenance_mode) { $this->assertNoText('Operating in maintenance mode.'); } $this->drupalGet($this->updateUrl, ['external' => TRUE]); + $this->updateRequirementsProblem(); $this->clickLink(t('Continue')); $this->clickLink(t('Apply pending updates')); $this->checkForMetaRefresh(); diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php index 99963a7..d795f6b 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @@ -10,6 +10,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Language\Language; use Drupal\Core\Url; +use Drupal\Tests\UpdateUiTrait; use Drupal\user\Entity\User; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; @@ -42,6 +43,7 @@ abstract class UpdatePathTestBase extends BrowserTestBase { use SchemaCheckTestTrait; + use UpdateUiTrait; /** * Modules to enable after the database is loaded. @@ -389,57 +391,6 @@ protected function runUpdates() { } /** - * Tests the requirements page. - */ - protected function updateRequirementsProblem() { - // By default, skip the PHP version warning on older test environments. - if (version_compare(phpversion(), '7.0') < 0) { - $this->continueOnExpectedWarnings(['PHP']); - } - } - - /** - * Continues installation when an expected warning is found. - * - * @param string[] $expected_warnings - * A list of warning summaries to expect on the requirements screen (e.g. - * 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings - * are found, the test will click the "try again" link to go to the - * next screen of the update. If an expected warning is not found, or if - * a warning not in the list is present, a fail is raised. - */ - protected function continueOnExpectedWarnings($expected_warnings = []) { - // Don't try to continue if there are errors. - if (strpos($this->getTextContent(), 'Errors found') !== FALSE) { - return; - } - // Allow only details elements that are directly after the warning header - // or each other. There is no guaranteed wrapper we can rely on across - // distributions. When there are multiple warnings, the selectors will be: - // - h3#warning+details summary - // - h3#warning+details+details summary - // - etc. - // We add one more selector than expected warnings to confirm that there - // isn't any other warning before clicking the link. - // @todo Make this more reliable in - // https://www.drupal.org/project/drupal/issues/2927345. - $selectors = []; - for ($i = 0; $i <= count($expected_warnings); $i++) { - $selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary'; - } - $warning_elements = $this->cssSelect(implode(', ', $selectors)); - - // Confirm that there are only the expected warnings. - $warnings = []; - foreach ($warning_elements as $warning) { - $warnings[] = trim($warning->getText()); - } - $this->assertEquals($expected_warnings, $warnings); - $this->clickLink('try again'); - $this->checkForMetaRefresh(); - } - - /** * Runs the install database tasks for the driver used by the test runner. */ protected function runDbTasks() { diff --git a/core/tests/Drupal/Tests/UpdateUiTrait.php b/core/tests/Drupal/Tests/UpdateUiTrait.php new file mode 100644 index 0000000..1736ab0 --- /dev/null +++ b/core/tests/Drupal/Tests/UpdateUiTrait.php @@ -0,0 +1,61 @@ +continueOnExpectedWarnings(['PHP']); + } + } + + /** + * Continues installation when an expected warning is found. + * + * @param string[] $expected_warnings + * A list of warning summaries to expect on the requirements screen (e.g. + * 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings + * are found, the test will click the "try again" link to go to the + * next screen of the update. If an expected warning is not found, or if + * a warning not in the list is present, a fail is raised. + */ + protected function continueOnExpectedWarnings($expected_warnings = []) { + // Don't try to continue if there are errors. + if (strpos($this->getTextContent(), 'Errors found') !== FALSE) { + return; + } + // Allow only details elements that are directly after the warning header + // or each other. There is no guaranteed wrapper we can rely on across + // distributions. When there are multiple warnings, the selectors will be: + // - h3#warning+details summary + // - h3#warning+details+details summary + // - etc. + // We add one more selector than expected warnings to confirm that there + // isn't any other warning before clicking the link. + // @todo Make this more reliable in + // https://www.drupal.org/project/drupal/issues/2927345. + $selectors = []; + for ($i = 0; $i <= count($expected_warnings); $i++) { + $selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary'; + } + $warning_elements = $this->cssSelect(implode(', ', $selectors)); + + // Confirm that there are only the expected warnings. + $warnings = []; + foreach ($warning_elements as $warning) { + $warnings[] = trim($warning->getText()); + } + $this->assertEquals($expected_warnings, $warnings); + $this->clickLink('try again'); + $this->checkForMetaRefresh(); + } + +}