You are here

protected function PatchInfoTest::assertPatchInformationInReport in PatchInfo 8.2

Assert that patch information is listed in update report.

Parameters

string $module_label: Module label as listed in update report.

string $module_version: Module version as listed in update report.

string $label: Label of patch information.

string $url: Url of patch information.

string $source: Source of patch information.

int $index: Link position counting from zero.

string $message: (optional) A message to display with the assertion. Do not translate messages: use strtr() to embed variables in the message text, not t(). If left blank, a default message will be displayed.

Return value

bool TRUE if the assertion succeeded, FALSE otherwise.

1 call to PatchInfoTest::assertPatchInformationInReport()
PatchInfoTest::testUpdateReport in tests/src/Functional/PatchInfoTest.php
Tests exposure of patch information in update report.

File

tests/src/Functional/PatchInfoTest.php, line 402

Class

PatchInfoTest
Tests functionality of PatchInfo module.

Namespace

Drupal\Tests\patchinfo\Functional

Code

protected function assertPatchInformationInReport($module_label, $module_version, $label, $url = '', $source = '', $index = 0, $message = '') {

  // Get any elements.
  $xpath = '//';
  $arguments = [];

  // That are parents of abbreviations with a label matching '(src)' and title
  // attribute matching the source parameter.
  if (!empty($source)) {
    $xpath .= 'abbr[normalize-space(text())="(src)"][normalize-space(@title)=:source]/parent::';
    $arguments[':source'] = $source;
  }

  // That are links.
  if (!empty($url)) {
    $xpath .= 'a';
  }
  else {
    $xpath .= 'li';
  }

  // That have a label matching the label parameter.
  $xpath .= '[normalize-space(text())=:label]';
  $arguments[':label'] = $label;

  // That have an href attribute ending with the url parameter.
  if (!empty($url)) {

    // @note: This is an XPath 1.0 implementation of the ends-with() function.
    $xpath .= '[:href = substring(@href, string-length(@href) - ' . (strlen($url) + 1) . ')]';
    $arguments[':href'] = $url;
  }

  // That is nested inside a list item.
  if (!empty($url)) {
    $xpath .= '/parent::li';
  }

  // That is nested inside an unordered list.
  $xpath .= '/parent::ul';

  // That has a parent div with a class attribute matching exactly
  // 'patchinfo-patches'.
  $xpath .= '/parent::div[@class="patchinfo-patches"]';

  // That has a parent div with a class attribute matching exactly
  // 'project-updates__details'.
  $xpath .= '/parent::div[@class="project-updates__details"]';

  // That has a preceding div on same label with a class attribute matching
  // exactly 'project-update__title'.
  $xpath .= '/preceding-sibling::div[@class="project-update__title"]';

  // That has either a label whose space normalized version matches the
  // module_label parameter and module_version parameter concatenated with
  // a string or a child link with a label matching the module_label paramter.
  $xpath_link = $xpath . '/a[normalize-space(text())=:module_label]';
  $xpath .= '[normalize-space(text())=:update_title]|' . $xpath_link;
  $arguments[':module_label'] = $module_label;
  $arguments[':update_title'] = $module_label . ' ' . $module_version;
  $patch_information = $this
    ->xpath($xpath, $arguments);
  $message = $message ? $message : strtr('Patch information for %module_label (%module_version) with label %label, url %url and source %source found.', [
    '%label' => $label,
    '%module_label' => $module_label,
    '%module_version' => $module_version,
    '%source' => $source,
    '%url' => $url,
  ]);
  return $this
    ->assertTrue(isset($patch_information[$index]), $message);
}