function ConfigurableLanguageManagerTest::testUrlContentTranslationWithPreferredAdminLanguage

Same name in other branches
  1. 9 core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithPreferredAdminLanguage()
  2. 8.9.x core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithPreferredAdminLanguage()
  3. 10 core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithPreferredAdminLanguage()

Tests translation with URL and Preferred Admin Language negotiators.

The interface language uses the preferred language for admin pages of the user and after that the URL. The Content uses just the URL.

File

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

Class

ConfigurableLanguageManagerTest
Tests Language Negotiation.

Namespace

Drupal\Tests\language\Functional

Code

public function testUrlContentTranslationWithPreferredAdminLanguage() : void {
    $assert_session = $this->assertSession();
    // Set the interface language to use the preferred administration language
    // and then the URL.
    
    /** @var \Drupal\language\LanguageNegotiatorInterface $language_negotiator */
    $language_negotiator = \Drupal::getContainer()->get('language_negotiator');
    $language_negotiator->saveConfiguration('language_interface', [
        'language-user-admin' => 1,
        'language-url' => 2,
        'language-selected' => 3,
    ]);
    // Set Content Language Negotiator to use just the 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');
    // Load the spanish node page again and see if both the node and the string
    // are translated.
    $this->drupalGet('/es/node/1');
    $assert_session->pageTextContains('Español');
    $assert_session->pageTextContains('Funciona con');
    $assert_session->pageTextNotContains('Powered by');
    // Check if the Powered by string is shown in English on an
    // administration page, and the node content is shown in Spanish.
    $this->drupalGet('/es/node/1/edit');
    $assert_session->pageTextContains('Español');
    $assert_session->pageTextContains('Powered by');
    $assert_session->pageTextNotContains('Funciona con');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.