function LanguageNegotiationContentEntityTest::testGetLangcode
Same name in other branches
- 11.x core/modules/language/tests/src/Unit/Plugin/LanguageNegotiation/LanguageNegotiationContentEntityTest.php \Drupal\Tests\language\Unit\Plugin\LanguageNegotiation\LanguageNegotiationContentEntityTest::testGetLangcode()
@covers ::getLangcode
File
-
core/
modules/ language/ tests/ src/ Unit/ Plugin/ LanguageNegotiation/ LanguageNegotiationContentEntityTest.php, line 100
Class
- LanguageNegotiationContentEntityTest
- Tests the LanguageNegotiationContentEntity plugin class.
Namespace
Drupal\Tests\language\Unit\Plugin\LanguageNegotiationCode
public function testGetLangcode() : void {
$languageNegotiationContentEntity = $this->createLanguageNegotiationPlugin();
// Case 1: Empty request.
$this->assertEquals(NULL, $languageNegotiationContentEntity->getLangcode());
// Case 2: A request is available, but the languageManager is not set and
// the static::QUERY_PARAMETER is not provided as a named parameter.
$request = Request::create('/de/foo', 'GET');
$request->query = new InputBag();
$this->assertEquals(NULL, $languageNegotiationContentEntity->getLangcode($request));
// Case 3: A request is available, the languageManager is set, but the
// static::QUERY_PARAMETER is not provided as a named parameter.
$languageNegotiationContentEntity->setLanguageManager($this->languageManager);
$this->assertEquals(NULL, $languageNegotiationContentEntity->getLangcode($request));
// Case 4: A request is available, the languageManager is set and the
// static::QUERY_PARAMETER is provided as a named parameter.
$expectedLangcode = 'de';
$request->query
->set(LanguageNegotiationContentEntity::QUERY_PARAMETER, $expectedLangcode);
$this->assertEquals($expectedLangcode, $languageNegotiationContentEntity->getLangcode($request));
// Case 5: A request is available, the languageManager is set and the
// static::QUERY_PARAMETER is provided as a named parameter with a given
// langcode that is not one of the system supported ones.
$unknownLangcode = 'xx';
$request->query
->set(LanguageNegotiationContentEntity::QUERY_PARAMETER, $unknownLangcode);
$this->assertNull($languageNegotiationContentEntity->getLangcode($request));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.