protected function RouteCachingLanguageTest::setUp in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/FunctionalTests/Routing/RouteCachingLanguageTest.php \Drupal\FunctionalTests\Routing\RouteCachingLanguageTest::setUp()
Overrides BrowserTestBase::setUp
File
- core/
tests/ Drupal/ FunctionalTests/ Routing/ RouteCachingLanguageTest.php, line 43
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.
ConfigurableLanguage::createFromLangcode('fr')
->save();
// Enable translation for page node.
$edit = [
'entity_types[node]' => 1,
'settings[node][page][translatable]' => 1,
'settings[node][page][fields][path]' => 1,
'settings[node][page][fields][body]' => 1,
'settings[node][page][settings][language][language_alterable]' => 1,
];
$this
->drupalGet('admin/config/regional/content-language');
$this
->submitForm($edit, 'Save configuration');
// 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.
$edit = [
'language_interface[enabled][language-url]' => 1,
];
$this
->drupalGet('admin/config/regional/language/detection');
$this
->submitForm($edit, 'Save settings');
$edit = [
'prefix[en]' => 'en',
];
$this
->drupalGet('admin/config/regional/language/detection/url');
$this
->submitForm($edit, 'Save configuration');
// 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.');
}