function RouteCachingNonPathLanguageNegotiationTest::setUp

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php \Drupal\FunctionalTests\Routing\RouteCachingNonPathLanguageNegotiationTest::setUp()
  2. 10 core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php \Drupal\FunctionalTests\Routing\RouteCachingNonPathLanguageNegotiationTest::setUp()
  3. 11.x core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php \Drupal\FunctionalTests\Routing\RouteCachingNonPathLanguageNegotiationTest::setUp()

Overrides BrowserTestBase::setUp

File

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

Class

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

Namespace

Drupal\FunctionalTests\Routing

Code

protected function setUp() : void {
    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->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, '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',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.