You are here

public function LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  2. 4.0.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  3. 3.0.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  4. 3.1.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  5. 3.2.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  6. 3.3.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  7. 3.4.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  8. 3.5.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  9. 3.7.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()
  10. 3.8.x tests/src/Functional/LingotekContentTypeBulkTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeBulkTranslationTest::testCheckTranslationsAction()

Tests that all the statuses are set when using the Check Translations action.

File

tests/src/Functional/LingotekContentTypeBulkTranslationTest.php, line 1387

Class

LingotekContentTypeBulkTranslationTest
Tests translating a config entity using the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testCheckTranslationsAction() {
  $assert_session = $this
    ->assertSession();

  // Add a couple of languages.
  ConfigurableLanguage::create([
    'id' => 'de_AT',
    'label' => 'German (Austria)',
  ])
    ->setThirdPartySetting('lingotek', 'locale', 'de_AT')
    ->save();
  ConfigurableLanguage::createFromLangcode('ca')
    ->setThirdPartySetting('lingotek', 'locale', 'ca_ES')
    ->save();
  ConfigurableLanguage::createFromLangcode('it')
    ->setThirdPartySetting('lingotek', 'locale', 'it_IT')
    ->save();
  $this
    ->goToConfigBulkManagementForm('node_type');
  $basepath = \Drupal::request()
    ->getBasePath();

  // I can init the upload of content.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
  $edit = [
    'table[article]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('node_type'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // I can check current status.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
  $edit = [
    'table[article]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckUpload('node_type'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Assert that I could request translations.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');

  // Check statuses, that may been requested externally.
  $edit = [
    'table[article]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckTranslations('node_type'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Now Drupal knows that there are translations ready.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/download/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');

  // Even if I just add a new language.
  ConfigurableLanguage::createFromLangcode('de')
    ->setThirdPartySetting('lingotek', 'locale', 'de_DE')
    ->save();
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');

  // Ensure locales are handled correctly by setting manual values.
  \Drupal::state()
    ->set('lingotek.document_completion_statuses', [
    'de-AT' => 50,
    'de-DE' => 100,
    'es-MX' => 10,
  ]);
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Now Drupal knows which translations are ready.
  $assert_session
    ->linkByHrefNotExists($basepath . '/admin/lingotek/config/download/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/download/node_type/article/de_DE?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefNotExists($basepath . '/admin/lingotek/config/download/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/it_IT?destination=' . $basepath . '/admin/lingotek/config/manage');
  \Drupal::state()
    ->set('lingotek.document_completion_statuses', [
    'it-IT' => 100,
    'de-DE' => 50,
    'es-MX' => 10,
  ]);

  // Check all statuses again.
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // All translations must be updated according exclusively with the
  // information from the TMS.
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/de_AT?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/node_type/article/de_DE?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/check_download/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/request/node_type/article/ca_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
  $assert_session
    ->linkByHrefExists($basepath . '/admin/lingotek/config/download/node_type/article/it_IT?destination=' . $basepath . '/admin/lingotek/config/manage');

  // Source status must be kept too.
  $this
    ->assertSourceStatusStateCount(Lingotek::STATUS_CURRENT, 'EN', 1);
}