function UpcastingTest::testEntityLanguage

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/ParamConverter/UpcastingTest.php \Drupal\Tests\system\Functional\ParamConverter\UpcastingTest::testEntityLanguage()
  2. 10 core/modules/system/tests/src/Functional/ParamConverter/UpcastingTest.php \Drupal\Tests\system\Functional\ParamConverter\UpcastingTest::testEntityLanguage()
  3. 11.x core/modules/system/tests/src/Functional/ParamConverter/UpcastingTest.php \Drupal\Tests\system\Functional\ParamConverter\UpcastingTest::testEntityLanguage()

Confirms entity is shown in user's language by default.

File

core/modules/system/tests/src/Functional/ParamConverter/UpcastingTest.php, line 70

Class

UpcastingTest
Tests upcasting of URL arguments to entities.

Namespace

Drupal\Tests\system\Functional\ParamConverter

Code

public function testEntityLanguage() {
    $language = ConfigurableLanguage::createFromLangcode('de');
    $language->save();
    \Drupal::configFactory()->getEditable('language.negotiation')
        ->set('url.prefixes', [
        'de' => 'de',
    ])
        ->save();
    // The container must be recreated after adding a new language.
    $this->rebuildContainer();
    $node = $this->drupalCreateNode([
        'title' => 'English label',
    ]);
    $translation = $node->addTranslation('de');
    $translation->setTitle('Deutscher Titel')
        ->save();
    $this->drupalGet("/paramconverter_test/node/" . $node->id() . "/test_language");
    $this->assertSession()
        ->pageTextContains("English label");
    $this->drupalGet("paramconverter_test/node/" . $node->id() . "/test_language", [
        'language' => $language,
    ]);
    $this->assertSession()
        ->pageTextContains("Deutscher Titel");
}

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