function ConfigTranslationUiSiteInformationTest::testSourceValueDuplicateSave

Same name in other branches
  1. 10 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiSiteInformationTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiSiteInformationTest::testSourceValueDuplicateSave()

Tests the site information translation interface.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationUiSiteInformationTest.php, line 124

Class

ConfigTranslationUiSiteInformationTest
Translate site information to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function testSourceValueDuplicateSave() : void {
    $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->drupalGet("{$translation_base_url}/fr/add");
    $this->submitForm($edit, '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->assertEquals($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->assertSession()
        ->pageTextNotContains('FR ' . $site_name);
    $this->assertSession()
        ->pageTextNotContains('FR ' . $site_slogan);
    $edit = [
        'translation[config_names][system.site][name]' => $site_name,
        'translation[config_names][system.site][slogan]' => 'FR ' . $site_slogan,
    ];
    $this->submitForm($edit, 'Save translation');
    $this->assertSession()
        ->pageTextContains('Successfully updated French translation.');
    $override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
    // Expect only slogan in language specific file.
    $expected = 'FR ' . $site_slogan;
    $this->assertEquals($expected, $override->get('slogan'));
    // Case 3: Keep default value for site name and slogan.
    $this->drupalGet("{$translation_base_url}/fr/edit");
    $this->assertSession()
        ->pageTextNotContains('FR ' . $site_slogan);
    $edit = [
        'translation[config_names][system.site][name]' => $site_name,
        'translation[config_names][system.site][slogan]' => $site_slogan,
    ];
    $this->submitForm($edit, '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('Edit');
    // Check 'Add' link for French.
    $this->assertSession()
        ->linkByHrefExists("{$translation_base_url}/fr/add");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.