You are here

protected function TestHelperTrait::findFacetLink in Facets 8

Use xpath to find a facet link.

Parameters

string $label: Label of a link to find.

Return value

array An array of links with the facets.

6 calls to TestHelperTrait::findFacetLink()
LanguageIntegrationTest::testUrlAliasTranslation in tests/src/Functional/LanguageIntegrationTest.php
Tests the url alias translation.
ProcessorIntegrationTest::testBooleanProcessorIntegration in tests/src/Functional/ProcessorIntegrationTest.php
Tests the for processors in the frontend with a 'boolean' facet.
ProcessorIntegrationTest::testNumericGranularity in tests/src/Functional/ProcessorIntegrationTest.php
Tests the for configuration of granularity processor.
TestHelperTrait::assertFacetLabel in tests/src/Functional/TestHelperTrait.php
Passes if a facet with the specified label is found and is a link.
TestHelperTrait::checkFacetIsActive in tests/src/Functional/TestHelperTrait.php
Check if a facet is active by providing a label for it.

... See full list

File

tests/src/Functional/TestHelperTrait.php, line 152

Class

TestHelperTrait
Adds helpers for test methods.

Namespace

Drupal\Tests\facets\Functional

Code

protected function findFacetLink($label) {
  $label = (string) $label;
  $label = strip_tags($label);
  $matches = [];
  if (preg_match('/(.*)\\s\\((\\d+)\\)/', $label, $matches)) {
    $links = $this
      ->xpath('//a//span[normalize-space(text())=:label]/following-sibling::span[normalize-space(text())=:count]', [
      ':label' => $matches[1],
      ':count' => '(' . $matches[2] . ')',
    ]);
  }
  else {
    $links = $this
      ->xpath('//a//span[normalize-space(text())=:label]', [
      ':label' => $label,
    ]);
  }
  return $links;
}