You are here

protected function PatchInfoTest::assertPatchInformationInForm in PatchInfo 8.2

Assert that patch information is listed in update form.

Parameters

string $module_label: Module label 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::assertPatchInformationInForm()
PatchInfoTest::testUpdateForm in tests/src/Functional/PatchInfoTest.php
Tests exposure of patch information in update manager form.

File

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

Class

PatchInfoTest
Tests functionality of PatchInfo module.

Namespace

Drupal\Tests\patchinfo\Functional

Code

protected function assertPatchInformationInForm($module_label, $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 td.
  $xpath .= '/parent::td';

  // That are links with a label whose space normalized version matches the
  // module_label parameter.
  $xpath .= '/a[normalize-space(text())=:module_label]';
  $arguments[':module_label'] = $module_label;
  $patch_information = $this
    ->xpath($xpath, $arguments);
  $message = $message ? $message : strtr('Patch information for %module_label with label %label, url %url and source %source found.', [
    '%label' => $label,
    '%module_label' => $module_label,
    '%source' => $source,
    '%url' => $url,
  ]);
  return $this
    ->assertTrue(isset($patch_information[$index]), $message);
}