You are here

public function LingotekContentModerationTest::testDraftRevisionDownloadDoesntOverwriteDraftNonDefaultRevision in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 3.7.x tests/src/Functional/LingotekContentModerationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentModerationTest::testDraftRevisionDownloadDoesntOverwriteDraftNonDefaultRevision()
  2. 3.8.x tests/src/Functional/LingotekContentModerationTest.php \Drupal\Tests\lingotek\Functional\LingotekContentModerationTest::testDraftRevisionDownloadDoesntOverwriteDraftNonDefaultRevision()

File

tests/src/Functional/LingotekContentModerationTest.php, line 602

Class

LingotekContentModerationTest
Tests setting up the integration with content moderation.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testDraftRevisionDownloadDoesntOverwriteDraftNonDefaultRevision() {

  // This is a hack for avoiding writing different lingotek endpoint mocks.
  \Drupal::state()
    ->set('lingotek.uploaded_content_type', 'nodeedited+revision');
  $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, 'article');
  $this
    ->assertText('Article Llamas are cool has been created.');

  // Edit the original as a new draft.
  $edit = [];
  $edit['title[0][value]'] = 'Dogs are cool';
  $edit['body[0][value]'] = 'Dogs are very cool';
  $this
    ->editAsNewDraftNodeForm('/node/1/edit', $edit);
  $this
    ->assertNoText('Dogs are cool was updated and sent to Lingotek successfully.');
  $this
    ->assertText('Article Dogs are cool has been updated.');
  $this
    ->goToContentBulkManagementForm();

  // Upload.
  $this
    ->clickLink('EN');
  $this
    ->assertText('Node Llamas are cool has been uploaded.');

  // Request translation.
  $this
    ->clickLink('ES');
  $this
    ->assertText('Locale \'es_MX\' was added as a translation target for node Llamas are cool.');

  // Check translation.
  $this
    ->clickLink('ES');
  $this
    ->assertText('The es_MX translation for node Llamas are cool is ready for download.');

  // The source published revision is the default one.
  $this
    ->drupalGet('node/1');
  $this
    ->assertText('Llamas are cool');
  $this
    ->goToContentBulkManagementForm();

  // Download translation.
  $edit = [
    'table[1]' => TRUE,
    'operation' => 'download:es',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertText('Operations completed.');

  // The source published revision must be the same still.
  $this
    ->drupalGet('node/1');
  $this
    ->assertText('Llamas are cool');

  // But the latest revision should keep the unpublished revision content.
  $this
    ->drupalGet('node/1/latest');
  $this
    ->assertText('Dogs are cool');

  // The translated revision is not published, so the source published
  // revision is displayed.
  $this
    ->drupalGet('es/node/1');
  $this
    ->assertText('Llamas are cool');

  // And it's also the latest published revision.
  $this
    ->drupalGet('es/node/1/latest');
  $this
    ->assertText('Los perros son chulos');
}