function LanguageNegotiationContentEntityTest::testGetLanguageSwitchLinks

Same name in other branches
  1. 11.x core/modules/language/tests/src/Unit/Plugin/LanguageNegotiation/LanguageNegotiationContentEntityTest.php \Drupal\Tests\language\Unit\Plugin\LanguageNegotiation\LanguageNegotiationContentEntityTest::testGetLanguageSwitchLinks()

@covers ::getLanguageSwitchLinks

File

core/modules/language/tests/src/Unit/Plugin/LanguageNegotiation/LanguageNegotiationContentEntityTest.php, line 211

Class

LanguageNegotiationContentEntityTest
Tests the LanguageNegotiationContentEntity plugin class.

Namespace

Drupal\Tests\language\Unit\Plugin\LanguageNegotiation

Code

public function testGetLanguageSwitchLinks() : void {
    $languageNegotiationContentEntity = $this->createLanguageNegotiationPlugin();
    $languageNegotiationContentEntity->setLanguageManager($this->languageManager);
    $request = Request::create('/foo', 'GET', [
        'param1' => 'xyz',
    ]);
    $url = Url::fromUri('base:' . $this->randomMachineName());
    $expectedLanguageSwitchLinksArray = [
        'de' => [
            'url' => $url,
            'title' => $this->languages['de']
                ->getName(),
            'attributes' => [
                'class' => [
                    'language-link',
                ],
            ],
            'query' => [
                LanguageNegotiationContentEntity::QUERY_PARAMETER => 'de',
                'param1' => 'xyz',
            ],
        ],
        'en' => [
            'url' => $url,
            'title' => $this->languages['en']
                ->getName(),
            'attributes' => [
                'class' => [
                    'language-link',
                ],
            ],
            'query' => [
                LanguageNegotiationContentEntity::QUERY_PARAMETER => 'en',
                'param1' => 'xyz',
            ],
        ],
    ];
    $providedLanguageSwitchLinksArray = $languageNegotiationContentEntity->getLanguageSwitchLinks($request, $this->randomMachineName(), $url);
    $this->assertEquals($expectedLanguageSwitchLinksArray, $providedLanguageSwitchLinksArray);
}

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