function PhpRequirementTest::testStatusPage

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/PhpRequirementTest.php \Drupal\Tests\system\Functional\System\PhpRequirementTest::testStatusPage()
  2. 10 core/modules/system/tests/src/Functional/System/PhpRequirementTest.php \Drupal\Tests\system\Functional\System\PhpRequirementTest::testStatusPage()

Tests status report messages regarding the PHP version.

File

core/modules/system/tests/src/Functional/System/PhpRequirementTest.php, line 52

Class

PhpRequirementTest
Tests the output of PHP requirements on the status report.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testStatusPage() : void {
    $minimum_php_version = PhpRequirements::getMinimumSupportedPhp();
    // Go to Administration.
    $this->drupalGet('admin/reports/status');
    $this->assertSession()
        ->statusCodeEquals(200);
    $phpversion = phpversion();
    // Verify that the PHP version is shown on the page.
    $this->assertSession()
        ->pageTextContains($phpversion);
    // Verify that an error is displayed about the PHP version if it is below
    // the minimum supported PHP.
    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');
    }
    // There should be an informational message if the PHP version is below the
    // recommended version.
    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');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.