You are here

public function LingotekTaxonomyTermLongTitleTranslationTest::testTermTranslationViaAPIWithAutomatedUpload in Lingotek Translation 8

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

File

src/Tests/LingotekTaxonomyTermLongTitleTranslationTest.php, line 126

Class

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

Namespace

Drupal\lingotek\Tests

Code

public function testTermTranslationViaAPIWithAutomatedUpload() {

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

  // 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 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']));

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

  // 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 value: name.');
}