You are here

public function ConfigTranslationUiTest::testSourceValueDuplicateSave in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testSourceValueDuplicateSave()
  2. 10 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testSourceValueDuplicateSave()

Tests the site information translation interface.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php, line 234

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

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 = [
    '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 = [
    '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 = [
    '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.', [
    '@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 = [
    '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
    ->assertSession()
    ->statusCodeEquals(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
    ->assertSession()
    ->linkNotExists(t('Edit'));

  // Check 'Add' link for French.
  $this
    ->assertLinkByHref("{$translation_base_url}/fr/add");
}