protected function BookMultilingualTest::setCurrentLanguage in Drupal 9
Same name and namespace in other branches
- 10 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.
3 calls to BookMultilingualTest::setCurrentLanguage()
- BookMultilingualTest::testMultilingualBookBreadcrumbBuilder in core/
modules/ book/ tests/ src/ Kernel/ BookMultilingualTest.php - Tests various book breadcrumb builder methods return correct translations.
- BookMultilingualTest::testMultilingualBookExport in core/
modules/ book/ tests/ src/ Kernel/ BookMultilingualTest.php - Tests the book export returns correct translations.
- BookMultilingualTest::testMultilingualBookManager in core/
modules/ book/ tests/ src/ Kernel/ BookMultilingualTest.php - Tests various book manager methods return correct translations.
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);
}