You are here

public function ConfigSourceUnitTest::testView in Translation Management Tool 8

Tests the view config entity

File

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

Class

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

Namespace

Drupal\Tests\tmgmt_config\Kernel

Code

public function testView() {
  $this
    ->installConfig([
    'system',
    'tmgmt',
  ]);
  $job = tmgmt_job_create('en', 'de');
  $job->translator = 'test_translator';
  $job
    ->save();
  $job_item = tmgmt_job_item_create('config', 'view', 'views.view.tmgmt_job_overview', array(
    'tjid' => $job
      ->id(),
  ));
  $job_item
    ->save();
  $view = View::load('tmgmt_job_overview');
  $source_plugin = $this->container
    ->get('plugin.manager.tmgmt.source')
    ->createInstance('config');
  $data = $source_plugin
    ->getData($job_item);

  // Test the name property.
  $this
    ->assertEqual($data['label']['#label'], 'Label');
  $this
    ->assertEqual($data['label']['#text'], $view
    ->label());
  $this
    ->assertEqual($data['label']['#translate'], TRUE);
  $this
    ->assertEqual($data['description']['#label'], 'Administrative description');
  $this
    ->assertEqual($data['description']['#text'], 'Gives a bulk operation overview of translation jobs in the system.');
  $this
    ->assertEqual($data['description']['#translate'], TRUE);
  $this
    ->assertEqual($data['display']['default']['display_title']['#text'], 'Master');
  $this
    ->assertEqual($data['display']['default']['display_options']['exposed_form']['options']['submit_button']['#label'], 'Submit button text');
  $this
    ->assertEqual($data['display']['default']['display_options']['pager']['options']['expose']['items_per_page_label']['#label'], 'Items per page label');

  // Tests for labels on more levels.
  $this
    ->assertEqual($data['display']['default']['display_options']['pager']['options']['expose']['#label'], 'Exposed options');
  $this
    ->assertEqual($data['display']['default']['display_options']['pager']['options']['#label'], 'Paged output, full pager');
  $this
    ->assertEqual($data['display']['default']['display_options']['pager']['#label'], 'Pager');
  $this
    ->assertEqual($data['display']['default']['display_options']['#label'], 'Default display options');
  $this
    ->assertEqual($data['display']['default']['#label'], 'Display settings');

  // 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'));
  $view = View::load('tmgmt_job_overview');
  $this
    ->assertEqual($view
    ->label(), $data['label']['#translation']['#text']);
  $this
    ->assertEqual($view
    ->get('description'), $data['description']['#translation']['#text']);
  $display = $view
    ->get('display');
  $this
    ->assertEqual($display['default']['display_options']['title'], $data['label']['#translation']['#text']);
  $this
    ->assertEqual($display['default']['display_options']['exposed_form']['options']['submit_button'], $data['display']['default']['display_options']['exposed_form']['options']['submit_button']['#translation']['#text']);
}