You are here

public function LingotekTaxonomyTermLongTitleTranslationTest::testBulkTermTranslationUsingActions in Lingotek Translation 3.6.x

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

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

File

tests/src/Functional/LingotekTaxonomyTermLongTitleTranslationTest.php, line 385

Class

LingotekTaxonomyTermLongTitleTranslationTest
Tests translating a taxonomy term with a very long title that doesn't fit.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testBulkTermTranslationUsingActions() {

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

  // Add a language.
  ConfigurableLanguage::createFromLangcode('de')
    ->setThirdPartySetting('lingotek', 'locale', 'de_AT')
    ->save();
  $bundle = $this->vocabulary
    ->id();
  $this
    ->saveLingotekContentTranslationSettings([
    'taxonomy_term' => [
      $bundle => [
        'profiles' => 'manual',
        'fields' => [
          'name' => 1,
          'description' => 1,
        ],
      ],
    ],
  ]);

  // Create a term.
  $edit = [];
  $edit['name[0][value]'] = 'Llamas are cool';
  $edit['description[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $this
    ->drupalPostForm("admin/structure/taxonomy/manage/{$bundle}/add", $edit, t('Save'));
  $this
    ->goToContentBulkManagementForm('taxonomy_term');

  // I can init the upload of content.
  $this
    ->assertLingotekUploadLink(1, 'taxonomy_term');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('taxonomy_term'),
  ];
  $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', 'taxonomy_term');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckUpload('taxonomy_term'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Request the German (AT) translation.
  $this
    ->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id', 'taxonomy_term');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForRequestTranslation('de', 'taxonomy_term'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.added_target_locale'));

  // Check status of the German (AT) translation.
  $this
    ->assertLingotekCheckTargetStatusLink('de_AT', 'dummy-document-hash-id', 'taxonomy_term');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => 'check_translation:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.checked_target_locale'));

  // Download the German (AT) translation.
  $this
    ->assertLingotekDownloadTargetLink('de_AT', 'dummy-document-hash-id', 'taxonomy_term');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    $this
      ->getBulkOperationFormName() => 'download:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Download translation. It must fail with a useful error message.
  $this
    ->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.');
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.downloaded_locale'));

  // Test the error is logged.
  $status = (bool) \Drupal::database()
    ->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
    ':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.",
  ]);
  $this
    ->assert($status, 'A watchdog message was logged for the length of the field.');

  // Check the right class is added.
  $this
    ->goToContentBulkManagementForm('taxonomy_term');
  $this
    ->assertTargetStatus('DE', Lingotek::STATUS_ERROR);

  // Check that the Target Status is Error
  $this->term = Term::load(1);
  $content_translation_service = \Drupal::service('lingotek.content_translation');
  $this
    ->assertIdentical(Lingotek::STATUS_ERROR, $content_translation_service
    ->getTargetStatus($this->term, 'de'));

  // Check that the link works
  $this
    ->clickLink('DE');
  $this
    ->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.');

  // Test the error is logged.
  $status = (bool) \Drupal::database()
    ->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
    ':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.",
  ]);
  $this
    ->assert($status, 'A watchdog message was logged for the length of the field.');
}