function TermTranslationViewsTest::testTermsTranslationWithContextualFilter

Same name and namespace in other branches
  1. 10 core/modules/taxonomy/tests/src/Functional/Views/TermTranslationViewsTest.php \Drupal\Tests\taxonomy\Functional\Views\TermTranslationViewsTest::testTermsTranslationWithContextualFilter()

Ensure that proper translation is returned when contextual filter.

Taxonomy term: Term ID & Content: Has taxonomy term ID (with depth) contextual filters are enabled for two separate view modes.

File

core/modules/taxonomy/tests/src/Functional/Views/TermTranslationViewsTest.php, line 78

Class

TermTranslationViewsTest
Tests for views translation.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

public function testTermsTranslationWithContextualFilter() : void {
    $this->drupalLogin($this->rootUser);
    foreach ($this->terms as $term) {
        // Test with "Content: Has taxonomy term ID (with depth)" contextual filter.
        // Generate base language url and send request.
        $url = Url::fromRoute('view.taxonomy_translated_term_name_test.page_1', [
            'arg_0' => $term->id(),
        ])
            ->toString();
        $this->drupalGet($url);
        $this->assertSession()
            ->pageTextContains($term->label());
        // Generate translation URL and send request.
        $url = Url::fromRoute('view.taxonomy_translated_term_name_test.page_1', [
            'arg_0' => $term->id(),
        ], [
            'language' => $this->translationLanguage,
        ])
            ->toString();
        $this->drupalGet($url);
        $this->assertSession()
            ->pageTextContains($this->termTranslationMap[$term->label()]);
        // Test with "Taxonomy term: Term ID" contextual filter.
        // Generate base language url and send request.
        $url = Url::fromRoute('view.taxonomy_translated_term_name_test.page_2', [
            'arg_0' => $term->id(),
        ])
            ->toString();
        $this->drupalGet($url);
        $this->assertSession()
            ->pageTextContains($term->label());
        // Generate translation URL and send request.
        $url = Url::fromRoute('view.taxonomy_translated_term_name_test.page_2', [
            'arg_0' => $term->id(),
        ], [
            'language' => $this->translationLanguage,
        ])
            ->toString();
        $this->drupalGet($url);
        $this->assertSession()
            ->pageTextContains($this->termTranslationMap[$term->label()]);
    }
}

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