You are here

public function LingotekTaxonomyTermLongTitleTranslationTest::testTermTranslationViaAPIWithManualUpload in Lingotek Translation 3.5.x

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

Tests that a term can be translated when created via API with automated upload.

File

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

Class

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

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testTermTranslationViaAPIWithManualUpload() {

  // 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.
  $this->term = Term::create([
    'name' => 'Llamas are cool',
    'description' => 'Llamas are very cool',
    'langcode' => 'en',
    'vid' => $this->vocabulary
      ->id(),
  ]);
  $this->term
    ->save();

  // Check that the translate tab is in the taxonomy term.
  $this
    ->drupalGet('taxonomy/term/1');
  $this
    ->clickLink('Translate');

  // The document should not have been automatically uploaded, so let's upload it.
  $this
    ->clickLink('Upload');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertText('Uploaded 1 document to Lingotek.');

  // Check that only the configured fields have been uploaded.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->assertUploadedDataFieldCount($data, 2);
  $this
    ->assertTrue(isset($data['name'][0]['value']));
  $this
    ->assertEqual(1, count($data['description'][0]));
  $this
    ->assertTrue(isset($data['description'][0]['value']));

  // The document should have been automatically uploaded, so let's check
  // the upload status.
  $this
    ->clickLink('Check Upload Status');
  $this
    ->assertText('The import for taxonomy_term Llamas are cool is complete.');

  // Request translation.
  $this
    ->clickLink('Request translation');
  $this
    ->assertText("Locale 'es_ES' was added as a translation target for taxonomy_term Llamas are cool.");

  // Check translation status.
  $this
    ->clickLink('Check translation status');
  $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
    ->clickLink('Download completed translation');
  $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.');
}