function UpcastingTest::testEntityLanguage

Same name and namespace in other branches
  1. 9 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 67

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->assertRaw("English label");
    $this->drupalGet("paramconverter_test/node/" . $node->id() . "/test_language", [
        'language' => $language,
    ]);
    $this->assertRaw("Deutscher Titel");
}

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