public function TermTranslationTest::testTranslatedBreadcrumbs in Drupal 8
Same name and namespace in other branches
- 9 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\FunctionalCode
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());
}