You are here

public function ConfigTranslationUiTest::testSiteInformationTranslationUi in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php \Drupal\config_translation\Tests\ConfigTranslationUiTest::testSiteInformationTranslationUi()

Tests the site information translation interface.

File

core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php, line 127
Contains \Drupal\config_translation\Tests\ConfigTranslationUiTest.

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\config_translation\Tests

Code

public function testSiteInformationTranslationUi() {
  $this
    ->drupalLogin($this->adminUser);
  $site_name = 'Site name for testing configuration translation';
  $site_slogan = 'Site slogan for testing configuration translation';
  $fr_site_name = 'Nom du site pour tester la configuration traduction';
  $fr_site_slogan = 'Slogan du site pour tester la traduction de configuration';
  $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 = array(
    '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.', array(
    '@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);
}