You are here

protected function TaxonomyAccessFixTestTrait::assertLinkByEndOfHref in Taxonomy access fix 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Traits/TaxonomyAccessFixTestTrait.php \Drupal\Tests\taxonomy_access_fix\Traits\TaxonomyAccessFixTestTrait::assertLinkByEndOfHref()

Passes if a a link whose href attribute ends with a string is found.

@todo Remove once https://www.drupal.org/node/2031223 has been fixed.

An optional element index may be passed.

Parameters

string $href: What the href attribute of the link should end with.

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.

3 calls to TaxonomyAccessFixTestTrait::assertLinkByEndOfHref()
TermAccessTest::testTermAccess in tests/src/Functional/TermAccessTest.php
Test access control functionality for taxonomy terms.
VocabularyAccessTest::testTaxonomyVocabularyCollection in tests/src/Functional/VocabularyAccessTest.php
Tests access to administrative Taxonomy Vocabulary collection.
VocabularyAccessTest::testTaxonomyVocabularyOverview in tests/src/Functional/VocabularyAccessTest.php
Tests access to Taxonomy Vocabulary overview page.

File

tests/src/Traits/TaxonomyAccessFixTestTrait.php, line 79

Class

TaxonomyAccessFixTestTrait
Provides common methods for functional tests of Taxonomy Access Fix module.

Namespace

Drupal\Tests\taxonomy_access_fix\Traits

Code

protected function assertLinkByEndOfHref($href, $index = 0, $message = '') {

  // This is an XPath 1.0 implementation of the ends-with() function.
  $links = $this
    ->xpath('//a[:href = substring(@href, string-length(@href) - ' . (strlen($href) + 1) . ')]', [
    ':href' => $href,
  ]);
  $message = $message ? $message : new FormattableMarkup('Link with href %href found.', [
    '%href' => $href,
  ]);
  return $this
    ->assertTrue(isset($links[$index]), $message);
}