function ConfigTranslationUiTest::testPluralConfigStringsSourceElements

Same name in other branches
  1. 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testPluralConfigStringsSourceElements()
  2. 8.9.x core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testPluralConfigStringsSourceElements()
  3. 10 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testPluralConfigStringsSourceElements()

Tests plural source elements in configuration translation forms.

File

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

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function testPluralConfigStringsSourceElements() : void {
    $this->drupalLogin($this->adminUser);
    // Languages to test, with various number of plural forms.
    $languages = [
        'vi' => [
            'plurals' => 1,
            'expected' => [
                TRUE,
                FALSE,
                FALSE,
                FALSE,
            ],
        ],
        'fr' => [
            'plurals' => 2,
            'expected' => [
                TRUE,
                TRUE,
                FALSE,
                FALSE,
            ],
        ],
        'sl' => [
            'plurals' => 4,
            'expected' => [
                TRUE,
                TRUE,
                TRUE,
                TRUE,
            ],
        ],
    ];
    foreach ($languages as $langcode => $data) {
        // Import a .po file to add a new language with a given number of plural forms
        $name = \Drupal::service('file_system')->tempnam('temporary://', $langcode . '_') . '.po';
        file_put_contents($name, $this->getPoFile($data['plurals']));
        $this->drupalGet('admin/config/regional/translate/import');
        $this->submitForm([
            'langcode' => $langcode,
            'files[file]' => $name,
        ], 'Import');
        // Change the config langcode of the 'files' view.
        $config = \Drupal::service('config.factory')->getEditable('views.view.files');
        $config->set('langcode', $langcode);
        $config->save();
        // Go to the translation page of the 'files' view.
        $translation_url = 'admin/structure/views/view/files/translate/en/add';
        $this->drupalGet($translation_url);
        // Check if the expected number of source elements are present.
        foreach ($data['expected'] as $index => $expected) {
            if ($expected) {
                $this->assertSession()
                    ->responseContains('edit-source-config-names-viewsviewfiles-display-default-display-options-fields-count-format-plural-string-' . $index);
            }
            else {
                $this->assertSession()
                    ->responseNotContains('edit-source-config-names-viewsviewfiles-display-default-display-options-fields-count-format-plural-string-' . $index);
            }
        }
    }
}

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