You are here

public function ContentEntitySourceUnitTest::testRequestDataForSpecificLanguage in Translation Management Tool 8

Test if the source is able to pull content in requested language.

File

sources/content/tests/src/Kernel/ContentEntitySourceUnitTest.php, line 448

Class

ContentEntitySourceUnitTest
Content entity Source unit tests.

Namespace

Drupal\Tests\tmgmt_content\Kernel

Code

public function testRequestDataForSpecificLanguage() {

  // Create an english node.
  $account = $this
    ->createUser();
  $type = $this
    ->drupalCreateContentType();
  $field = FieldStorageConfig::loadByName('node', 'body');
  $field
    ->setTranslatable(TRUE);
  $field
    ->setCardinality(2);
  $field
    ->save();
  $node = Node::create(array(
    'title' => $this
      ->randomMachineName(),
    'uid' => $account
      ->id(),
    'type' => $type
      ->id(),
    'langcode' => 'cs',
  ));
  $node = $node
    ->addTranslation('en');
  $node
    ->get('title')
    ->appendItem(array(
    'value' => $this
      ->randomMachineName(),
  ));
  $value = array(
    'value' => $this
      ->randomMachineName(),
    'summary' => $this
      ->randomMachineName(),
    'format' => 'text_plain',
  );
  $node
    ->get('body')
    ->appendItem($value);
  $node
    ->get('body')
    ->appendItem($value);
  $node
    ->save();
  $job = tmgmt_job_create('en', 'de');
  $job
    ->save();
  $job_item = tmgmt_job_item_create('content', 'node', $node
    ->id(), array(
    'tjid' => $job
      ->id(),
  ));
  $job_item
    ->save();
  $source_plugin = $this->container
    ->get('plugin.manager.tmgmt.source')
    ->createInstance('content');
  $data = $source_plugin
    ->getData($job_item);
  $this
    ->assertEqual($data['body'][0]['value']['#text'], $value['value']);
}