function LocaleConfigurableLanguageManagerTest::testGetLanguages

Same name in other branches
  1. 9 core/modules/locale/tests/src/Kernel/LocaleConfigurableLanguageManagerTest.php \Drupal\Tests\locale\Kernel\LocaleConfigurableLanguageManagerTest::testGetLanguages()
  2. 10 core/modules/locale/tests/src/Kernel/LocaleConfigurableLanguageManagerTest.php \Drupal\Tests\locale\Kernel\LocaleConfigurableLanguageManagerTest::testGetLanguages()
  3. 11.x core/modules/locale/tests/src/Kernel/LocaleConfigurableLanguageManagerTest.php \Drupal\Tests\locale\Kernel\LocaleConfigurableLanguageManagerTest::testGetLanguages()

File

core/modules/locale/tests/src/Kernel/LocaleConfigurableLanguageManagerTest.php, line 23

Class

LocaleConfigurableLanguageManagerTest
Tests that the configurable language manager and locale operate correctly.

Namespace

Drupal\Tests\locale\Kernel

Code

public function testGetLanguages() {
    $this->installSchema('locale', [
        'locales_source',
        'locales_target',
        'locales_location',
    ]);
    $default_language = new ConfigurableLanguage([
        'label' => $this->randomMachineName(),
        'id' => 'default',
        'weight' => 0,
    ], 'configurable_language');
    $default_language->save();
    // Set new default language.
    \Drupal::service('language.default')->set($default_language);
    \Drupal::service('string_translation')->setDefaultLangcode($default_language->getId());
    $languages = \Drupal::service('language_manager')->getLanguages(LanguageInterface::STATE_ALL);
    $this->assertEqual([
        'default',
        'und',
        'zxx',
    ], array_keys($languages));
    $configurableLanguage = new ConfigurableLanguage([
        'label' => $this->randomMachineName(),
        'id' => 'test',
        'weight' => 1,
    ], 'configurable_language');
    // Simulate a configuration sync by setting the flag otherwise the locked
    // language weights would be updated whilst saving.
    // @see \Drupal\language\Entity\ConfigurableLanguage::postSave()
    $configurableLanguage->setSyncing(TRUE)
        ->save();
    $languages = \Drupal::service('language_manager')->getLanguages(LanguageInterface::STATE_ALL);
    $this->assertEqual([
        'default',
        'test',
        'und',
        'zxx',
    ], array_keys($languages));
}

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