You are here

public function JobsTest::testBucketJob in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/JobsTest.php \Drupal\Tests\tmgmt_smartling\Functional\JobsTest::testBucketJob()

Test bucket job.

File

tests/src/Functional/JobsTest.php, line 121

Class

JobsTest
Jobs tests.

Namespace

Drupal\Tests\tmgmt_smartling\Functional

Code

public function testBucketJob() {
  if (!empty($this->smartlingPluginProviderSettings)) {

    // 1. Send content in a job.
    $this
      ->drupalPostForm('/admin/tmgmt/sources', [
      'items[1]' => 1,
      'target_language' => '_all',
    ], t('Request translation'));
    $this
      ->drupalPostForm(NULL, [
      'target_language' => 'de',
      'settings[create_new_job_tab][name]' => 'Drupal TMGMT connector test ' . mt_rand(),
      'settings[create_new_job_tab][due_date][date]' => '2020-12-12',
      'settings[create_new_job_tab][due_date][time]' => '12:12',
      'settings[create_new_job_tab][authorize]' => TRUE,
      'settings[smartling_users_time_zone]' => 'Europe/Kiev',
    ], t('Submit to provider and continue'));

    // 2. Check that upload queue is empty.
    $this
      ->assertTrue($this
      ->getCountOfItemsInQueue('tmgmt_extension_suit_upload') == 0, 'Upload queue is empty.');

    // 3. Update a node - trigger entity changes handling.
    $node = Node::load(1);
    $node
      ->setTitle('Updated node title');
    $node
      ->save();

    // 4. Check upload entity queue.
    $this
      ->assertTrue($this
      ->getCountOfItemsInQueue('tmgmt_extension_suit_upload') == 2, 'Upload queue contains 2 items.');
    $data1 = $this
      ->fetchQueueItemsData('tmgmt_extension_suit_upload');
    $batch_uid_old_1 = $data1[0]['batch_uid'];
    $batch_uid_old_2 = $data1[1]['batch_uid'];
    $this
      ->assertEqual($batch_uid_old_1, $batch_uid_old_2, 'First two files will be uploaded into the same batch.');
    $this
      ->assertEqual($data1, [
      [
        'id' => 1,
        'batch_uid' => $batch_uid_old_1,
        'batch_execute_on_job' => 2,
      ],
      [
        'id' => 2,
        'batch_uid' => $batch_uid_old_1,
        'batch_execute_on_job' => 2,
      ],
    ], 'Queue items have valid data inside.');

    // 5. Update a node - trigger entity changes handling once again.
    $node = Node::load(1);
    $node
      ->setTitle('Updated node title once again');
    $node
      ->save();

    // 6. Check upload entity queue once again.
    $this
      ->assertTrue($this
      ->getCountOfItemsInQueue('tmgmt_extension_suit_upload') == 4, 'Upload queue contains 4 items.');
    $data2 = $this
      ->fetchQueueItemsData('tmgmt_extension_suit_upload');
    $batch_uid_new_1 = $data2[2]['batch_uid'];
    $batch_uid_new_2 = $data2[3]['batch_uid'];
    $this
      ->assertEqual($batch_uid_new_1, $batch_uid_new_2, 'Second two files will be uploaded into the same batch.');
    $this
      ->assertNotEqual($batch_uid_old_1, $batch_uid_new_1, 'First and second batches are different.');
    $this
      ->assertEqual($data2, [
      [
        'id' => 1,
        'batch_uid' => $batch_uid_old_1,
        'batch_execute_on_job' => 2,
      ],
      [
        'id' => 2,
        'batch_uid' => $batch_uid_old_1,
        'batch_execute_on_job' => 2,
      ],
      [
        'id' => 1,
        'batch_uid' => $batch_uid_new_1,
        'batch_execute_on_job' => 2,
      ],
      [
        'id' => 2,
        'batch_uid' => $batch_uid_new_1,
        'batch_execute_on_job' => 2,
      ],
    ], 'Queue items have valid data inside.');
  }
  else {
    $this
      ->fail("Smartling settings file for simpletests not found.");
  }
}