You are here

public function TranslatorTest::testRemoteLanguagesMappings in Translation Management Tool 8

Tests remote languages mappings support in the tmgmt core.

File

tests/src/Functional/TranslatorTest.php, line 130

Class

TranslatorTest
Verifies functionality of translator handling

Namespace

Drupal\Tests\tmgmt\Functional

Code

public function testRemoteLanguagesMappings() {
  $mappings = $this->default_translator
    ->getRemoteLanguagesMappings();
  $this
    ->assertEqual($mappings, array(
    'en' => 'en-us',
    'de' => 'de-ch',
    'el' => 'el',
    'es' => 'es',
  ));
  $this
    ->assertEqual($this->default_translator
    ->mapToRemoteLanguage('en'), 'en-us');
  $this
    ->assertEqual($this->default_translator
    ->mapToRemoteLanguage('de'), 'de-ch');
  $remote_language_mappings = $this->default_translator
    ->get('remote_languages_mappings');
  $remote_language_mappings['de'] = 'de-de';
  $remote_language_mappings['en'] = 'en-uk';
  $this->default_translator
    ->set('remote_languages_mappings', $remote_language_mappings);
  $this->default_translator
    ->save();
  $this
    ->assertEqual($this->default_translator
    ->mapToRemoteLanguage('en'), 'en-uk');
  $this
    ->assertEqual($this->default_translator
    ->mapToRemoteLanguage('de'), 'de-de');

  // Test the fallback.
  $this->container
    ->get('state')
    ->set('tmgmt_test_translator_map_languages', FALSE);
  $this->container
    ->get('plugin.manager.tmgmt.translator')
    ->clearCachedDefinitions();
  $this
    ->assertEqual($this->default_translator
    ->mapToRemoteLanguage('en'), 'en');
  $this
    ->assertEqual($this->default_translator
    ->mapToRemoteLanguage('de'), 'de');
}