You are here

public function ConfigTranslationUiTest::testPluralConfigStrings 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::testPluralConfigStrings()

Test translation of plural strings with multiple plural forms in config.

File

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

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\config_translation\Tests

Code

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

  // First import a .po file with multiple plural forms.
  // This will also automatically add the 'sl' language.
  $name = tempnam('temporary://', "sl_") . '.po';
  file_put_contents($name, $this
    ->getPoFile(4));
  $this
    ->drupalPostForm('admin/config/regional/translate/import', array(
    'langcode' => 'sl',
    'files[file]' => $name,
  ), t('Import'));

  // Translate the files view, as this one uses numeric formatters.
  $description = 'Singular form';
  $field_value = '1 place';
  $field_value_plural = '@count places';
  $translation_url = 'admin/structure/views/view/files/translate/sl/add';
  $this
    ->drupalGet($translation_url);

  // Make sure original text is present on this page, in addition to 2 new
  // empty fields.
  $this
    ->assertRaw($description);
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]', $field_value);
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]', $field_value_plural);
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]', '');
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]', '');

  // Then make sure it also works.
  $edit = [
    'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]' => $field_value . ' SL',
    'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]' => $field_value_plural . ' 1 SL',
    'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]' => $field_value_plural . ' 2 SL',
    'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]' => $field_value_plural . ' 3 SL',
  ];
  $this
    ->drupalPostForm($translation_url, $edit, t('Save translation'));

  // Make sure the values have changed.
  $this
    ->drupalGet($translation_url);
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]', "{$field_value} SL");
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]', "{$field_value_plural} 1 SL");
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]', "{$field_value_plural} 2 SL");
  $this
    ->assertFieldByName('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]', "{$field_value_plural} 3 SL");
}