public function TermTranslationBreadcrumbTest::testTranslatedBreadcrumbs in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/taxonomy/src/Tests/TermTranslationBreadcrumbTest.php \Drupal\taxonomy\Tests\TermTranslationBreadcrumbTest::testTranslatedBreadcrumbs()
Test translated breadcrumbs.
File
- core/
modules/ taxonomy/ src/ Tests/ TermTranslationBreadcrumbTest.php, line 61 - Contains \Drupal\taxonomy\Tests\TermTranslationBreadcrumbTest.
Class
- TermTranslationBreadcrumbTest
- Tests for proper breadcrumb translation.
Namespace
Drupal\taxonomy\TestsCode
public function testTranslatedBreadcrumbs() {
// Ensure non-translated breadcrumb is correct.
$breadcrumb = array(
Url::fromRoute('<front>')
->toString() => 'Home',
);
foreach ($this->terms as $term) {
$breadcrumb[$term
->url()] = $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
->urlInfo(), $breadcrumb, $term
->label());
$languages = \Drupal::languageManager()
->getLanguages();
// Construct the expected translated breadcrumb.
$breadcrumb = array(
Url::fromRoute('<front>', [], [
'language' => $languages[$this->translateToLangcode],
])
->toString() => 'Home',
);
foreach ($this->terms as $term) {
$translated = $term
->getTranslation($this->translateToLangcode);
$url = $translated
->url('canonical', [
'language' => $languages[$this->translateToLangcode],
]);
$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
->urlInfo('canonical', [
'language' => $languages[$this->translateToLangcode],
]), $breadcrumb, $translated
->label());
}