You are here

protected function CountryTest::clickLinkHelper in Ubercart 8.4

Provides a helper for ::clickLinkInRow().

Parameters

string|\Drupal\Component\Render\MarkupInterface $label: Text between the anchor tags, uses starts-with().

int $index: Link position counting from zero.

string $pattern: A pattern to use for the XPath.

Return value

bool|string Page contents on success, or FALSE on failure.

1 call to CountryTest::clickLinkHelper()
CountryTest::clickLinkInRow in uc_country/tests/src/Functional/CountryTest.php
Follows a link in the same table row as the label text.

File

uc_country/tests/src/Functional/CountryTest.php, line 146

Class

CountryTest
Import, edit, and remove countries and their settings.

Namespace

Drupal\Tests\uc_country\Functional

Code

protected function clickLinkHelper($label, $index, $pattern) {

  // Cast MarkupInterface objects to string.
  $label = (string) $label;
  $url_before = $this
    ->getUrl();
  $urls = $this
    ->xpath($pattern, [
    ':label' => $label,
  ]);
  if (isset($urls[$index])) {
    $url_target = $this
      ->getAbsoluteUrl($urls[$index]
      ->getAttribute('href'));
    $this
      ->assertTrue(TRUE, format_string('Clicked link %label (@url_target) from @url_before', [
      '%label' => $label,
      '@url_target' => $url_target,
      '@url_before' => $url_before,
    ]), 'Browser');
    return $this
      ->drupalGet($url_target);
  }
  $this
    ->fail(format_string('Link %label does not exist on @url_before', [
    '%label' => $label,
    '@url_before' => $url_before,
  ]), 'Browser');
  return FALSE;
}