protected function BookMultilingualTest::setCurrentLanguage in Drupal 10
Same name and namespace in other branches
- 9 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::setCurrentLanguage()
Sets the current language.
Parameters
string $langcode: The langcode. The content language will be set to this using the appropriate domain while the user language will be set to something else so subsequent tests catch errors where the interface language is used instead of the content language.
File
- core/
modules/ book/ tests/ src/ Kernel/ BookMultilingualTest.php, line 274
Class
- BookMultilingualTest
- Tests multilingual books.
Namespace
Drupal\Tests\book\KernelCode
protected function setCurrentLanguage(string $langcode) : void {
\Drupal::requestStack()
->push(Request::create("http://{$langcode}.book.test.domain/"));
$language_manager = $this->container
->get('language_manager');
$language_manager
->reset();
$current_user = \Drupal::currentUser();
$languages = $language_manager
->getLanguages();
unset($languages[$langcode]);
$current_user
->getAccount()
->set('preferred_langcode', reset($languages)
->getId());
$this
->assertNotSame($current_user
->getPreferredLangcode(), $langcode);
}