function RouteCachingLanguageTest::setUp
Same name in other branches
- 9 core/tests/Drupal/FunctionalTests/Routing/RouteCachingLanguageTest.php \Drupal\FunctionalTests\Routing\RouteCachingLanguageTest::setUp()
- 8.9.x core/tests/Drupal/FunctionalTests/Routing/RouteCachingLanguageTest.php \Drupal\FunctionalTests\Routing\RouteCachingLanguageTest::setUp()
- 10 core/tests/Drupal/FunctionalTests/Routing/RouteCachingLanguageTest.php \Drupal\FunctionalTests\Routing\RouteCachingLanguageTest::setUp()
Overrides BrowserTestBase::setUp
File
-
core/
tests/ Drupal/ FunctionalTests/ Routing/ RouteCachingLanguageTest.php, line 49
Class
- RouteCachingLanguageTest
- Tests that route lookup is cached by the current language.
Namespace
Drupal\FunctionalTests\RoutingCode
protected function setUp() : void {
parent::setUp();
$this->createContentType([
'type' => 'page',
]);
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('page_title_block');
$permissions = [
'access administration pages',
'administer content translation',
'administer content types',
'administer languages',
'administer url aliases',
'create content translations',
'create page content',
'create url aliases',
'edit any page content',
'translate any entity',
];
// Create and log in user.
$this->webUser = $this->drupalCreateUser($permissions);
$this->drupalLogin($this->webUser);
// Enable French language.
static::createLanguageFromLangcode('fr');
// Enable translation for page node.
static::enableContentTranslation('node', 'page');
// Create a field with settings to validate.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_link',
'entity_type' => 'node',
'type' => 'link',
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'settings' => [
'title' => DRUPAL_OPTIONAL,
'link_type' => LinkItemInterface::LINK_GENERIC,
],
]);
$field->save();
\Drupal::service('entity_display.repository')->getFormDisplay('node', 'page', 'default')
->setComponent('field_link', [
'type' => 'link_default',
])
->save();
\Drupal::service('entity_display.repository')->getViewDisplay('node', 'page', 'full')
->setComponent('field_link', [
'type' => 'link',
])
->save();
// Enable URL language detection and selection and set a prefix for both
// languages.
\Drupal::configFactory()->getEditable('language.types')
->set('negotiation.language_interface.enabled.language_url', 1)
->save();
\Drupal::configFactory()->getEditable('language.negotiation')
->set('url.prefixes.en', 'en')
->save();
// Reset the cache after changing the negotiation settings as that changes
// how links are built.
$this->resetAll();
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
$this->assertTrue($definitions['path']->isTranslatable(), 'Node path is translatable.');
$this->assertTrue($definitions['body']->isTranslatable(), 'Node body is translatable.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.