You are here

function ConfigSourceListTest::testSimpleConfigTranslation in Translation Management Tool 8

Test for simple configuration translation.

File

sources/tmgmt_config/tests/src/Functional/ConfigSourceListTest.php, line 226

Class

ConfigSourceListTest
Tests the user interface for entity translation lists.

Namespace

Drupal\Tests\tmgmt_config\Functional

Code

function testSimpleConfigTranslation() {
  $this
    ->loginAsTranslator(array(
    'translate configuration',
  ));

  // Go to the translate tab.
  $this
    ->drupalGet('admin/tmgmt/sources/config/_simple_config');

  // Assert some basic strings on that page.
  $this
    ->assertText(t('Simple configuration overview (Config Entity)'));

  // Request a translation for Site information settings.
  $edit = array(
    'items[system.site_information_settings]' => TRUE,
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Request translation'));

  // Verify that we are on the translate tab.
  $this
    ->assertText(t('One job needs to be checked out.'));
  $this
    ->assertText('System information (English to ?, Unprocessed)');

  // Submit.
  $this
    ->drupalPostForm(NULL, array(), t('Submit to provider'));

  // Make sure that we're back on the originally defined destination URL.
  $this
    ->assertUrl('admin/tmgmt/sources/config/_simple_config');
  $overview_url = Url::fromRoute('tmgmt.source_overview', array(
    'plugin' => 'config',
    'item_type' => '_simple_config',
  ))
    ->toString();

  // Translated languages should now be listed as Needs review.
  $url = JobItem::load(1)
    ->toUrl()
    ->setOption('query', [
    'destination' => $overview_url,
  ])
    ->toString();
  $imgs = $this
    ->xpath('//a[@href=:href]/img', [
    ':href' => $url,
  ]);
  $this
    ->assertEqual('Active job item: Needs review', $imgs[0]
    ->getAttribute('title'));
  $this
    ->assertText(t('Test translation created.'));
  $this
    ->assertText('The translation of System information to German is finished and can now be reviewed.');

  // Verify that the pending translation is shown.
  $review = $this
    ->xpath('//table[@id="edit-items"]/tbody/tr[@class="even"][1]/td[@class="langstatus-de"]/a');
  $destination = $this
    ->getAbsoluteUrl($review[0]
    ->getAttribute('href'));
  $this
    ->drupalGet($destination);
  $this
    ->drupalPostForm(NULL, array(), t('Save'));

  // Request a translation for Account settings
  $edit = array(
    'items[entity.user.admin_form]' => TRUE,
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Request translation'));

  // Verify that we are on the checkout page.
  $this
    ->assertText(t('One job needs to be checked out.'));
  $this
    ->assertText('Account settings (English to ?, Unprocessed)');
  $this
    ->drupalPostForm(NULL, array(), t('Submit to provider'));

  // Make sure that we're back on the originally defined destination URL.
  $this
    ->assertUrl('admin/tmgmt/sources/config/_simple_config');

  // Translated languages should now be listed as Needs review.
  $links = $this
    ->xpath('//table[@id="edit-items"]/tbody/tr/td/a');
  $this
    ->assertEquals(2, count($links));

  // Save one translation.
  $this
    ->drupalPostForm('admin/tmgmt/items/1', array(), t('Save as completed'));

  // Test if the filter works.
  $filters = array(
    'search[name]' => 'system',
  );
  $this
    ->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));

  // Check if the list has 2 rows.
  $this
    ->assertEqual(count($this
    ->xpath('//tbody/tr')), 2);
  $filters = array(
    'search[target_language]' => 'de',
    'search[target_status]' => 'translated',
  );
  $this
    ->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));

  // Just 1 simple configuration was translated.
  $this
    ->assertEqual(count($this
    ->xpath('//tbody/tr')), 1);

  // Filter with name and target_status.
  $filters = array(
    'search[name]' => 'settings',
    'search[target_language]' => 'de',
    'search[target_status]' => 'untranslated',
  );
  $this
    ->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));

  // There is 1 simple configuration untranslated with name 'settings'.
  $this
    ->assertEqual(count($this
    ->xpath('//tbody/tr')), 1);
  $filters = array(
    'search[name]' => 'sys',
    'search[target_language]' => 'de',
    'search[target_status]' => 'translated',
  );
  $this
    ->drupalPostForm('admin/tmgmt/sources/config/_simple_config', $filters, t('Search'));

  // There are 2 simple configurations with name 'sys' but just 1 is translated.
  $this
    ->assertEqual(count($this
    ->xpath('//tbody/tr')), 1);
}