You are here

protected function LanguageTest::setUp in Token 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/LanguageTest.php, line 88

Class

LanguageTest
Tests language tokens.

Namespace

Drupal\Tests\token\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this->token = $this->container
    ->get('token');

  // Use a version of the language manager in which the various languages can
  // be easily overridden during the test. We need to do this here instead of
  // in ::register() since the container is being altered by
  // LanguageServiceProvider::alter() after the services have been registered.
  $this->languageManager = new MockLanguageManager($this->container
    ->get('language.default'), $this->container
    ->get('config.factory'), $this->container
    ->get('module_handler'), $this->container
    ->get('language.config_factory_override'), $this->container
    ->get('request_stack'));
  $this->container
    ->set('language_manager', $this->languageManager);
  foreach ($this->langcodes as $langcode) {

    // Enable test languages.
    $this->languages[$langcode] = ConfigurableLanguage::createFromLangcode($langcode);
    $this->languages[$langcode]
      ->save();

    // Populate language prefixes and domains to use in the test.
    $this->language_prefixes[$langcode] = "{$langcode}-prefix";
    $this->language_domains[$langcode] = $langcode . '.example.com';
  }

  // Set language negotiation prefixes and domains to values that are uniquely
  // identifiable in the test.
  $language_negotiation_config = $this
    ->config('language.negotiation');
  $language_negotiation_config
    ->set('url.prefixes', $this->language_prefixes);
  $language_negotiation_config
    ->set('url.domains', $this->language_domains);
  $language_negotiation_config
    ->save();
}