You are here

protected function LanguageBrowserDetectionAcceptLanguageTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Functional/LanguageBrowserDetectionAcceptLanguageTest.php \Drupal\Tests\language\Functional\LanguageBrowserDetectionAcceptLanguageTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/language/tests/src/Functional/LanguageBrowserDetectionAcceptLanguageTest.php, line 35

Class

LanguageBrowserDetectionAcceptLanguageTest
Tests browser language detection with different accept-language headers.

Namespace

Drupal\Tests\language\Functional

Code

protected function setUp() {
  parent::setUp();

  // User to manage languages.
  $admin = $this
    ->drupalCreateUser([], NULL, TRUE);
  $this
    ->drupalLogin($admin);

  // Create FR.
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();

  // Set language detection to url and browser detection.
  $this
    ->drupalPostForm('/admin/config/regional/language/detection', [
    'language_interface[enabled][language-url]' => TRUE,
    'language_interface[enabled][language-browser]' => TRUE,
    'language_interface[enabled][language-selected]' => TRUE,
  ], 'Save settings');

  // Set prefixes to en and fr.
  $this
    ->drupalPostForm('/admin/config/regional/language/detection/url', [
    'prefix[en]' => 'en',
    'prefix[fr]' => 'fr',
  ], 'Save configuration');

  // Add language codes to browser detection.
  $this
    ->drupalPostForm('/admin/config/regional/language/detection/browser', [
    'new_mapping[browser_langcode]' => 'fr',
    'new_mapping[drupal_langcode]' => 'fr',
  ], 'Save configuration');
  $this
    ->drupalPostForm('/admin/config/regional/language/detection/browser', [
    'new_mapping[browser_langcode]' => 'en',
    'new_mapping[drupal_langcode]' => 'en',
  ], 'Save configuration');
  $this
    ->drupalPostForm('/admin/config/regional/language/detection/selected', [
    'edit-selected-langcode' => 'en',
  ], 'Save configuration');
  $this
    ->drupalLogout();
}