You are here

public function RequestBulkTranslationTest::testRequestBulkTranslationSkippingNodeInTwoLanguages in TMGMT Extension Suite 8

Test request bulk translation with conflicting items.

File

src/Tests/RequestBulkTranslationTest.php, line 230

Class

RequestBulkTranslationTest
Class RequestBulkTranslationTest

Namespace

Drupal\tmgmt_extension_suit\Tests

Code

public function testRequestBulkTranslationSkippingNodeInTwoLanguages() {

  // Let's get a conflicting job items.
  $this
    ->requestTranslation([
    1,
  ], 'fr', 1);
  $this
    ->requestTranslation([
    1,
  ], 'de', 2);

  // Request bulk translation including conflicting job items.
  $this
    ->requestBulkTranslation([
    1,
    2,
    3,
  ], [
    'fr',
    'de',
  ], 'local', [
    'settings[translator]' => 1,
    'settings[job_comment]' => 'Comment',
  ]);
  $this
    ->assertText('2 items conflicted with pending items and were skipped. Existing job items:');
  $this
    ->assertText('Job item with source language = "en" and target language = "fr" for entity "node" with id = "1".');
  $this
    ->assertText('Job item with source language = "en" and target language = "de" for entity "node" with id = "1".');
  $this
    ->assertText('Translation request queued for 4 jobs. Return to "Sources" page.');

  // In upload queue should be 4 jobs: 2 nodes in fr and de.
  $this
    ->assertEqual($this
    ->getCountOfItemsInQueue('tmgmt_extension_suit_upload'), 4);
  $jobs = Job::loadMultiple([
    1,
    2,
    3,
    4,
    5,
    6,
  ]);

  // Check source language.
  $this
    ->assertEqual($jobs[1]
    ->getSourceLangcode(), 'en');
  $this
    ->assertEqual($jobs[2]
    ->getSourceLangcode(), 'en');
  $this
    ->assertEqual($jobs[3]
    ->getSourceLangcode(), 'en');
  $this
    ->assertEqual($jobs[4]
    ->getSourceLangcode(), 'en');
  $this
    ->assertEqual($jobs[5]
    ->getSourceLangcode(), 'en');
  $this
    ->assertEqual($jobs[6]
    ->getSourceLangcode(), 'en');

  // Check target language.
  $this
    ->assertEqual($jobs[1]
    ->getTargetLangcode(), 'fr');
  $this
    ->assertEqual($jobs[2]
    ->getTargetLangcode(), 'de');
  $this
    ->assertEqual($jobs[3]
    ->getTargetLangcode(), 'de');
  $this
    ->assertEqual($jobs[4]
    ->getTargetLangcode(), 'fr');
  $this
    ->assertEqual($jobs[5]
    ->getTargetLangcode(), 'de');
  $this
    ->assertEqual($jobs[6]
    ->getTargetLangcode(), 'fr');

  // Check job settings.
  $this
    ->assertEqual($jobs[1]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => '',
      'job_comment' => '',
    ],
  ]);
  $this
    ->assertEqual($jobs[2]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => '',
      'job_comment' => '',
    ],
  ]);
  $this
    ->assertEqual($jobs[3]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => 1,
      'job_comment' => 'Comment',
    ],
  ]);
  $this
    ->assertEqual($jobs[4]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => 1,
      'job_comment' => 'Comment',
    ],
  ]);
  $this
    ->assertEqual($jobs[5]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => 1,
      'job_comment' => 'Comment',
    ],
  ]);
  $this
    ->assertEqual($jobs[6]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => 1,
      'job_comment' => 'Comment',
    ],
  ]);
}