PhpRequirementTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/System/PhpRequirementTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\System;
use Drupal\Core\Utility\PhpRequirements;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
class PhpRequirementTest extends BrowserTestBase {
use RequirementsPageTrait;
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'access site reports',
]);
$this
->drupalLogin($admin_user);
$settings['settings']['trusted_host_patterns'] = (object) [
'value' => [
'^' . preg_quote(\Drupal::request()
->getHost()) . '$',
],
'required' => TRUE,
];
$this
->writeSettings($settings);
}
public function testStatusPage() {
$minimum_php_version = PhpRequirements::getMinimumSupportedPhp();
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->statusCodeEquals(200);
$phpversion = phpversion();
$this
->assertSession()
->pageTextContains($phpversion);
if (version_compare($phpversion, $minimum_php_version) < 0) {
$this
->assertErrorSummaries([
'PHP',
]);
$this
->assertSession()
->pageTextContains('Your PHP installation is too old. Drupal requires at least PHP ' . $minimum_php_version);
}
else {
$this
->assertSession()
->pageTextNotContains('Your PHP installation is too old. Drupal requires at least PHP ' . $minimum_php_version);
$this
->assertSession()
->pageTextNotContains('Errors found');
}
if (version_compare($phpversion, \Drupal::RECOMMENDED_PHP) < 0) {
$this
->assertSession()
->pageTextContains('It is recommended to upgrade to PHP version ' . \Drupal::RECOMMENDED_PHP . ' or higher');
}
else {
$this
->assertSession()
->pageTextNotContains('It is recommended to upgrade to PHP version ' . \Drupal::RECOMMENDED_PHP . ' or higher');
}
}
}