You are here

public function LanguageCookieLanguageSelectionPageTest::testLanguageCookieAndSelectionPage in Language Cookie 8

Test that the language cookie and the language selection page work.

File

tests/src/Functional/LanguageCookieLanguageSelectionPageTest.php, line 45

Class

LanguageCookieLanguageSelectionPageTest
Test that the language_cookie module works well with language_selection_page.

Namespace

Drupal\Tests\language_cookie\Functional

Code

public function testLanguageCookieAndSelectionPage() {

  // Test that no cookie is set when the module is enabled but not configured.
  $node = $this
    ->drupalCreateNode();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();

  // Enable cookie.
  $this
    ->drupalGet('admin/config/regional/language/detection');
  $this
    ->submitForm([
    'language_interface[enabled][language-url]' => 1,
    'language_interface[enabled][' . LanguageNegotiationCookie::METHOD_ID . ']' => 1,
    'language_interface[enabled][language-selection-page]' => 1,
    'language_interface[weight][language-url]' => -8,
    'language_interface[weight][' . LanguageNegotiationCookie::METHOD_ID . ']' => -5,
    'language_interface[weight][language-selection-page]' => -4,
  ], 'Save settings');
  $this
    ->assertSession()
    ->cookieEquals('language', 'en');

  // Remove cookie.
  $this
    ->getSession()
    ->setCookie('language', NULL);
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();
  $this
    ->assertSession()
    ->responseContains('en/node/' . $node
    ->id());

  // Cookie should not yet be set.
  $this
    ->assertEmpty($this
    ->getSession()
    ->getCookie('language'));
  $this
    ->clickLink('English');

  // Cookie should be set at this point.
  $this
    ->assertSession()
    ->cookieEquals('language', 'en');
}