You are here

public function RouteCachingLanguageTest::testLinkTranslationWithAlias in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/Routing/RouteCachingLanguageTest.php \Drupal\FunctionalTests\Routing\RouteCachingLanguageTest::testLinkTranslationWithAlias()

Creates content with a link field pointing to an alias of another language.

@dataProvider providerLanguage

File

core/tests/Drupal/FunctionalTests/Routing/RouteCachingLanguageTest.php, line 132

Class

RouteCachingLanguageTest
Tests that route lookup is cached by the current language.

Namespace

Drupal\FunctionalTests\Routing

Code

public function testLinkTranslationWithAlias($source_langcode) {
  $source_url_options = [
    'language' => ConfigurableLanguage::load($source_langcode),
  ];

  // Create a target node in the source language that is the link target.
  $edit = [
    'langcode[0][value]' => $source_langcode,
    'title[0][value]' => 'Target page',
    'path[0][alias]' => '/target-page',
  ];
  $this
    ->drupalGet('node/add/page', $source_url_options);
  $this
    ->submitForm($edit, 'Save');

  // Confirm that the alias works.
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->addressEquals($source_langcode . '/target-page');
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('Target page');

  // Create a second node that links to the first through the link field.
  $edit = [
    'langcode[0][value]' => $source_langcode,
    'title[0][value]' => 'Link page',
    'field_link[0][uri]' => '/target-page',
    'field_link[0][title]' => 'Target page',
    'path[0][alias]' => '/link-page',
  ];
  $this
    ->drupalGet('node/add/page', $source_url_options);
  $this
    ->submitForm($edit, 'Save');

  // Make sure the link node is displayed with a working link.
  $assert_session
    ->pageTextContains('Link page');
  $this
    ->clickLink('Target page');
  $assert_session
    ->addressEquals($source_langcode . '/target-page');
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('Target page');

  // Clear all caches, then add a translation for the link node.
  $this
    ->resetAll();
  $this
    ->drupalGet('link-page', $source_url_options);
  $this
    ->clickLink('Translate');
  $this
    ->clickLink('Add');

  // Do not change the link field.
  $edit = [
    'title[0][value]' => 'Translated link page',
    'path[0][alias]' => '/translated-link-page',
  ];
  $this
    ->submitForm($edit, 'Save (this translation)');
  $assert_session
    ->pageTextContains('Translated link page');

  // @todo Clicking on the link does not include the language prefix.
  $this
    ->drupalGet('target-page', $source_url_options);
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('Target page');
}