function ConfigTranslationUiModulesTest::testViewsTranslationUI

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

Tests the views translation interface.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationUiModulesTest.php, line 163

Class

ConfigTranslationUiModulesTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function testViewsTranslationUI() : void {
    $this->drupalLogin($this->adminUser);
    $description = 'All content promoted to the front page.';
    $human_readable_name = 'Frontpage';
    $display_settings_default = 'Default';
    $display_options_default = '(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->assertSession()
        ->linkByHrefExists("{$translation_base_url}/fr/add");
    $this->clickLink('Add');
    // Make sure original text is present on this page.
    $this->assertSession()
        ->pageTextContains($description);
    $this->assertSession()
        ->pageTextContains($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_default . " FR",
        'translation[config_names][views.view.frontpage][display][default][display_options][title]' => $display_options_default . " FR",
    ];
    $this->drupalGet("{$translation_base_url}/fr/add");
    $this->submitForm($edit, 'Save translation');
    $this->assertSession()
        ->pageTextContains('Successfully saved French translation.');
    // Check for edit, delete links (and no 'add' link) for French language.
    $this->assertSession()
        ->linkByHrefNotExists("{$translation_base_url}/fr/add");
    $this->assertSession()
        ->linkByHrefExists("{$translation_base_url}/fr/edit");
    $this->assertSession()
        ->linkByHrefExists("{$translation_base_url}/fr/delete");
    // Check translation saved proper.
    $this->drupalGet("{$translation_base_url}/fr/edit");
    $this->assertSession()
        ->fieldValueEquals('translation[config_names][views.view.frontpage][description]', $description . " FR");
    $this->assertSession()
        ->fieldValueEquals('translation[config_names][views.view.frontpage][label]', $human_readable_name . " FR");
    $this->assertSession()
        ->fieldValueEquals('translation[config_names][views.view.frontpage][display][default][display_title]', $display_settings_default . " FR");
    $this->assertSession()
        ->fieldValueEquals('translation[config_names][views.view.frontpage][display][default][display_options][title]', $display_options_default . " FR");
}

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