You are here

public function LingotekSystemSiteBulkTranslationTest::testSystemSiteTranslationUsingActions in Lingotek Translation 8

Tests that a config can be translated using the actions on the management page.

File

src/Tests/LingotekSystemSiteBulkTranslationTest.php, line 84

Class

LingotekSystemSiteBulkTranslationTest
Tests translating a config object using the bulk management form.

Namespace

Drupal\lingotek\Tests

Code

public function testSystemSiteTranslationUsingActions() {

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);

  // Add a language.
  ConfigurableLanguage::createFromLangcode('de')
    ->setThirdPartySetting('lingotek', 'locale', 'de_AT')
    ->save();

  // Go to the bulk config management page.
  $this
    ->goToConfigBulkManagementForm();
  $basepath = \Drupal::request()
    ->getBasePath();

  // I can init the upload of content.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/config/upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
  $edit = [
    'table[system.site_information_settings]' => TRUE,
    // System information.
    'operation' => 'upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // I can check current status.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/config/check_upload/system.site_information_settings/system.site_information_settings?destination=' . $basepath . '/admin/lingotek/config/manage');
  $edit = [
    'table[system.site_information_settings]' => TRUE,
    // System information.
    'operation' => 'check_upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  // Request the German (AT) translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
  $edit = [
    'table[system.site_information_settings]' => TRUE,
    // System information.
    'operation' => 'request_translation:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.added_target_locale'));

  // Check status of the Spanish translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/config/check_download/system.site_information_settings/system.site_information_settings/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
  $edit = [
    'table[system.site_information_settings]' => TRUE,
    // System information.
    'operation' => 'check_translation:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.checked_target_locale'));

  // Download the German translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/config/download/system.site_information_settings/system.site_information_settings/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
  $edit = [
    'table[system.site_information_settings]' => TRUE,
    // System information.
    'operation' => 'download:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.downloaded_locale'));

  // Now the link is to the workbench, and it opens in a new tab.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/de_AT');
  $workbench_link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/de_AT' and @target='_blank']");
  $this
    ->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}