function TermIndexTest::testTaxonomyTermHierarchyBreadcrumbs

Same name in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Functional/TermIndexTest.php \Drupal\Tests\taxonomy\Functional\TermIndexTest::testTaxonomyTermHierarchyBreadcrumbs()
  2. 10 core/modules/taxonomy/tests/src/Functional/TermIndexTest.php \Drupal\Tests\taxonomy\Functional\TermIndexTest::testTaxonomyTermHierarchyBreadcrumbs()
  3. 11.x core/modules/taxonomy/tests/src/Functional/TermIndexTest.php \Drupal\Tests\taxonomy\Functional\TermIndexTest::testTaxonomyTermHierarchyBreadcrumbs()

Tests that there is a link to the parent term on the child term page.

File

core/modules/taxonomy/tests/src/Functional/TermIndexTest.php, line 242

Class

TermIndexTest
Tests the hook implementations that maintain the taxonomy index.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTaxonomyTermHierarchyBreadcrumbs() {
    // Create two taxonomy terms and set term2 as the parent of term1.
    $term1 = $this->createTerm($this->vocabulary);
    $term2 = $this->createTerm($this->vocabulary);
    $term1->parent = [
        $term2->id(),
    ];
    $term1->save();
    // Verify that the page breadcrumbs include a link to the parent term.
    $this->drupalGet('taxonomy/term/' . $term1->id());
    // Breadcrumbs are not rendered with a language, prevent the term
    // language from being added to the options.
    // Check that parent term link is displayed when viewing the node.
    $this->assertSession()
        ->responseContains(Link::fromTextAndUrl($term2->getName(), $term2->toUrl('canonical', [
        'language' => NULL,
    ]))
        ->toString());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.