You are here

public function LingotekEntityTestBulkTranslationTest::testCheckTranslationsAction in Lingotek Translation 3.4.x

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

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

File

tests/src/Functional/LingotekEntityTestBulkTranslationTest.php, line 194

Class

LingotekEntityTestBulkTranslationTest
Tests translating the entity test using the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testCheckTranslationsAction() {

  // 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();

  // Create a entity_test_mul.
  $edit = [];
  $edit['name[0][value]'] = 'Llamas are cool';
  $edit['field_test_text[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
  $this
    ->drupalPostForm('/entity_test_mul/add/entity_test_mul', $edit, t('Save'));
  $this
    ->goToContentBulkManagementForm('entity_test_mul');

  // I can init the upload of content.
  $this
    ->assertLingotekUploadLink(1, 'entity_test_mul');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('entity_test_mul'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // I can check current status.
  $this
    ->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'entity_test_mul');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckUpload('entity_test_mul'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Assert that I could request translations.
  $this
    ->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');

  // Check statuses, that may been requested externally.
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckTranslations('entity_test_mul'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Now Drupal knows that there are translations ready.
  $this
    ->assertLingotekDownloadTargetLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekDownloadTargetLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');

  // Even if I just add a new language.
  ConfigurableLanguage::createFromLangcode('de')
    ->setThirdPartySetting('lingotek', 'locale', 'de_DE')
    ->save();
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->assertLingotekDownloadTargetLink('de_DE', 'dummy-document-hash-id', 'entity_test_mul');

  // 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.
  $this
    ->assertNoLingotekDownloadTargetLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekDownloadTargetLink('de_DE', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertNoLingotekDownloadTargetLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekRequestTranslationLink('ca_ES', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekRequestTranslationLink('it_IT', 'dummy-document-hash-id', 'entity_test_mul');
  \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.
  $this
    ->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekCheckTargetStatusLink('de_DE', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekCheckTargetStatusLink('es_MX', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekRequestTranslationLink('ca_ES', 'dummy-document-hash-id', 'entity_test_mul');
  $this
    ->assertLingotekDownloadTargetLink('it_IT', 'dummy-document-hash-id', 'entity_test_mul');

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