public function ConfigSourceUnitTest::testView

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
    ->assertEquals('Label', $data['label']['#label']);
  $this
    ->assertEquals($view
    ->label(), $data['label']['#text']);
  $this
    ->assertTrue($data['label']['#translate']);
  $this
    ->assertEquals('Administrative description', $data['description']['#label']);
  $this
    ->assertEquals('Gives a bulk operation overview of translation jobs in the system.', $data['description']['#text']);
  $this
    ->assertTrue($data['description']['#translate']);
  $this
    ->assertEquals('Master', $data['display']['default']['display_title']['#text']);
  $this
    ->assertEquals('Submit button text', $data['display']['default']['display_options']['exposed_form']['options']['submit_button']['#label']);
  $this
    ->assertEquals('Items per page label', $data['display']['default']['display_options']['pager']['options']['expose']['items_per_page_label']['#label']);

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

  // Test item types.
  $this
    ->assertEquals('View', $source_plugin
    ->getItemTypes()['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
    ->assertEquals($data['label']['#translation']['#text'], $view
    ->label());
  $this
    ->assertEquals($data['description']['#translation']['#text'], $view
    ->get('description'));
  $display = $view
    ->get('display');
  $this
    ->assertEquals($data['label']['#translation']['#text'], $display['default']['display_options']['title']);
  $this
    ->assertEquals($data['display']['default']['display_options']['exposed_form']['options']['submit_button']['#translation']['#text'], $display['default']['display_options']['exposed_form']['options']['submit_button']);
}