You are here

public function LingotekNodeParagraphsTranslationTest::testContentEntityMetadataIsIncluded in Lingotek Translation 8

Tests that the metadata of the node and the embedded paragraphs is included.

File

src/Tests/LingotekNodeParagraphsTranslationTest.php, line 159

Class

LingotekNodeParagraphsTranslationTest
Tests translating a node with multiple locales including paragraphs.

Namespace

Drupal\lingotek\Tests

Code

public function testContentEntityMetadataIsIncluded() {

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

  // Add paragraphed content.
  $this
    ->drupalGet('node/add/paragraphed_content_demo');
  $this
    ->drupalPostForm(NULL, NULL, t('Add Image + Text'));
  $this
    ->drupalPostForm(NULL, NULL, t('Add Image + Text'));
  $edit = array();
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['field_paragraphs_demo[0][subform][field_text_demo][0][value]'] = 'Llamas are very cool for the first time';
  $edit['field_paragraphs_demo[1][subform][field_text_demo][0][value]'] = 'Llamas are very cool for the second time';
  $this
    ->drupalPostForm(NULL, $edit, t('Save and publish'));
  $this->node = Node::load(1);

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');
  $serialized_node = $translation_service
    ->getSourceData($this->node);
  $this
    ->verbose(var_export($serialized_node, TRUE));

  // Main node metadata is there.
  $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.');

  // And paragraphs metadata is there too.
  $this
    ->assertTrue(isset($serialized_node['field_paragraphs_demo'][0]['_lingotek_metadata']), 'The Lingotek metadata is included in the first paragraph.');
  $this
    ->assertEqual('paragraph', $serialized_node['field_paragraphs_demo'][0]['_lingotek_metadata']['_entity_type_id'], 'Entity type id is included as metadata in the first paragraph.');
  $this
    ->assertEqual(1, $serialized_node['field_paragraphs_demo'][0]['_lingotek_metadata']['_entity_id'], 'Entity id is included as metadata in the first paragraph.');
  $this
    ->assertEqual(1, $serialized_node['field_paragraphs_demo'][0]['_lingotek_metadata']['_entity_revision'], 'Entity revision id is included as metadata in the first paragraph.');
  $this
    ->assertTrue(isset($serialized_node['field_paragraphs_demo'][1]['_lingotek_metadata']), 'The Lingotek metadata is included in the second paragraph.');
  $this
    ->assertEqual('paragraph', $serialized_node['field_paragraphs_demo'][1]['_lingotek_metadata']['_entity_type_id'], 'Entity type id is included as metadata in the second paragraph.');
  $this
    ->assertEqual(2, $serialized_node['field_paragraphs_demo'][1]['_lingotek_metadata']['_entity_id'], 'Entity id is included as metadata in the second paragraph.');
  $this
    ->assertEqual(2, $serialized_node['field_paragraphs_demo'][1]['_lingotek_metadata']['_entity_revision'], 'Entity revision id is included as metadata in the second paragraph.');
}