function LanguageNegotiationUrlTest::testDomain

Same name in this branch
  1. 10 core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Functional\LanguageNegotiationUrlTest::testDomain()
Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Unit\LanguageNegotiationUrlTest::testDomain()
  2. 9 core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Functional\LanguageNegotiationUrlTest::testDomain()
  3. 8.9.x core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Unit\LanguageNegotiationUrlTest::testDomain()
  4. 8.9.x core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Functional\LanguageNegotiationUrlTest::testDomain()
  5. 11.x core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Unit\LanguageNegotiationUrlTest::testDomain()
  6. 11.x core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Functional\LanguageNegotiationUrlTest::testDomain()

Tests domain language negotiation and outbound path processing.

@dataProvider providerTestDomain

File

core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php, line 229

Class

LanguageNegotiationUrlTest
@coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl[[api-linebreak]] @group language

Namespace

Drupal\Tests\language\Unit

Code

public function testDomain($http_host, $domains, $expected_langcode) : void {
  $this->languageManager
    ->expects($this->any())
    ->method('getCurrentLanguage')
    ->willReturn($this->languages['en']);
  $config = $this->getConfigFactoryStub([
    'language.negotiation' => [
      'url' => [
        'source' => LanguageNegotiationUrl::CONFIG_DOMAIN,
        'domains' => $domains,
      ],
    ],
  ]);
  $request = Request::create('', 'GET', [], [], [], [
    'HTTP_HOST' => $http_host,
  ]);
  $method = new LanguageNegotiationUrl();
  $method->setLanguageManager($this->languageManager);
  $method->setConfig($config);
  $method->setCurrentUser($this->user);
  $this->assertEquals($expected_langcode, $method->getLangcode($request));
  $cacheability = new BubbleableMetadata();
  $options = [];
  $this->assertSame('foo', $method->processOutbound('foo', $options, $request, $cacheability));
  $expected_cacheability = new BubbleableMetadata();
  if ($expected_langcode !== FALSE && count($domains) > 1) {
    $expected_cacheability->setCacheMaxAge(Cache::PERMANENT)
      ->setCacheContexts([
      'languages:' . LanguageInterface::TYPE_URL,
      'url.site',
    ]);
  }
  $this->assertEquals($expected_cacheability, $cacheability);
}

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