You are here

protected function RouteCachingNonPathLanguageNegotiationTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php \Drupal\FunctionalTests\Routing\RouteCachingNonPathLanguageNegotiationTest::setUp()

Overrides BrowserTestBase::setUp

File

core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php, line 38

Class

RouteCachingNonPathLanguageNegotiationTest
Tests the route cache when the language is not in the path.

Namespace

Drupal\FunctionalTests\Routing

Code

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

  // Create and log in user.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer blocks',
    'administer languages',
    'access administration pages',
  ]);
  $this
    ->drupalLogin($this->adminUser);

  // Add language.
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();

  // Enable session language detection and selection.
  $edit = [
    'language_interface[enabled][language-url]' => FALSE,
    'language_interface[enabled][language-session]' => TRUE,
  ];
  $this
    ->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));

  // A more common scenario is domain-based negotiation but that can not be
  // tested. Session negotiation by default is not considered by the URL
  // language type that is used to resolve the alias. Explicitly enable
  // that to be able to test this scenario.
  // @todo Improve in https://www.drupal.org/project/drupal/issues/1125428.
  $this
    ->config('language.types')
    ->set('negotiation.language_url.enabled', [
    'language-session' => 0,
  ])
    ->save();

  // Enable the language switching block.
  $this
    ->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
    'id' => 'test_language_block',
  ]);
}