public function TranslatorTest::testRemoteLanguagesMappings

Tests remote languages mappings support in the tmgmt core.

File

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

Class

TranslatorTest
Verifies functionality of translator handling

Namespace

Drupal\Tests\tmgmt\Functional

Code

public function testRemoteLanguagesMappings() {
  $mappings = $this->default_translator
    ->getRemoteLanguagesMappings();
  $this
    ->assertEquals(array(
    'en' => 'en-us',
    'de' => 'de-ch',
    'el' => 'el',
    'es' => 'es',
  ), $mappings);
  $this
    ->assertEquals('en-us', $this->default_translator
    ->mapToRemoteLanguage('en'));
  $this
    ->assertEquals('de-ch', $this->default_translator
    ->mapToRemoteLanguage('de'));
  $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
    ->assertEquals('en-uk', $this->default_translator
    ->mapToRemoteLanguage('en'));
  $this
    ->assertEquals('de-de', $this->default_translator
    ->mapToRemoteLanguage('de'));

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