You are here

public function LingotekNodeWorkbenchModerationTranslationTest::testNewRevisionCreatedWhenProcessing in Lingotek Translation 3.7.x

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

Tests that new revisions are created when processing with Lingotek.

File

tests/src/Functional/LingotekNodeWorkbenchModerationTranslationTest.php, line 84

Class

LingotekNodeWorkbenchModerationTranslationTest
Tests translating a node with workbench moderation enabled.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testNewRevisionCreatedWhenProcessing() {
  $assert_session = $this
    ->assertSession();

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

  // 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);
  $this
    ->goToContentBulkManagementForm();

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

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

  // Only one revision stored.

  /** @var \Drupal\node\NodeStorageInterface $node_storage */
  $node_storage = \Drupal::entityTypeManager()
    ->getStorage('node');
  $result = $node_storage
    ->getQuery()
    ->allRevisions()
    ->condition('nid', 1)
    ->sort('vid', 'DESC')
    ->pager(50)
    ->count()
    ->execute();
  $this
    ->assertEqual(1, $result, 'Only one revision is stored.');
  $this
    ->goToContentBulkManagementForm();

  // There is a link for checking status.
  $this
    ->assertLingotekCheckSourceStatusLink();

  // And we can already request a translation.
  $this
    ->assertLingotekRequestTranslationLink('es_MX');
  $this
    ->clickLink('EN');
  $this
    ->assertText('The import for node Llamas are cool is complete.');

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

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

  // Download the Spanish translation.
  $this
    ->assertLingotekDownloadTargetLink('es_MX');
  $this
    ->clickLink('ES');
  $this
    ->assertText('The translation of node Llamas are cool into es_MX has been downloaded.');
  $this
    ->assertIdentical('es_MX', \Drupal::state()
    ->get('lingotek.downloaded_locale'));

  // Now the link is to the workbench, and it opens in a new tab.
  $this
    ->assertLingotekWorkbenchLink('es_MX', 'dummy-document-hash-id', 'ES');

  // Open the node.
  $this
    ->clickLink('Llamas are cool');

  // There is a revisions tab as the translation creates a new revision.
  $assert_session
    ->linkExists('Revisions');
  $this
    ->clickLink('Revisions');
  $this
    ->drupalGet('es/node/1/revisions');
  $this
    ->assertText('Document translated into ES by Lingotek.');

  // Only one revision stored.

  /** @var \Drupal\node\NodeStorageInterface $node_storage */
  $node_storage = \Drupal::entityTypeManager()
    ->getStorage('node');
  $result = $node_storage
    ->getQuery()
    ->allRevisions()
    ->condition('nid', 1)
    ->sort('vid', 'DESC')
    ->pager(50)
    ->count()
    ->execute();
  $this
    ->assertEqual(2, $result, 'A new revision is stored.');
}