You are here

public function StatusTest::testStatusPage in Drupal 9

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

Tests that the status page returns.

File

core/modules/system/tests/src/Functional/System/StatusTest.php, line 47

Class

StatusTest
Tests output on the status overview page.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testStatusPage() {

  // Go to Administration.
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Verify that the PHP version is shown on the page.
  $this
    ->assertSession()
    ->pageTextContains(phpversion());
  if (function_exists('phpinfo')) {
    $this
      ->assertSession()
      ->linkByHrefExists(Url::fromRoute('system.php')
      ->toString());
  }
  else {
    $this
      ->assertSession()
      ->linkByHrefNotExists(Url::fromRoute('system.php')
      ->toString());
  }

  // If a module is fully installed no pending updates exists.
  $this
    ->assertSession()
    ->pageTextNotContains('Out of date');

  // The setting config_sync_directory is not properly formed.
  $this
    ->assertSession()
    ->pageTextContains("Your {$this->siteDirectory}/settings.php file must define the \$settings['config_sync_directory'] setting");

  /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
  $update_registry = \Drupal::service('update.update_hook_registry');

  // Set the schema version of update_test_postupdate to a lower version, so
  // update_test_postupdate_update_8001() needs to be executed.
  $update_registry
    ->setInstalledVersion('update_test_postupdate', 8000);
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertSession()
    ->pageTextContains('Out of date');

  // Now cleanup the executed post update functions.
  $update_registry
    ->setInstalledVersion('update_test_postupdate', 8001);

  /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
  $post_update_registry = \Drupal::service('update.post_update_registry');
  $post_update_registry
    ->filterOutInvokedUpdatesByModule('update_test_postupdate');
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertSession()
    ->pageTextContains('Out of date');
  $this
    ->drupalGet('admin/reports/status/php');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Check if cron error is displayed in errors section
  $cron_last_run = \Drupal::state()
    ->get('system.cron_last');
  \Drupal::state()
    ->set('system.cron_last', 0);
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertSession()
    ->elementExists('xpath', '//details[contains(@class, "system-status-report__entry")]//div[contains(text(), "Cron has not run recently")]');
  \Drupal::state()
    ->set('system.cron_last', $cron_last_run);
}