You are here

function RequestBulkTranslationTest::testRequestBulkTranslation in TMGMT Extension Suite 8

Test request bulk translation.

File

src/Tests/RequestBulkTranslationTest.php, line 117

Class

RequestBulkTranslationTest
Class RequestBulkTranslationTest

Namespace

Drupal\tmgmt_extension_suit\Tests

Code

function testRequestBulkTranslation() {
  $this
    ->requestBulkTranslation([
    2,
    3,
  ], [
    'fr',
    'de',
  ], 'local', [
    'settings[translator]' => 1,
    'settings[job_comment]' => 'Comment',
  ]);
  $this
    ->assertText('Translation request queued for 4 jobs. Return to "Sources" page.');

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

  // 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');

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

  // Check job settings.
  $this
    ->assertEqual($jobs[1]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => 1,
      'job_comment' => 'Comment',
    ],
  ]);
  $this
    ->assertEqual($jobs[2]
    ->get('settings')
    ->getValue(), [
    [
      'translator' => 1,
      'job_comment' => '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',
    ],
  ]);
}