public function RouteCachingLanguageTest::testLinkTranslationWithAlias in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalTests/Routing/RouteCachingLanguageTest.php \Drupal\FunctionalTests\Routing\RouteCachingLanguageTest::testLinkTranslationWithAlias()
- 10 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 129
Class
- RouteCachingLanguageTest
- Tests that route lookup is cached by the current language.
Namespace
Drupal\FunctionalTests\RoutingCode
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
->drupalPostForm('node/add/page', $edit, t('Save'), $source_url_options);
// 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
->drupalPostForm('node/add/page', $edit, t('Save'), $source_url_options);
// 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(t('Add'));
// Do not change the link field.
$edit = [
'title[0][value]' => 'Translated link page',
'path[0][alias]' => '/translated-link-page',
];
$this
->drupalPostForm(NULL, $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');
}