You are here

public function LingotekNodeTranslationTest::testContentFormOperations in Lingotek Translation 3.8.x

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

Tests that the node operations are as expected.

File

tests/src/Functional/LingotekNodeTranslationTest.php, line 1430

Class

LingotekNodeTranslationTest
Tests translating a node.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testContentFormOperations() {

  // Create a node.
  $edit = [];
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
  $this
    ->saveAndPublishNodeForm($edit);

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

  // Check that we can add a translation for Spanish when content is not
  // uploaded.
  $this
    ->assertSession()
    ->linkExists('Add');
  $this
    ->assertSession()
    ->linkByHrefExists('/es/node/1/translations/add/en/es');

  // Upload the document.
  $this
    ->clickLink('Upload');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains('Uploaded 1 document to Lingotek.');

  // Check that we can add a translation for Spanish when content is just
  // uploaded.
  $this
    ->assertSession()
    ->linkExists('Add');
  $this
    ->assertSession()
    ->linkByHrefExists('/es/node/1/translations/add/en/es');

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

  // Check that we can add a translation for Spanish when content is correctly
  // uploaded.
  $this
    ->assertSession()
    ->linkExists('Add');
  $this
    ->assertSession()
    ->linkByHrefExists('/es/node/1/translations/add/en/es');

  // Request translation.
  $this
    ->clickLink('Request translation');
  $this
    ->assertSession()
    ->pageTextContains("Locale 'es_MX' was added as a translation target for node Llamas are cool.");
  $this
    ->assertSame('es_MX', \Drupal::state()
    ->get('lingotek.added_target_locale'));

  // Check that we can add a translation for Spanish when translation is
  // already requested.
  $this
    ->assertSession()
    ->linkExists('Add');
  $this
    ->assertSession()
    ->linkByHrefExists('/es/node/1/translations/add/en/es');

  // Check translation status.
  $this
    ->clickLink('Check translation status');
  $this
    ->assertSame('es_MX', \Drupal::state()
    ->get('lingotek.checked_target_locale'));
  $this
    ->assertSession()
    ->pageTextContains('The es_MX translation for node Llamas are cool is ready for download.');

  // Check that we can add a translation for Spanish when translation is
  // ready.
  $this
    ->assertSession()
    ->linkExists('Add');
  $this
    ->assertSession()
    ->linkByHrefExists('/es/node/1/translations/add/en/es');
  $this
    ->assertSession()
    ->linkExistsExact('Edit in Lingotek Workbench');
  $this
    ->assertSession()
    ->linkByHrefExists('/admin/lingotek/workbench/dummy-document-hash-id/es_MX');

  // Download translation.
  $this
    ->clickLink('Download completed translation');
  $this
    ->assertSession()
    ->pageTextContains('The translation of node Llamas are cool into es_MX has been downloaded.');
  $this
    ->assertSame('es_MX', \Drupal::state()
    ->get('lingotek.downloaded_locale'));

  // Check that we can edit a translation for Spanish when translation is
  // downloaded. Also locally.
  $this
    ->assertSession()
    ->linkExistsExact('Edit in Lingotek Workbench');
  $this
    ->assertSession()
    ->linkByHrefExists('/admin/lingotek/workbench/dummy-document-hash-id/es_MX');
  $this
    ->assertSession()
    ->linkExistsExact('Edit');
  $this
    ->assertSession()
    ->linkByHrefExists('/es/node/1/edit');

  // The content is translated and published.
  $this
    ->clickLink('Las llamas son chulas');
  $this
    ->assertSession()
    ->pageTextContains('Las llamas son chulas');
  $this
    ->assertSession()
    ->pageTextContains('Las llamas son muy chulas');
}