You are here

public function LanguageCookieNegotiationConfigTest::testLanguageCookieSetOnEveryPageLoadOption in Language Cookie 8

Test the language_cookie set_on_every_pageload config option.

File

tests/src/Functional/LanguageCookieNegotiationConfigTest.php, line 196

Class

LanguageCookieNegotiationConfigTest
Test the language cookie negotiation config.

Namespace

Drupal\Tests\language_cookie\Functional

Code

public function testLanguageCookieSetOnEveryPageLoadOption() {
  $node = $this
    ->drupalCreateNode();
  $this
    ->drupalGet('fr/node/' . $node
    ->id());
  $this
    ->assertRegExp('/language=fr/i', $this
    ->drupalGetHeader('Set-Cookie'), 'Cookie is set.');
  $this
    ->drupalGet('fr/node/' . $node
    ->id());
  $this
    ->assertEmpty($this
    ->drupalGetHeader('Set-Cookie'));
  $this
    ->drupalGet('en/node/' . $node
    ->id());
  $this
    ->assertRegExp('/language=en/i', $this
    ->drupalGetHeader('Set-Cookie'), 'Cookie is set.');
  $config = $this
    ->config('language_cookie.negotiation');
  $config
    ->set('set_on_every_pageload', TRUE);
  $config
    ->save();
  $node = $this
    ->drupalCreateNode();
  $this
    ->drupalGet('fr/node/' . $node
    ->id());
  $this
    ->assertRegExp('/language=fr/i', $this
    ->drupalGetHeader('Set-Cookie'), 'Cookie is set.');
  $this
    ->drupalGet('fr/node/' . $node
    ->id());
  $this
    ->assertRegExp('/language=fr/i', $this
    ->drupalGetHeader('Set-Cookie'), 'Cookie is set.');
  $this
    ->drupalGet('en/node/' . $node
    ->id());
  $this
    ->assertRegExp('/language=en/i', $this
    ->drupalGetHeader('Set-Cookie'), 'Cookie is set.');
}