function NodeTypeTranslationTest::testNodeTypeTranslation
Same name and namespace in other branches
- 9 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()
- 11.x 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 101
Class
- NodeTypeTranslationTest
- Ensures that node types translation work correctly.
Namespace
Drupal\Tests\node\FunctionalCode
public function testNodeTypeTranslation() {
$type = mb_strtolower($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->drupalPostForm("admin/structure/types/manage/{$type}/translate/{$langcode}/add", $edit, t('Save translation'));
// Check the name is translated without admin theme for editing.
$this->drupalPostForm('admin/appearance', [
'use_admin_theme' => '0',
], t('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->assertRaw(t('Create @name', [
'@name' => $translated_name,
], [
'langcode' => $langcode,
]));
// Check the name is translated with admin theme for editing.
$this->drupalPostForm('admin/appearance', [
'use_admin_theme' => '1',
], t('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->assertRaw(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.