LanguageConfigFactoryOverrideTest.php 1.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

namespace Drupal\Tests\language\Kernel;

use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\KernelTests\KernelTestBase;

/**
 * Tests \Drupal\language\Config\LanguageConfigFactoryOverride.
 *
 * @group language
 */
class LanguageConfigFactoryOverrideTest extends KernelTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
20
  protected static $modules = ['system', 'language'];
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

  /**
   * Tests language.config_factory_override service has the default language.
   */
  public function testLanguageConfigFactoryOverride() {
    $this->installConfig('system');
    $this->installConfig('language');

    /** @var \Drupal\language\Config\LanguageConfigFactoryOverride $config_factory_override */
    $config_factory_override = \Drupal::service('language.config_factory_override');
    $this->assertEquals('en', $config_factory_override->getLanguage()->getId());

    ConfigurableLanguage::createFromLangcode('de')->save();

    // Invalidate the container.
    $this->config('system.site')->set('default_langcode', 'de')->save();
37
    $this->container->get('kernel')->rebuildContainer();
38
39
40
41
42
43

    $config_factory_override = \Drupal::service('language.config_factory_override');
    $this->assertEquals('de', $config_factory_override->getLanguage()->getId());
  }

}