You are here

protected function TwigTransTest::installLanguages in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::installLanguages()
  2. 10 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::installLanguages()

Helper function: install languages.

1 call to TwigTransTest::installLanguages()
TwigTransTest::setUp in core/modules/system/tests/src/Functional/Theme/TwigTransTest.php

File

core/modules/system/tests/src/Functional/Theme/TwigTransTest.php, line 199

Class

TwigTransTest
Tests Twig "trans" tags.

Namespace

Drupal\Tests\system\Functional\Theme

Code

protected function installLanguages() {
  $file_system = \Drupal::service('file_system');
  foreach ($this->languages as $langcode => $name) {

    // Generate custom .po contents for the language.
    $contents = $this
      ->poFileContents($langcode);
    if ($contents) {

      // Add test language for translation testing.
      $edit = [
        'predefined_langcode' => 'custom',
        'langcode' => $langcode,
        'label' => $name,
        'direction' => LanguageInterface::DIRECTION_LTR,
      ];

      // Install the language in Drupal.
      $this
        ->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
      $this
        ->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.');

      // Import the custom .po contents for the language.
      $filename = $file_system
        ->tempnam('temporary://', "po_") . '.po';
      file_put_contents($filename, $contents);
      $options = [
        'files[file]' => $filename,
        'langcode' => $langcode,
        'customized' => TRUE,
      ];
      $this
        ->drupalPostForm('admin/config/regional/translate/import', $options, t('Import'));
      $file_system
        ->unlink($filename);
    }
  }
  $this->container
    ->get('language_manager')
    ->reset();
}