class LanguageDependencyInjectionTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/language/tests/src/Kernel/LanguageDependencyInjectionTest.php \Drupal\Tests\language\Kernel\LanguageDependencyInjectionTest
- 9 core/modules/language/tests/src/Kernel/LanguageDependencyInjectionTest.php \Drupal\Tests\language\Kernel\LanguageDependencyInjectionTest
Compares the default language from $GLOBALS against the dependency injected language object.
@group language
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\Tests\language\Kernel\LanguageTestBase
- class \Drupal\Tests\language\Kernel\LanguageDependencyInjectionTest
- class \Drupal\Tests\language\Kernel\LanguageTestBase
Expanded class hierarchy of LanguageDependencyInjectionTest
File
- core/
modules/ language/ tests/ src/ Kernel/ LanguageDependencyInjectionTest.php, line 14
Namespace
Drupal\Tests\language\KernelView source
class LanguageDependencyInjectionTest extends LanguageTestBase {
/**
* Tests dependency injected languages against a new Language object.
*
* @see \Drupal\Core\Language\LanguageInterface
*/
public function testDependencyInjectedNewLanguage() {
$expected = $this->languageManager
->getDefaultLanguage();
$result = $this->languageManager
->getCurrentLanguage();
$this
->assertSame($expected, $result);
}
/**
* Tests dependency injected Language object.
*
* @see \Drupal\Core\Language\Language
*/
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
->assertSame('fr', $result
->getId());
// 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
->assertSame($default_language
->getId(), $result
->getId());
}
}