You are here

public function ConfigTranslationUiTest::testViewsTranslationUI in Zircon Profile 8.0

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

Tests the views translation interface.

File

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

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\config_translation\Tests

Code

public function testViewsTranslationUI() {
  $this
    ->drupalLogin($this->adminUser);

  // Assert contextual link related to views.
  $ids = array(
    'entity.view.edit_form:view=frontpage:location=page&name=frontpage&display_id=page_1',
  );
  $response = $this
    ->renderContextualLinks($ids, 'node');
  $this
    ->assertResponse(200);
  $json = Json::decode($response);
  $this
    ->assertTrue(strpos($json[$ids[0]], 'Translate view'), 'Translate view contextual link added.');
  $description = 'All content promoted to the front page.';
  $human_readable_name = 'Frontpage';
  $display_settings_master = 'Master';
  $display_options_master = '(Empty)';
  $translation_base_url = 'admin/structure/views/view/frontpage/translate';
  $this
    ->drupalGet($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($description);
  $this
    ->assertRaw($human_readable_name);

  // Update Views Fields for French.
  $edit = array(
    'translation[config_names][views.view.frontpage][description]' => $description . " FR",
    'translation[config_names][views.view.frontpage][label]' => $human_readable_name . " FR",
    'translation[config_names][views.view.frontpage][display][default][display_title]' => $display_settings_master . " FR",
    'translation[config_names][views.view.frontpage][display][default][display_options][title]' => $display_options_master . " FR",
  );
  $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][views.view.frontpage][description]', $description . " FR");
  $this
    ->assertFieldByName('translation[config_names][views.view.frontpage][label]', $human_readable_name . " FR");
  $this
    ->assertFieldByName('translation[config_names][views.view.frontpage][display][default][display_title]', $display_settings_master . " FR");
  $this
    ->assertFieldByName('translation[config_names][views.view.frontpage][display][default][display_options][title]', $display_options_master . " FR");
}