You are here

public function ConfigurableLanguageManagerTest::testUrlContentTranslationWithSessionLanguage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithSessionLanguage()
  2. 10 core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithSessionLanguage()

Test translation with URL and Session Language Negotiators.

File

core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php, line 152

Class

ConfigurableLanguageManagerTest
Tests Language Negotiation.

Namespace

Drupal\Tests\language\Functional

Code

public function testUrlContentTranslationWithSessionLanguage() {
  $assert_session = $this
    ->assertSession();

  /** @var \Drupal\language\LanguageNegotiatorInterface $language_negotiator */
  $language_negotiator = \Drupal::getContainer()
    ->get('language_negotiator');

  // Set Interface Language Negotiator to Session.
  $language_negotiator
    ->saveConfiguration('language_interface', [
    'language-session' => 1,
    'language-url' => 2,
    'language-selected' => 3,
  ]);

  // Set Content Language Negotiator to URL.
  $language_negotiator
    ->saveConfiguration('language_content', [
    'language-url' => 4,
    'language-selected' => 5,
  ]);

  // See if the full view of the node in english is present and the
  // string in the Powered By Block is in English.
  $this
    ->drupalGet('/node/1');
  $assert_session
    ->pageTextContains('English');
  $assert_session
    ->pageTextContains('Powered by');

  // The language session variable has not been set yet, so
  // The string should be in Spanish.
  $this
    ->drupalGet('/es/node/1');
  $assert_session
    ->pageTextContains('Español');
  $assert_session
    ->pageTextNotContains('Powered by');
  $assert_session
    ->pageTextContains('Funciona con');

  // Set the session language to Spanish but load the English node page.
  $this
    ->drupalGet('/node/1', [
    'query' => [
      'language' => 'es',
    ],
  ]);
  $assert_session
    ->pageTextContains('English');
  $assert_session
    ->pageTextNotContains('Español');
  $assert_session
    ->pageTextContains('Funciona con');
  $assert_session
    ->pageTextNotContains('Powered by');

  // Set the session language to English but load the node page in Spanish.
  $this
    ->drupalGet('/es/node/1', [
    'query' => [
      'language' => 'en',
    ],
  ]);
  $assert_session
    ->pageTextNotContains('English');
  $assert_session
    ->pageTextContains('Español');
  $assert_session
    ->pageTextNotContains('Funciona con');
  $assert_session
    ->pageTextContains('Powered by');
}