function NodeTypeTranslationTest::testNodeTypeTranslation
Same name in other branches
- 9 core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTranslation()
- 8.9.x core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTranslation()
- 10 core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTranslation()
Tests the node type translation.
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeTypeTranslationTest.php, line 105
Class
- NodeTypeTranslationTest
- Ensures that node types translation work correctly.
Namespace
Drupal\Tests\node\FunctionalCode
public function testNodeTypeTranslation() : void {
$type = $this->randomMachineName(16);
$name = $this->randomString();
$this->drupalLogin($this->adminUser);
$this->drupalCreateContentType([
'type' => $type,
'name' => $name,
]);
// Translate the node type name.
$langcode = $this->additionalLangcodes[0];
$translated_name = $langcode . '-' . $name;
$edit = [
"translation[config_names][node.type.{$type}][name]" => $translated_name,
];
// Edit the title label to avoid having an exception when we save the translation.
$this->drupalGet("admin/structure/types/manage/{$type}/translate/{$langcode}/add");
$this->submitForm($edit, 'Save translation');
// Check the name is translated without admin theme for editing.
$this->drupalGet('admin/appearance');
$this->submitForm([
'use_admin_theme' => '0',
], 'Save configuration');
$this->drupalGet("{$langcode}/node/add/{$type}");
// This is a Spanish page, so ensure the text asserted is translated in
// Spanish and not French by adding the langcode option.
$this->assertSession()
->responseContains(t('Create @name', [
'@name' => $translated_name,
], [
'langcode' => $langcode,
]));
// Check the name is translated with admin theme for editing.
$this->drupalGet('admin/appearance');
$this->submitForm([
'use_admin_theme' => '1',
], 'Save configuration');
$this->drupalGet("{$langcode}/node/add/{$type}");
// This is a Spanish page, so ensure the text asserted is translated in
// Spanish and not French by adding the langcode option.
$this->assertSession()
->responseContains(t('Create @name', [
'@name' => $translated_name,
], [
'langcode' => $langcode,
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.