You are here

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

Test the number of source elements for plural strings in config translation forms.

File

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

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\config_translation\Tests

Code

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

  // Languages to test, with various number of plural forms.
  $languages = array(
    'vi' => array(
      'plurals' => 1,
      'expected' => array(
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ),
    ),
    'fr' => array(
      'plurals' => 2,
      'expected' => array(
        TRUE,
        TRUE,
        FALSE,
        FALSE,
      ),
    ),
    'sl' => array(
      'plurals' => 4,
      'expected' => array(
        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 = tempnam('temporary://', $langcode . '_') . '.po';
    file_put_contents($name, $this
      ->getPoFile($data['plurals']));
    $this
      ->drupalPostForm('admin/config/regional/translate/import', array(
      'langcode' => $langcode,
      'files[file]' => $name,
    ), t('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
          ->assertRaw('edit-source-config-names-viewsviewfiles-display-default-display-options-fields-count-format-plural-string-' . $index);
      }
      else {
        $this
          ->assertNoRaw('edit-source-config-names-viewsviewfiles-display-default-display-options-fields-count-format-plural-string-' . $index);
      }
    }
  }
}