You are here

public function LingotekNodeBulkFormTest::testJobIdFilter in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  2. 4.0.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  3. 3.0.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  4. 3.1.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  5. 3.2.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  6. 3.3.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  7. 3.4.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  8. 3.5.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  9. 3.7.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()
  10. 3.8.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testJobIdFilter()

Tests that the bulk management job filter works correctly.

File

tests/src/Functional/Form/LingotekNodeBulkFormTest.php, line 211

Class

LingotekNodeBulkFormTest
Tests the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional\Form

Code

public function testJobIdFilter() {
  $assert_session = $this
    ->assertSession();
  $nodes = [];

  // See https://www.drupal.org/project/drupal/issues/2925290.
  $indexes = "ABCDEFGHIJKLMNOPQ";

  // Create some nodes.
  for ($i = 1; $i < 15; $i++) {
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool ' . $indexes[$i];
    $edit['body[0][value]'] = 'Llamas are very cool ' . $indexes[$i];
    $edit['langcode[0][value]'] = 'en';
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $nodes[$i] = $edit;
  }
  $this
    ->goToContentBulkManagementForm();

  // Assert there is a pager.
  $assert_session
    ->linkByHrefExists('?page=1');

  // After we filter by an unexisting job, there is no content and no rows.
  $edit = [
    'filters[wrapper][job]' => 'this job does not exist',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
  $assert_session
    ->linkNotExists('Llamas are cool');
  $assert_session
    ->linkByHrefNotExists('?page=1');

  // After we reset, we get back to having a pager and all the content.
  $this
    ->drupalPostForm(NULL, [], 'Reset');
  foreach (range(1, 10) as $j) {
    $assert_session
      ->linkExists('Llamas are cool ' . $indexes[$j]);
  }
  $assert_session
    ->linkByHrefExists('?page=1');

  // Show 50 results.
  \Drupal::service('tempstore.private')
    ->get('lingotek.management.items_per_page')
    ->set('limit', 50);
  $this
    ->goToContentBulkManagementForm();

  // I can init the upload of content.
  $this
    ->assertLingotekUploadLink(11, 'node');
  $edit = [
    'table[4]' => TRUE,
    'table[6]' => TRUE,
    'table[8]' => TRUE,
    'table[10]' => TRUE,
    'table[12]' => TRUE,
    'table[14]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('node'),
    'job_id' => 'even numbers',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $edit = [
    'table[1]' => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    'table[5]' => TRUE,
    'table[7]' => TRUE,
    'table[11]' => TRUE,
    'table[13]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('node'),
    'job_id' => 'prime numbers',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Show 10 results.
  \Drupal::service('tempstore.private')
    ->get('lingotek.management.items_per_page')
    ->set('limit', 10);
  $this
    ->goToContentBulkManagementForm();

  // After we filter by prime, there is no pager and the rows
  // selected are the ones expected.
  $edit = [
    'filters[wrapper][job]' => 'prime',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
  foreach ([
    1,
    2,
    3,
    5,
    7,
    11,
    13,
  ] as $j) {
    $assert_session
      ->linkExists('Llamas are cool ' . $indexes[$j]);
  }
  $assert_session
    ->linkNotExists('Page 2');
  $assert_session
    ->linkNotExists('Llamas are cool ' . $indexes[4]);
  $this
    ->assertFieldByName('filters[wrapper][job]', 'prime', 'The value is retained in the filter.');

  // After we filter by even, there is no pager and the rows selected are the
  // ones expected.
  $edit = [
    'filters[wrapper][job]' => 'even',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
  foreach ([
    4,
    6,
    8,
    10,
    12,
    14,
  ] as $j) {
    $assert_session
      ->linkExists('Llamas are cool ' . $indexes[$j]);
  }
  $assert_session
    ->linkByHrefNotExists('?page=1');
  $assert_session
    ->linkNotExists('Llamas are cool ' . $indexes[5]);
  $this
    ->assertFieldByName('filters[wrapper][job]', 'even', 'The value is retained in the filter.');

  // After we reset, we get back to having a pager and all the content.
  $this
    ->drupalPostForm(NULL, [], 'Reset');
  foreach (range(1, 10) as $j) {
    $assert_session
      ->linkExists('Llamas are cool ' . $indexes[$j]);
  }
  $assert_session
    ->linkByHrefExists('?page=1');
}