function LanguageListTest::testLanguageStates
Same name in other branches
- 9 core/modules/language/tests/src/Functional/LanguageListTest.php \Drupal\Tests\language\Functional\LanguageListTest::testLanguageStates()
- 10 core/modules/language/tests/src/Functional/LanguageListTest.php \Drupal\Tests\language\Functional\LanguageListTest::testLanguageStates()
- 11.x core/modules/language/tests/src/Functional/LanguageListTest.php \Drupal\Tests\language\Functional\LanguageListTest::testLanguageStates()
Functional tests for the language states (locked or configurable).
File
-
core/
modules/ language/ tests/ src/ Functional/ LanguageListTest.php, line 209
Class
- LanguageListTest
- Adds a new language and tests changing its status and the default language.
Namespace
Drupal\Tests\language\FunctionalCode
public function testLanguageStates() {
// Add some languages, and also lock some of them.
ConfigurableLanguage::create([
'label' => $this->randomMachineName(),
'id' => 'l1',
])
->save();
ConfigurableLanguage::create([
'label' => $this->randomMachineName(),
'id' => 'l2',
'locked' => TRUE,
])
->save();
ConfigurableLanguage::create([
'label' => $this->randomMachineName(),
'id' => 'l3',
])
->save();
ConfigurableLanguage::create([
'label' => $this->randomMachineName(),
'id' => 'l4',
'locked' => TRUE,
])
->save();
$expected_locked_languages = [
'l4' => 'l4',
'l2' => 'l2',
'und' => 'und',
'zxx' => 'zxx',
];
$expected_all_languages = [
'l4' => 'l4',
'l3' => 'l3',
'l2' => 'l2',
'l1' => 'l1',
'en' => 'en',
'und' => 'und',
'zxx' => 'zxx',
];
$expected_conf_languages = [
'l3' => 'l3',
'l1' => 'l1',
'en' => 'en',
];
$locked_languages = $this->container
->get('language_manager')
->getLanguages(LanguageInterface::STATE_LOCKED);
$this->assertEqual(array_diff_key($expected_locked_languages, $locked_languages), [], 'Locked languages loaded correctly.');
$all_languages = $this->container
->get('language_manager')
->getLanguages(LanguageInterface::STATE_ALL);
$this->assertEqual(array_diff_key($expected_all_languages, $all_languages), [], 'All languages loaded correctly.');
$conf_languages = $this->container
->get('language_manager')
->getLanguages();
$this->assertEqual(array_diff_key($expected_conf_languages, $conf_languages), [], 'Configurable languages loaded correctly.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.