You are here

public function LingotekSaveTargetDataTest::testRightRevisionsAreSavedIfThereIsMetadata in Lingotek Translation 3.7.x

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

File

tests/src/Functional/LingotekSaveTargetDataTest.php, line 95

Class

LingotekSaveTargetDataTest
Tests the Lingotek content service saves data to entities correctly.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testRightRevisionsAreSavedIfThereIsMetadata() {

  // Create a node.

  /** @var \Drupal\node\NodeInterface $node */
  $node = $this
    ->createNode([
    'type' => 'article',
    'title' => 'Revision 1',
  ]);

  // Create a new revision.
  $node
    ->setTitle('Revision 2');
  $node
    ->setNewRevision();
  $node
    ->save();

  // Create a third one.
  $node
    ->setTitle('Revision 3');
  $node
    ->setNewRevision();
  $node
    ->save();

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');
  $es_data = [
    'title' => [
      0 => [
        'value' => 'Revision 2 ES',
      ],
    ],
    'body' => [
      0 => [
        'value' => 'es body',
      ],
    ],
    '_lingotek_metadata' => [
      '_entity_type_id' => 'node',
      '_entity_id' => 1,
      '_entity_revision' => 2,
    ],
  ];
  $translation_service
    ->saveTargetData($node, 'es', $es_data);
  $node = \Drupal::entityTypeManager()
    ->getStorage('node')
    ->load(1);
  $node = $node
    ->getTranslation('es');
  $this
    ->assertEqual('es body', $node->body->value, 'The body is translated correctly.');
  $this
    ->assertEqual('Revision 2 ES', $node
    ->getTitle(), 'The title in the revision translation is the one given.');
  $this
    ->assertEqual(3, $node
    ->getRevisionId(), 'The translation is saved in the newest revision.');
}