You are here

public function EntityUrlLanguageTest::testEntityUrlLanguageWithLanguageContentEnabled in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/Tests/EntityUrlLanguageTest.php \Drupal\language\Tests\EntityUrlLanguageTest::testEntityUrlLanguageWithLanguageContentEnabled()

Ensures correct entity URLs with the method language-content-entity enabled.

Test case with the method language-content-entity enabled and configured with higher and also with lower priority than the method language-url.

File

core/modules/language/src/Tests/EntityUrlLanguageTest.php, line 75
Contains \Drupal\language\Tests\EntityUrlLanguageTest.

Class

EntityUrlLanguageTest
Tests the language of entity URLs. @group language

Namespace

Drupal\language\Tests

Code

public function testEntityUrlLanguageWithLanguageContentEnabled() {

  // Define the method language-content-entity with a higher priority than
  // language-url.
  $config = $this
    ->config('language.types');
  $config
    ->set('configurable', [
    LanguageInterface::TYPE_INTERFACE,
    LanguageInterface::TYPE_CONTENT,
  ]);
  $config
    ->set('negotiation.language_content.enabled', [
    LanguageNegotiationContentEntity::METHOD_ID => 0,
    LanguageNegotiationUrl::METHOD_ID => 1,
  ]);
  $config
    ->save();

  // Without being on an content entity route the default entity URL tests
  // should still pass.
  $this
    ->testEntityUrlLanguage();

  // Now switching to an entity route, so that the URL links are generated
  // while being on an entity route.
  $this
    ->setCurrentRequestForRoute('/entity_test/{entity_test}', 'entity.entity_test.canonical');

  // The method language-content-entity should run before language-url and
  // append query parameter for the content language and prevent language-url
  // from overwriting the url.
  $this
    ->assertTrue(strpos($this->entity
    ->urlInfo('canonical')
    ->toString(), '/en/entity_test/' . $this->entity
    ->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=en') !== FALSE);
  $this
    ->assertTrue(strpos($this->entity
    ->getTranslation('es')
    ->urlInfo('canonical')
    ->toString(), '/en/entity_test/' . $this->entity
    ->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=es') !== FALSE);
  $this
    ->assertTrue(strpos($this->entity
    ->getTranslation('fr')
    ->urlInfo('canonical')
    ->toString(), '/en/entity_test/' . $this->entity
    ->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=fr') !== FALSE);

  // Define the method language-url with a higher priority than
  // language-content-entity. This configuration should match the default one,
  // where the language-content-entity is turned off.
  $config
    ->set('negotiation.language_content.enabled', [
    LanguageNegotiationUrl::METHOD_ID => 0,
    LanguageNegotiationContentEntity::METHOD_ID => 1,
  ]);
  $config
    ->save();

  // The default entity URL tests should pass again with the current
  // configuration.
  $this
    ->testEntityUrlLanguage();
}