You are here

public function LingotekTaxonomyTermLongTitleTranslationTest::testBulkTermTranslationUsingLinks in Lingotek Translation 3.4.x

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

Tests that a taxonomy term can be translated using the links on the management page.

File

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

Class

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

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testBulkTermTranslationUsingLinks() {

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);
  $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');

  // Clicking English must init the upload of content.
  $this
    ->assertLingotekUploadLink(1, 'taxonomy_term');

  // And we cannot request yet a translation.
  $this
    ->assertNoLingotekRequestTranslationLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
  $this
    ->clickLink('EN');
  $this
    ->assertText('Taxonomy_term Llamas are cool has been uploaded.');
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // There is a link for checking status.
  $this
    ->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'taxonomy_term');

  // And we can already request a translation.
  $this
    ->assertLingotekRequestTranslationLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
  $this
    ->clickLink('EN');
  $this
    ->assertText('The import for taxonomy_term Llamas are cool is complete.');

  // Request the Spanish translation.
  $this
    ->assertLingotekRequestTranslationLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
  $this
    ->clickLink('ES');
  $this
    ->assertText("Locale 'es_ES' was added as a translation target for taxonomy_term Llamas are cool.");
  $this
    ->assertIdentical('es_ES', \Drupal::state()
    ->get('lingotek.added_target_locale'));

  // Check status of the Spanish translation.
  $this
    ->assertLingotekCheckTargetStatusLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
  $this
    ->clickLink('ES');
  $this
    ->assertIdentical('es_ES', \Drupal::state()
    ->get('lingotek.checked_target_locale'));
  $this
    ->assertText('The es_ES translation for taxonomy_term Llamas are cool is ready for download.');

  // Download translation. It must fail with a useful error message.
  $this
    ->assertLingotekDownloadTargetLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
  $this
    ->clickLink('ES');
  $this
    ->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) 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 (es_ES) 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('ES', '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, 'es'));

  // Check that the link works
  $this
    ->clickLink('ES');
  $this
    ->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) 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 (es_ES) value: name.",
  ]);
  $this
    ->assert($status, 'A watchdog message was logged for the length of the field.');
}