You are here

protected function RequirementsPageTrait::assertRequirementSummaries in Drupal 10

Asserts the given requirements section summaries are present on the page.

If an expected requirements message is not found, or if a message not in the list is present, a fail is raised.

Parameters

string[] $summaries: A list of warning summaries to expect on the requirements screen (e.g. 'PHP', 'PHP OPcode caching', etc.).

string $type: The type of requirement, either 'warning' or 'error'.

File

core/tests/Drupal/Tests/RequirementsPageTrait.php, line 85

Class

RequirementsPageTrait
Provides helper methods for the requirements page.

Namespace

Drupal\Tests

Code

protected function assertRequirementSummaries(array $summaries, string $type) {

  // The selectors are different for Seven and Claro.
  $is_claro = stripos($this
    ->getSession()
    ->getPage()
    ->getContent(), 'claro/css/theme/maintenance-page.css') !== FALSE;
  $selectors = [];
  if ($is_claro) {

    // In Claro each requirement heading is present in a div with the class
    // system-status-report__status-title. There is one summary element per
    // requirement type and it is adjacent to a div with the class
    // claro-details__wrapper.
    $selectors[] = 'summary#' . $type . '+.claro-details__wrapper .system-status-report__status-title';
  }
  else {

    // Allow only details elements that are directly after the warning/error
    // 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.
    // For errors, the selectors are the same except that they are h3#error.
    // We add one more selector than expected requirements to confirm that
    // there isn't any other requirement message before clicking the link.
    // @todo Make this more reliable in
    //   https://www.drupal.org/project/drupal/issues/2927345.
    for ($i = 0; $i <= count($summaries); $i++) {
      $selectors[] = 'h3#' . $type . implode('', array_fill(0, $i + 1, '+details')) . ' summary';
    }
  }
  $elements = $this
    ->cssSelect(implode(', ', $selectors));

  // Confirm that there are only the expected requirements.
  $requirements = [];
  foreach ($elements as $requirement) {
    $requirements[] = trim($requirement
      ->getText());
  }
  $this
    ->assertEquals($summaries, $requirements);
}