function ConfigTranslationUiTest::testViewsTranslationUI

Same name in other branches
  1. 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testViewsTranslationUI()

Tests the views translation interface.

File

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

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function testViewsTranslationUI() {
    $this->drupalLogin($this->adminUser);
    $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 = [
        '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.', [
        '@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");
}

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