Commit c087641e authored by effulgentsia's avatar effulgentsia

Issue #3039287 by bendeguz.csirmaz, effulgentsia, xjm, alexpott, catch,...

Issue #3039287 by bendeguz.csirmaz, effulgentsia, xjm, alexpott, catch, jibran, hampercm, tedbow, Joseph Zhao, dawehner: Implement changes required to remove support for PHP 5.5 and 5.6
parent 96649b02
......@@ -18,15 +18,36 @@
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* Minimum supported version of PHP.
* Minimum allowed version of PHP.
*
* Below this version:
* - The installer cannot be run.
* - Updates cannot be run.
* - Modules and themes cannot be enabled.
* - If a site managed to bypass all of the above, then an error is shown in
* the status report and various fatal errors occur on various pages.
*
* Drupal cannot be installed on versions of PHP older than this version.
* @see install.php
*
* @todo Move this to an appropriate autoloadable class. See
* https://www.drupal.org/project/drupal/issues/2908079
*/
const DRUPAL_MINIMUM_PHP = '5.5.9';
/**
* Minimum supported version of PHP.
*
* Below this version:
* - New sites cannot be installed, except from within tests.
* - Updates from previous Drupal versions can be run, but users are warned
* that Drupal no longer supports that PHP version.
* - An error is shown in the status report that the PHP version is too old.
*
* @todo Move this to an appropriate autoloadable class. See
* https://www.drupal.org/project/drupal/issues/2908079
*/
const DRUPAL_MINIMUM_SUPPORTED_PHP = '7.0.8';
/**
* Minimum recommended version of PHP.
*
......
......@@ -4,6 +4,7 @@
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
/**
* Adds and configures languages to check field schema definition.
......@@ -12,6 +13,8 @@
*/
class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase {
use RequirementsPageTrait;
/**
* Modules to enable.
*
......@@ -83,6 +86,8 @@ public function testTranslatedUpdate() {
// markup and a link instead of specific text because text may be
// translated.
$this->drupalGet($update_url . '/selection', ['external' => TRUE]);
$this->updateRequirementsProblem();
$this->drupalGet($update_url . '/selection', ['external' => TRUE]);
$this->assertRaw('messages--status', 'No pending updates.');
$this->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.');
}
......
......@@ -8,6 +8,7 @@
use Drupal\Core\Language\Language;
use Drupal\Core\Session\UserSession;
use Drupal\Core\Site\Settings;
use Drupal\Tests\RequirementsPageTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
......@@ -22,6 +23,8 @@
*/
abstract class InstallerTestBase extends WebTestBase {
use RequirementsPageTrait;
/**
* Custom settings.php values to write for a test run.
*
......@@ -213,12 +216,7 @@ protected function setUpSettings() {
* @see system_requirements()
*/
protected function setUpRequirementsProblem() {
// By default, skip the "recommended PHP version" warning on older test
// environments. This allows the installer to be tested consistently on
// both recommended PHP versions and older (but still supported) versions.
if (version_compare(phpversion(), '7.0') < 0) {
$this->continueOnExpectedWarnings(['PHP']);
}
// Do nothing.
}
/**
......@@ -244,44 +242,4 @@ protected function refreshVariables() {
}
}
/**
* 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 "continue anyway" link to go to the
* next screen of the installer. 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((string) $warning);
}
$this->assertEqual($expected_warnings, $warnings);
$this->clickLink('continue anyway');
}
}
......@@ -24,7 +24,6 @@
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PrivateStream;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\system\SystemRequirements;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -186,36 +185,43 @@ function system_requirements($phase) {
];
}
if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) {
$requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => DRUPAL_MINIMUM_PHP]);
// Check if the PHP version is below what Drupal supports.
if (version_compare($phpversion, DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
$requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.',
[
'%version' => DRUPAL_MINIMUM_SUPPORTED_PHP,
'%recommended' => DRUPAL_RECOMMENDED_PHP,
':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php',
]
);
$requirements['php']['severity'] = REQUIREMENT_ERROR;
// If PHP is old, it's not safe to continue with the requirements check.
return $requirements;
}
if ((version_compare($phpversion, DRUPAL_RECOMMENDED_PHP) < 0) && ($phase === 'install' || $phase === 'runtime')) {
// Warn if still on PHP 5. If at least PHP 7.0, relax from "warning" to
// "info", and show it at runtime only, to not scare users while installing.
if (version_compare($phpversion, '7.0') < 0) {
$requirements['php']['description'] = t('Drupal will drop support for this version on March 6, 2019. Upgrade to PHP version %recommended or higher to ensure your site can receive updates and remain secure. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
$requirements['php']['severity'] = REQUIREMENT_WARNING;
// If the PHP version is also below the absolute minimum allowed, it's not
// safe to continue with the requirements check.
if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) {
return $requirements;
}
else {
if ($phase === 'runtime') {
$requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
$requirements['php']['severity'] = REQUIREMENT_INFO;
}
// Otherwise downgrade the error to a warning during updates. Even if there
// are some problems with the site's PHP version, it's still better for the
// site to keep its Drupal codebase up to date.
elseif ($phase === 'update') {
$requirements['php']['severity'] = REQUIREMENT_WARNING;
}
}
// Suggest to update to at least 5.5.21 or 5.6.5 for disabling multiple
// statements.
if (($phase === 'install' || \Drupal::database()->driver() === 'mysql') && !SystemRequirements::phpVersionWithPdoDisallowMultipleStatements($phpversion)) {
$requirements['php_multiple_statement'] = [
'title' => t('PHP (multiple statement disabling)'),
'value' => $phpversion_label,
'description' => t('PHP versions higher than 5.6.5 or 5.5.21 provide built-in SQL injection protection for mysql databases. It is recommended to update.'),
'severity' => REQUIREMENT_INFO,
];
// Since we allow sites with unsupported PHP versions to still run Drupal
// updates, we also need to be able to run tests with those PHP versions,
// which requires the ability to install test sites. Not all tests are
// required to pass on these PHP versions, but we want to monitor which
// ones do and don't.
elseif ($phase === 'install' && drupal_valid_test_ua()) {
$requirements['php']['severity'] = REQUIREMENT_INFO;
}
}
// For PHP versions that are still supported but no longer recommended,
// inform users of what's recommended, allowing them to take action before it
// becomes urgent.
elseif ($phase === 'runtime' && version_compare($phpversion, DRUPAL_RECOMMENDED_PHP) < 0) {
$requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
$requirements['php']['severity'] = REQUIREMENT_INFO;
}
// Test for PHP extensions.
......
......@@ -4,6 +4,7 @@
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Tests\RequirementsPageTrait;
/**
* Provides methods to conditionally enable db update functions and apply
......@@ -14,6 +15,7 @@
trait DbUpdatesTrait {
use StringTranslationTrait;
use RequirementsPageTrait;
/**
* Enables db updates until the specified index.
......@@ -34,6 +36,7 @@ protected function enableUpdates($module, $group, $index) {
*/
protected function applyUpdates() {
$this->drupalGet(Url::fromRoute('system.db_update'));
$this->updateRequirementsProblem();
$this->clickLink($this->t('Continue'));
$this->clickLink($this->t('Apply pending updates'));
$this->checkForMetaRefresh();
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\system\Functional\Update;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
/**
* Tests that a module implementing hook_update_8000() causes an error to be
......@@ -12,6 +13,8 @@
*/
class InvalidUpdateHookTest extends BrowserTestBase {
use RequirementsPageTrait;
/**
* Modules to enable.
*
......@@ -45,6 +48,7 @@ public function testInvalidUpdateHook() {
// Confirm that a module with hook_update_8000() cannot be updated.
$this->drupalLogin($this->updateUser);
$this->drupalGet($this->updateUrl);
$this->updateRequirementsProblem();
$this->clickLink(t('Continue'));
$this->assertText(t('Some of the pending updates cannot be applied because their dependencies were not met.'));
}
......
......@@ -77,6 +77,8 @@ public function testPostUpdate() {
$this->assertEqual($existing_updates[$expected_update], 1, 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->assertText('No pending updates.');
}
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
/**
* Tests that update hooks are properly run.
......@@ -13,6 +14,8 @@
*/
class UpdateSchemaTest extends BrowserTestBase {
use RequirementsPageTrait;
/**
* {@inheritdoc}
*/
......@@ -56,6 +59,7 @@ public function testUpdateHooks() {
$this->drupalLogin($this->user);
$this->drupalGet($this->updateUrl, ['external' => TRUE]);
$this->updateRequirementsProblem();
$this->clickLink(t('Continue'));
$this->assertRaw('Schema version 8001.');
// Run the update hooks.
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
/**
* Tests the update script access and functionality.
......@@ -13,6 +14,8 @@
*/
class UpdateScriptTest extends BrowserTestBase {
use RequirementsPageTrait;
/**
* 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();
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\system\Functional\Update;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
/**
* Tests that the minimum schema version is correct even if only 7.x update
......@@ -12,6 +13,8 @@
*/
class UpdatesWith7xTest extends BrowserTestBase {
use RequirementsPageTrait;
/**
* Modules to enable.
*
......@@ -48,6 +51,7 @@ public function testWith7x() {
// 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('Some of the pending updates cannot be applied because their dependencies were not met.'));
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\minimal\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
use Drupal\user\UserInterface;
/**
......@@ -12,6 +13,8 @@
*/
class MinimalTest extends BrowserTestBase {
use RequirementsPageTrait;
protected $profile = 'minimal';
/**
......@@ -34,6 +37,8 @@ public function testMinimal() {
// Ensure that there are no pending updates after installation.
$this->drupalLogin($this->rootUser);
$this->drupalGet('update.php/selection');
$this->updateRequirementsProblem();
$this->drupalGet('update.php/selection');
$this->assertText('No pending updates.');
// Ensure that there are no pending entity updates after installation.
......
......@@ -10,6 +10,7 @@
use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
use Drupal\user\Entity\Role;
/**
......@@ -20,6 +21,7 @@
class StandardTest extends BrowserTestBase {
use SchemaCheckTestTrait;
use RequirementsPageTrait;
protected $profile = 'standard';
......@@ -155,6 +157,8 @@ public function testStandard() {
// Ensure that there are no pending updates after installation.
$this->drupalLogin($this->rootUser);
$this->drupalGet('update.php/selection');
$this->updateRequirementsProblem();
$this->drupalGet('update.php/selection');
$this->assertText('No pending updates.');
// Ensure that there are no pending entity updates after installation.
......
......@@ -8,6 +8,7 @@
use Drupal\Core\Site\Settings;
use Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
use GuzzleHttp\HandlerStack;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
......@@ -19,6 +20,8 @@
*/
abstract class InstallerTestBase extends BrowserTestBase {
use RequirementsPageTrait;
/**
* Custom settings.php values to write for a test run.
*
......@@ -244,12 +247,7 @@ protected function setUpSettings() {
* @see system_requirements()
*/
protected function setUpRequirementsProblem() {
// By default, skip the "recommended PHP version" warning on older test
// environments. This allows the installer to be tested consistently on
// both recommended PHP versions and older (but still supported) versions.
if (version_compare(phpversion(), '7.0') < 0) {
$this->continueOnExpectedWarnings(['PHP']);
}
// Do nothing.
}
/**
......@@ -275,45 +273,4 @@ protected function refreshVariables() {
}
}
/**
* 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 "continue anyway" link to go to the
* next screen of the installer. 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('continue anyway');
$this->checkForMetaRefresh();
}
}
......@@ -10,6 +10,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Language\Language;
use Drupal\Core\Url;
use Drupal\Tests\RequirementsPageTrait;
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 RequirementsPageTrait;
/**
* Modules to enable after the database is loaded.
......@@ -295,6 +297,7 @@ protected function runUpdates() {
]);
$this->drupalGet($this->updateUrl);
$this->updateRequirementsProblem();
$this->clickLink(t('Continue'));
$this->doSelectionTest();
......
......@@ -58,6 +58,7 @@ public function setUp() {
}
// Get a lock and a valid site path.
$this->testDb = new TestDatabase();
include $this->root . '/core/includes/bootstrap.inc';
}
/**
......@@ -83,6 +84,10 @@ public function tearDown() {
* Tests the quick-start command.
*/
public function testQuickStartCommand() {
if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
$this->markTestSkipped();
}
// Install a site using the standard profile to ensure the one time login
// link generation works.
......@@ -117,7 +122,6 @@ public function testQuickStartCommand() {
$this->assertContains("127.0.0.1:$port/user/reset/1/", $process->getOutput());
// Generate a cookie so we can make a request against the installed site.
include $this->root . '/core/includes/bootstrap.inc';
define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
chmod($this->testDb->getTestSitePath(), 0755);
$cookieJar = CookieJar::fromArray([
......@@ -132,10 +136,48 @@ public function testQuickStartCommand() {
$process->stop();
}
/**
* Tests that the installer throws a requirement error on older PHP versions.
*/
public function testPhpRequirement() {
if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) >= 0) {
$this->markTestSkipped();
}
$install_command = [
$this->php,
'core/scripts/drupal',
'quick-start',
'standard',
"--site-name='Test site {$this->testDb->getDatabasePrefix()}'",
'--suppress-login',
];
$process = new Process($install_command, NULL, ['DRUPAL_DEV_SITE_PATH' => $this->testDb->getTestSitePath()]);
$process->inheritEnvironmentVariables();
$process->setTimeout(500);
$process->start();
while ($process->isRunning()) {
// Wait for more output.
sleep(1);
}
$error_output = $process->getErrorOutput();
$this->assertContains('Your PHP installation is too old.', $error_output);
$this->assertContains('Drupal requires at least PHP', $error_output);
$this->assertContains(DRUPAL_MINIMUM_SUPPORTED_PHP, $error_output);
// Stop the web server.
$process->stop();
}
/**
* Tests the quick-start commands.
*/
public function testQuickStartInstallAndServerCommands() {
if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
$this->markTestSkipped();
}
// Install a site.
$install_command = [
$this->php,
......@@ -180,7 +222,6 @@ public function testQuickStartInstallAndServerCommands() {
sleep(2);
// Generate a cookie so we can make a request against the installed site.
include $this->root . '/core/includes/bootstrap.inc';
define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
chmod($this->testDb->getTestSitePath(), 0755);
$cookieJar = CookieJar::fromArray([
......
<?php
namespace Drupal\Tests;
/**
* Provides helper methods for the requirements page.
*/
trait RequirementsPageTrait {
/**
* Handles the update requirements page.
*/
protected function updateRequirementsProblem() {
// Assert a warning is shown on older test environments.
if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
$this->assertNoText('Errors found');
$this->assertWarningSummaries(['PHP']);
$this->clickLink('try again');
$this->checkForMetaRefresh();
}
}
/**
* Continues installation when the expected warnings are found.
*
* This function is no longer called by any core test, but it is retained for
* use by contrib/custom tests. It is not deprecated, because it remains the
* recommended function to call for its purpose.
*
* @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 "continue anyway" link to go to the
* next screen of the installer. 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 = []) {
$this->assertNoText('Errors found');
$this->assertWarningSummaries($expected_warnings);
$this->clickLink('continue anyway');
$this->checkForMetaRefresh();
}
/**
* Assert the given warning summaries are present on the page.
*
* If an expected warning is not found, or if a warning not in the list is
* present, a fail is raised.
*
* @param string[] $warning_summaries
* A list of warning summaries to expect on the requirements screen (e.g.
* 'PHP', 'PHP OPcode caching', etc.).
*/
protected function assertWarningSummaries(array $warning_summaries) {
// 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($warning_summaries); $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($warning_summaries, $warnings);
}
}
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