function TermTranslationTest::testTranslatedBreadcrumbs

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

Test translated breadcrumbs.

File

core/modules/taxonomy/tests/src/Functional/TermTranslationTest.php, line 61

Class

TermTranslationTest
Tests for proper breadcrumb translation.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTranslatedBreadcrumbs() {
    // Ensure non-translated breadcrumb is correct.
    $breadcrumb = [
        Url::fromRoute('<front>')->toString() => 'Home',
    ];
    foreach ($this->terms as $term) {
        $breadcrumb[$term->toUrl()
            ->toString()] = $term->label();
    }
    // The last item will not be in the breadcrumb.
    array_pop($breadcrumb);
    // Check the breadcrumb on the leaf term page.
    $term = $this->getLeafTerm();
    $this->assertBreadcrumb($term->toUrl(), $breadcrumb, $term->label());
    $languages = \Drupal::languageManager()->getLanguages();
    // Construct the expected translated breadcrumb.
    $breadcrumb = [
        Url::fromRoute('<front>', [], [
            'language' => $languages[$this->translateToLangcode],
        ])
            ->toString() => 'Home',
    ];
    foreach ($this->terms as $term) {
        $translated = $term->getTranslation($this->translateToLangcode);
        $url = $translated->toUrl('canonical', [
            'language' => $languages[$this->translateToLangcode],
        ])
            ->toString();
        $breadcrumb[$url] = $translated->label();
    }
    array_pop($breadcrumb);
    // Check for the translated breadcrumb on the translated leaf term page.
    $term = $this->getLeafTerm();
    $translated = $term->getTranslation($this->translateToLangcode);
    $this->assertBreadcrumb($translated->toUrl('canonical', [
        'language' => $languages[$this->translateToLangcode],
    ]), $breadcrumb, $translated->label());
}

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