You are here

public function CheckStatusTest::testCheckStatus in TMGMT Extension Suite 8.2

Test tmgmt_extension_suit_add_to_check_status() function.

In this test we don't run cron because it will immediately process newly added queue items and we will not be able to check if added items was correct. So we're calling a function that is called by hook_cron.

File

tests/src/Functional/CheckStatusTest.php, line 19

Class

CheckStatusTest
Class CheckStatusTest

Namespace

Drupal\Tests\tmgmt_extension_suit\Functional

Code

public function testCheckStatus() {
  $this
    ->addLanguage('es');

  // Allow user to translate from en to es.
  $edit = [
    'tmgmt_translation_skills[0][language_from]' => 'en',
    'tmgmt_translation_skills[0][language_to]' => 'es',
  ];
  $this
    ->drupalPostForm('user/' . $this
    ->getUserForTranslations()
    ->id() . '/edit', $edit, t('Save'));

  // One job - one job item.
  $this
    ->requestTranslation([
    1,
  ], 'fr', 1);

  // Job 1. Job item 1.
  $this
    ->requestTranslation([
    1,
  ], 'de', 2);

  // Job 2. Job item 2.
  // One job - many job items.
  $this
    ->requestTranslation([
    2,
    3,
  ], 'fr', 3);

  // Job 3. Job item 3, 4.
  $this
    ->requestTranslation([
    2,
    3,
  ], 'de', 4);

  // Job 4. Job item 5, 6.
  $this
    ->requestTranslation([
    2,
    3,
  ], 'es', 5);

  // Job 5. Job item 7, 8.
  // Let's mark job items as 'needs review'.
  $this
    ->translateJobItems([
    2,
    5,
    7,
    8,
  ]);

  // So now we have next jobs with job items:
  // job (state) - job item/s (state).
  // 1 (active) - 1 (active).
  // 2 (active) - 2 (review).
  // 3 (active) - 3 (active), 4 (active).
  // 4 (active) - 5 (review), 6 (active).
  // 5 (active) - 7 (review), 8 (review).
  // Expectation - in check status queue will be next jobs: 1, 3, 4
  tmgmt_extension_suit_add_to_check_status();
  $this
    ->assertEqual($this
    ->getCountOfItemsInQueue('tmgmt_extension_suit_check_status'), 3);
  $this
    ->assertEqual($this
    ->isItemAddedToQueue('tmgmt_extension_suit_check_status', 1), 1);
  $this
    ->assertEqual($this
    ->isItemAddedToQueue('tmgmt_extension_suit_check_status', 2), 0);
  $this
    ->assertEqual($this
    ->isItemAddedToQueue('tmgmt_extension_suit_check_status', 3), 1);
  $this
    ->assertEqual($this
    ->isItemAddedToQueue('tmgmt_extension_suit_check_status', 4), 1);
  $this
    ->assertEqual($this
    ->isItemAddedToQueue('tmgmt_extension_suit_check_status', 5), 0);
}