public function ConfigTranslationUiTest::testSourceValueDuplicateSave in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php \Drupal\config_translation\Tests\ConfigTranslationUiTest::testSourceValueDuplicateSave()
Tests the site information translation interface.
File
- core/
modules/ config_translation/ src/ Tests/ ConfigTranslationUiTest.php, line 196 - Contains \Drupal\config_translation\Tests\ConfigTranslationUiTest.
Class
- ConfigTranslationUiTest
- Translate settings and entities to various languages.
Namespace
Drupal\config_translation\TestsCode
public function testSourceValueDuplicateSave() {
$this
->drupalLogin($this->adminUser);
$site_name = 'Site name for testing configuration translation';
$site_slogan = 'Site slogan for testing configuration translation';
$translation_base_url = 'admin/config/system/site-information/translate';
$this
->setSiteInformation($site_name, $site_slogan);
$this
->drupalGet($translation_base_url);
// Case 1: Update new value for site slogan and site name.
$edit = array(
'translation[config_names][system.site][name]' => 'FR ' . $site_name,
'translation[config_names][system.site][slogan]' => 'FR ' . $site_slogan,
);
// First time, no overrides, so just Add link.
$this
->drupalPostForm("{$translation_base_url}/fr/add", $edit, t('Save translation'));
// Read overridden file from active config.
$override = \Drupal::languageManager()
->getLanguageConfigOverride('fr', 'system.site');
// Expect both name and slogan in language specific file.
$expected = array(
'name' => 'FR ' . $site_name,
'slogan' => 'FR ' . $site_slogan,
);
$this
->assertEqual($expected, $override
->get());
// Case 2: Update new value for site slogan and default value for site name.
$this
->drupalGet("{$translation_base_url}/fr/edit");
// Assert that the language configuration does not leak outside of the
// translation form into the actual site name and slogan.
$this
->assertNoText('FR ' . $site_name);
$this
->assertNoText('FR ' . $site_slogan);
$edit = array(
'translation[config_names][system.site][name]' => $site_name,
'translation[config_names][system.site][slogan]' => 'FR ' . $site_slogan,
);
$this
->drupalPostForm(NULL, $edit, t('Save translation'));
$this
->assertRaw(t('Successfully updated @language translation.', array(
'@language' => 'French',
)));
$override = \Drupal::languageManager()
->getLanguageConfigOverride('fr', 'system.site');
// Expect only slogan in language specific file.
$expected = 'FR ' . $site_slogan;
$this
->assertEqual($expected, $override
->get('slogan'));
// Case 3: Keep default value for site name and slogan.
$this
->drupalGet("{$translation_base_url}/fr/edit");
$this
->assertNoText('FR ' . $site_slogan);
$edit = array(
'translation[config_names][system.site][name]' => $site_name,
'translation[config_names][system.site][slogan]' => $site_slogan,
);
$this
->drupalPostForm(NULL, $edit, t('Save translation'));
$override = \Drupal::languageManager()
->getLanguageConfigOverride('fr', 'system.site');
// Expect no language specific file.
$this
->assertTrue($override
->isNew());
// Check configuration page with translator user. Should have no access.
$this
->drupalLogout();
$this
->drupalLogin($this->translatorUser);
$this
->drupalGet('admin/config/system/site-information');
$this
->assertResponse(403);
// While translator can access the translation page, the edit link is not
// present due to lack of permissions.
$this
->drupalGet($translation_base_url);
$this
->assertNoLink(t('Edit'));
// Check 'Add' link for French.
$this
->assertLinkByHref("{$translation_base_url}/fr/add");
}