You are here

public function ConfigSourceUnitTest::testSystemSite in Translation Management Tool 8

Tests the view of the system site.

File

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

Class

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

Namespace

Drupal\Tests\tmgmt_config\Kernel

Code

public function testSystemSite() {
  $this
    ->installConfig([
    'system',
  ]);
  $this
    ->config('system.site')
    ->set('slogan', 'Test slogan')
    ->save();
  $job = tmgmt_job_create('en', 'de');
  $job->translator = 'test_translator';
  $job
    ->save();
  $job_item = tmgmt_job_item_create('config', '_simple_config', 'system.site_information_settings', 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['slogan']['#label'], 'Slogan');
  $this
    ->assertEqual($data['slogan']['#text'], 'Test slogan');
  $this
    ->assertEqual($data['slogan']['#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('system.site')
    ->get('slogan'), $data['slogan']['#translation']['#text']);
}