You are here

public function UpcastingTest::testEntityLanguage in Drupal 8

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()

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");
}