public function LanguageDependencyInjectionTest::testDependencyInjectedNewDefaultLanguage in Drupal 8
Same name and namespace in other branches
- 9 core/modules/language/tests/src/Kernel/LanguageDependencyInjectionTest.php \Drupal\Tests\language\Kernel\LanguageDependencyInjectionTest::testDependencyInjectedNewDefaultLanguage()
- 10 core/modules/language/tests/src/Kernel/LanguageDependencyInjectionTest.php \Drupal\Tests\language\Kernel\LanguageDependencyInjectionTest::testDependencyInjectedNewDefaultLanguage()
Test dependency injected Language object against a new default language object.
See also
\Drupal\Core\Language\Language
File
- core/
modules/ language/ tests/ src/ Kernel/ LanguageDependencyInjectionTest.php, line 33
Class
- LanguageDependencyInjectionTest
- Compares the default language from $GLOBALS against the dependency injected language object.
Namespace
Drupal\Tests\language\KernelCode
public function testDependencyInjectedNewDefaultLanguage() {
$default_language = ConfigurableLanguage::load(\Drupal::languageManager()
->getDefaultLanguage()
->getId());
// Change the language default object to different values.
$fr = ConfigurableLanguage::createFromLangcode('fr');
$fr
->save();
$this
->config('system.site')
->set('default_langcode', 'fr')
->save();
// The language system creates a Language object which contains the
// same properties as the new default language object.
$result = \Drupal::languageManager()
->getCurrentLanguage();
$this
->assertIdentical($result
->getId(), 'fr');
// Delete the language to check that we fallback to the default.
try {
$fr
->delete();
$this
->fail('Expected DeleteDefaultLanguageException thrown.');
} catch (DeleteDefaultLanguageException $e) {
// Expected exception; just continue testing.
}
// Re-save the previous default language and the delete should work.
$this
->config('system.site')
->set('default_langcode', $default_language
->getId())
->save();
$fr
->delete();
$result = \Drupal::languageManager()
->getCurrentLanguage();
$this
->assertIdentical($result
->getId(), $default_language
->getId());
}