You are here

public function ContentEntitySourceUnitTest::testAcceptTranslation in Translation Management Tool 8

Test node acceptTranslation.

File

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

Class

ContentEntitySourceUnitTest
Content entity Source unit tests.

Namespace

Drupal\Tests\tmgmt_content\Kernel

Code

public function testAcceptTranslation() {
  $account = $this
    ->createUser();
  $type = $this
    ->drupalCreateContentType();
  $this->container
    ->get('content_translation.manager')
    ->setEnabled('node', $type
    ->id(), TRUE);

  /** @var Translator $translator */
  $translator = Translator::load('test_translator');
  $translator
    ->setAutoAccept(TRUE)
    ->save();
  $node = Node::create([
    'title' => $this
      ->randomMachineName(),
    'uid' => $account
      ->id(),
    'type' => $type
      ->id(),
    'langcode' => 'en',
  ]);
  $node
    ->save();
  $job = tmgmt_job_create('en', 'de');
  $job->translator = 'test_translator';
  $job
    ->save();
  $job_item = tmgmt_job_item_create('content', $node
    ->getEntityTypeId(), $node
    ->id(), array(
    'tjid' => $job
      ->id(),
  ));
  $job_item
    ->save();

  // Request translation. Here it fails.
  $job
    ->requestTranslation();
  $items = $job
    ->getItems();

  /** @var \Drupal\tmgmt\Entity\JobItem $item */
  $item = reset($items);

  // As was set to auto_accept, should be accepted.
  $this
    ->assertEqual($item
    ->getState(), JobItemInterface::STATE_ACCEPTED);

  // Test that the source language is set correctly.
  $node = Node::load($node
    ->id());
  $manager = $this->container
    ->get('content_translation.manager');
  $this
    ->assertEquals('en', $manager
    ->getTranslationMetadata($node
    ->getTranslation('de'))
    ->getSource(), 'Source language is correct.');
}