You are here

public function LingotekGetSourceDataTest::testContentEntityMetadataIsIncluded in Lingotek Translation 8

File

src/Tests/LingotekGetSourceDataTest.php, line 97

Class

LingotekGetSourceDataTest
Tests the Lingotek content service extract data from entities correctly.

Namespace

Drupal\lingotek\Tests

Code

public function testContentEntityMetadataIsIncluded() {

  // Create a node.
  $node = $this
    ->createNode([
    'type' => 'article',
  ]);

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');
  $serialized_node = $translation_service
    ->getSourceData($node);
  $this
    ->assertTrue(isset($serialized_node['_lingotek_metadata']), 'The Lingotek metadata is included in the extracted data.');
  $this
    ->assertEqual('node', $serialized_node['_lingotek_metadata']['_entity_type_id'], 'Entity type id is included as metadata.');
  $this
    ->assertEqual(1, $serialized_node['_lingotek_metadata']['_entity_id'], 'Entity id is included as metadata.');
  $this
    ->assertEqual(1, $serialized_node['_lingotek_metadata']['_entity_revision'], 'Entity revision id is included as metadata.');
  $node
    ->setNewRevision();
  $node
    ->setTitle($this
    ->randomString(10));
  $node
    ->save();
  $serialized_node = $translation_service
    ->getSourceData($node);
  $this
    ->assertTrue(isset($serialized_node['_lingotek_metadata']), 'The Lingotek metadata is included in the extracted data.');
  $this
    ->assertEqual('node', $serialized_node['_lingotek_metadata']['_entity_type_id'], 'Entity type id is included as metadata.');
  $this
    ->assertEqual(1, $serialized_node['_lingotek_metadata']['_entity_id'], 'Entity id is included as metadata.');
  $this
    ->assertEqual(2, $serialized_node['_lingotek_metadata']['_entity_revision'], 'Entity revision id is included as metadata, and has changed.');
}