You are here

public function ConfigSourceUnitTest::testAccountSettings in Translation Management Tool 8

Tests the user config entity.

File

sources/tmgmt_config/tests/src/Kernel/ConfigSourceUnitTest.php, line 188

Class

ConfigSourceUnitTest
Unit tests for exporting translatable data from config entities and saving it back.

Namespace

Drupal\Tests\tmgmt_config\Kernel

Code

public function testAccountSettings() {
  $this
    ->installConfig([
    'user',
  ]);
  $this
    ->config('user.settings')
    ->set('anonymous', 'Test Anonymous')
    ->save();
  $job = tmgmt_job_create('en', 'de');
  $job->translator = 'test_translator';
  $job
    ->save();
  $job_item = tmgmt_job_item_create('config', '_simple_config', 'entity.user.admin_form', array(
    'tjid' => $job
      ->id(),
  ));
  $job_item
    ->save();
  $source_plugin = $this->container
    ->get('plugin.manager.tmgmt.source')
    ->createInstance('config');
  $data = $source_plugin
    ->getData($job_item);

  // Test the name property.
  $this
    ->assertEqual($data['user__settings']['anonymous']['#label'], 'Name');
  $this
    ->assertEqual($data['user__settings']['anonymous']['#text'], 'Test Anonymous');
  $this
    ->assertEqual($data['user__settings']['anonymous']['#translate'], TRUE);

  // Test item types.
  $this
    ->assertEqual($source_plugin
    ->getItemTypes()['view'], t('View'));

  // Now request a translation and save it back.
  $job
    ->requestTranslation();
  $items = $job
    ->getItems();
  $item = reset($items);
  $item
    ->acceptTranslation();
  $data = $item
    ->getData();

  // Check that the translations were saved correctly.
  $language_manager = \Drupal::languageManager();
  $language_manager
    ->setConfigOverrideLanguage($language_manager
    ->getLanguage('de'));
  $this
    ->assertEqual(\Drupal::config('user.settings')
    ->get('anonymous'), $data['user__settings']['anonymous']['#translation']['#text']);
}