/** * Test domain language negotiation. * * @dataProvider providerTestDomain */ public function testDomain($http_host, $domains, $expected_langcode) { $config_data = array('source' => LanguageNegotiationUrl::CONFIG_DOMAIN, 'domains' => $domains); $config_object = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock(); $config_object->expects($this->any())->method('get')->with('url')->will($this->returnValue($config_data)); $config = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface'); $config->expects($this->any())->method('get')->with('language.negotiation')->will($this->returnValue($config_object)); $request = Request::create('', 'GET', array(), array(), array(), array('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)); }
/** * Test domain language negotiation and outbound path processing. * * @dataProvider providerTestDomain */ public function testDomain($http_host, $domains, $expected_langcode) { $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($this->languages['en'])); $config = $this->getConfigFactoryStub(['language.negotiation' => ['url' => ['source' => LanguageNegotiationUrl::CONFIG_DOMAIN, 'domains' => $domains]]]); $request = Request::create('', 'GET', array(), array(), array(), array('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); }