LanguageCookieLanguageSelectionPageTest.php in Language Cookie 8
File
tests/src/Functional/LanguageCookieLanguageSelectionPageTest.php
View source
<?php
namespace Drupal\Tests\language_cookie\Functional;
use Drupal\language_cookie\Plugin\LanguageNegotiation\LanguageNegotiationCookie;
use Drupal\language_cookie_test\Plugin\LanguageNegotiation\LanguageCookieFixedNegotiation;
class LanguageCookieLanguageSelectionPageTest extends LanguageCookieTestBase {
protected static $modules = [
'language_selection_page',
];
protected const LANGUAGE_SELECTION_PAGE_TEXT = 'This page is the default page of the module Language Selection Page';
protected function setUp() : void {
parent::setUp();
$this
->drupalGet('admin/config/regional/language/detection');
$this
->submitForm([
'language_interface[enabled][' . LanguageNegotiationCookie::METHOD_ID . ']' => FALSE,
'language_interface[enabled][' . LanguageCookieFixedNegotiation::METHOD_ID . ']' => FALSE,
'language_interface[enabled][language-selection-page]' => 1,
'language_interface[enabled][language-url]' => 1,
], 'Save settings');
}
public function testLanguageCookieAndSelectionPage() {
$node = $this
->drupalCreateNode();
$this
->drupalGet('node/' . $node
->id());
$this
->assertLanguageSelectionPageLoaded();
$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');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('node/' . $node
->id());
$this
->assertLanguageSelectionPageLoaded();
$this
->assertSession()
->responseContains('en/node/' . $node
->id());
$this
->assertEmpty($this
->getSession()
->getCookie('language'));
$this
->clickLink('English');
$this
->assertSession()
->cookieEquals('language', 'en');
}
protected function assertLanguageSelectionPageLoaded() {
$this
->assertSession()
->pageTextContains(self::LANGUAGE_SELECTION_PAGE_TEXT);
}
protected function assertLanguageSelectionPageNotLoaded() {
$this
->assertSession()
->pageTextNotContains(self::LANGUAGE_SELECTION_PAGE_TEXT);
}
}