You are here

public function LingotekSaveTargetDataTest::testRightRevisionsAreSavedIfThereIsMetadata in Lingotek Translation 8

File

src/Tests/LingotekSaveTargetDataTest.php, line 68

Class

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

Namespace

Drupal\lingotek\Tests

Code

public function testRightRevisionsAreSavedIfThereIsMetadata() {

  // Create a node.

  /** @var 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::entityManager()
    ->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.');
}