function LanguageDependencyInjectionTest::testDependencyInjectedNewDefaultLanguage in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/language/src/Tests/LanguageDependencyInjectionTest.php \Drupal\language\Tests\LanguageDependencyInjectionTest::testDependencyInjectedNewDefaultLanguage()
Test dependency injected Language object against a new default language object.
See also
\Drupal\Core\Language\Language
File
- core/
modules/ language/ src/ Tests/ LanguageDependencyInjectionTest.php, line 40 - Contains \Drupal\language\Tests\LanguageDependencyInjectionTest.
Class
- LanguageDependencyInjectionTest
- Compares the default language from $GLOBALS against the dependency injected language object.
Namespace
Drupal\language\TestsCode
function testDependencyInjectedNewDefaultLanguage() {
$default_language = ConfigurableLanguage::load(\Drupal::languageManager()
->getDefaultLanguage()
->getId());
// Change the language default object to different values.
ConfigurableLanguage::createFromLangcode('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 {
entity_delete_multiple('configurable_language', array(
'fr',
));
$this
->fail('Expected DeleteDefaultLanguageException thrown.');
} catch (DeleteDefaultLanguageException $e) {
$this
->pass('Expected DeleteDefaultLanguageException thrown.');
}
// Re-save the previous default language and the delete should work.
$this
->config('system.site')
->set('default_langcode', $default_language
->getId())
->save();
entity_delete_multiple('configurable_language', array(
'fr',
));
$result = \Drupal::languageManager()
->getCurrentLanguage();
$this
->assertIdentical($result
->getId(), $default_language
->getId());
}