You are here

public function DisableLanguageRedirectTest::testRedirectDifferentDomain in Disable language 8

Tests redirect when the chosen language negotiation method is url domain.

File

tests/src/Functional/DisableLanguageRedirectTest.php, line 97

Class

DisableLanguageRedirectTest
@coversDefaultClass \Drupal\disable_language\EventSubscriber\DisabledLanguagesEventSubscriber @group disable_language

Namespace

Drupal\Tests\disable_language\Functional

Code

public function testRedirectDifferentDomain() {
  \Drupal::configFactory()
    ->getEditable('language.negotiation')
    ->set('url.source', LanguageNegotiationUrl::CONFIG_DOMAIN)
    ->set('url.domains', [
    'nl' => 'nl.example.com',
    'fr' => \Drupal::request()
      ->getHost(),
  ])
    ->save();

  // Do not actually follow the redirects, since we are using a non-existing
  // domain.
  $this
    ->getSession()
    ->getDriver()
    ->getClient()
    ->followRedirects(false);
  $this->maximumMetaRefreshCount = 0;

  // Check for the correct redirect status code and presence of the external
  // domain in the Location-header.
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(307);
  $this
    ->assertSession()
    ->responseHeaderContains('Location', 'nl.example.com');
}