function ConfigTranslationUiTest::testSiteInformationTranslationUi
Same name in other branches
- 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testSiteInformationTranslationUi()
Tests the site information translation interface.
File
-
core/
modules/ config_translation/ tests/ src/ Functional/ ConfigTranslationUiTest.php, line 132
Class
- ConfigTranslationUiTest
- Translate settings and entities to various languages.
Namespace
Drupal\Tests\config_translation\FunctionalCode
public function testSiteInformationTranslationUi() {
$this->drupalLogin($this->adminUser);
$site_name = 'Name of the site for testing configuration translation';
$site_slogan = 'Site slogan for testing configuration translation';
$site_name_label = 'Site name';
$fr_site_name = 'Nom du site pour tester la configuration traduction';
$fr_site_slogan = 'Slogan du site pour tester la traduction de configuration';
$fr_site_name_label = 'Libellé du champ "Nom du site"';
$translation_base_url = 'admin/config/system/site-information/translate';
// Set site name and slogan for default language.
$this->setSiteInformation($site_name, $site_slogan);
$this->drupalGet('admin/config/system/site-information');
// Check translation tab exist.
$this->assertLinkByHref($translation_base_url);
$this->drupalGet($translation_base_url);
// Check that the 'Edit' link in the source language links back to the
// original form.
$this->clickLink(t('Edit'));
// Also check that saving the form leads back to the translation overview.
$this->drupalPostForm(NULL, [], t('Save configuration'));
$this->assertUrl($translation_base_url);
// Check 'Add' link of French to visit add page.
$this->assertLinkByHref("{$translation_base_url}/fr/add");
$this->clickLink(t('Add'));
// Make sure original text is present on this page.
$this->assertRaw($site_name);
$this->assertRaw($site_slogan);
// Update site name and slogan for French.
$edit = [
'translation[config_names][system.site][name]' => $fr_site_name,
'translation[config_names][system.site][slogan]' => $fr_site_slogan,
];
$this->drupalPostForm("{$translation_base_url}/fr/add", $edit, t('Save translation'));
$this->assertRaw(t('Successfully saved @language translation.', [
'@language' => 'French',
]));
// Check for edit, delete links (and no 'add' link) for French language.
$this->assertNoLinkByHref("{$translation_base_url}/fr/add");
$this->assertLinkByHref("{$translation_base_url}/fr/edit");
$this->assertLinkByHref("{$translation_base_url}/fr/delete");
// Check translation saved proper.
$this->drupalGet("{$translation_base_url}/fr/edit");
$this->assertFieldByName('translation[config_names][system.site][name]', $fr_site_name);
$this->assertFieldByName('translation[config_names][system.site][slogan]', $fr_site_slogan);
// Place branding block with site name and slogan into header region.
$this->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
]);
// Check French translation of site name and slogan are in place.
$this->drupalGet('fr');
$this->assertRaw($fr_site_name);
$this->assertRaw($fr_site_slogan);
// Visit French site to ensure base language string present as source.
$this->drupalGet("fr/{$translation_base_url}/fr/edit");
$this->assertText($site_name);
$this->assertText($site_slogan);
// Translate 'Site name' label in French.
$search = [
'string' => $site_name_label,
'langcode' => 'fr',
'translation' => 'untranslated',
];
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$textarea = current($this->xpath('//textarea'));
$lid = $textarea->getAttribute('name');
$edit = [
$lid => $fr_site_name_label,
];
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
// Ensure that the label is in French (and not in English).
$this->drupalGet("fr/{$translation_base_url}/fr/edit");
$this->assertText($fr_site_name_label);
$this->assertNoText($site_name_label);
// Ensure that the label is also in French (and not in English)
// when editing another language with the interface in French.
$this->drupalGet("fr/{$translation_base_url}/ta/edit");
$this->assertText($fr_site_name_label);
$this->assertNoText($site_name_label);
// Ensure that the label is not translated when the interface is in English.
$this->drupalGet("{$translation_base_url}/fr/edit");
$this->assertText($site_name_label);
$this->assertNoText($fr_site_name_label);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.