You are here

public function LingotekNodeBulkFormTest::testLabelFilter 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::testLabelFilter()
  2. 4.0.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  3. 3.0.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  4. 3.1.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  5. 3.2.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  6. 3.3.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  7. 3.4.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  8. 3.5.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  9. 3.7.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()
  10. 3.8.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testLabelFilter()

Tests that the bulk management label filtering works correctly.

File

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

Class

LingotekNodeBulkFormTest
Tests the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional\Form

Code

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

  // Create a node.
  for ($i = 1; $i < 15; $i++) {
    $animal = 'Llamas';
    if ($i % 2 == 0) {
      $animal = 'Dogs';
    }
    elseif ($i % 3 == 0) {
      $animal = 'Cats';
    }
    $edit = [];
    $edit['title[0][value]'] = $animal . ' are cool ' . $i;
    $edit['body[0][value]'] = $animal . ' are very cool ' . $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 label 'Llamas', there is no pager and the rows
  // selected are the ones expected.
  $edit = [
    'filters[wrapper][label]' => 'Llamas',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
  foreach ([
    1,
    5,
    7,
    11,
    13,
  ] as $j) {
    $assert_session
      ->linkExists('Llamas are cool ' . $j);
  }
  $assert_session
    ->linkByHrefNotExists('?page=1');
  $assert_session
    ->linkNotExists('Dogs are cool 2');
  $this
    ->assertFieldByName('filters[wrapper][label]', 'Llamas', 'The value is retained in the filter.');

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

  // After we filter by label 'Cats', there is no pager and the rows selected
  // are the ones expected.
  $edit = [
    'filters[wrapper][label]' => 'Cats',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
  foreach ([
    3,
    9,
  ] as $j) {
    $assert_session
      ->linkExists('Cats are cool ' . $j);
  }
  $assert_session
    ->linkByHrefNotExists('?page=1');
  $assert_session
    ->linkNotExists('Dogs are cool 5');
  $this
    ->assertFieldByName('filters[wrapper][label]', 'Cats', 'The value is retained in the filter.');

  // After we reset, we get back to having a pager and all the content under
  // limit of 10.
  $this
    ->drupalPostForm(NULL, [], 'Reset');
  foreach ([
    1,
    5,
    7,
  ] as $j) {
    $assert_session
      ->linkExists('Llamas are cool ' . $j);
  }
  foreach ([
    2,
    4,
    6,
    8,
    10,
  ] as $j) {
    $assert_session
      ->linkExists('Dogs are cool ' . $j);
  }
  foreach ([
    3,
    9,
  ] as $j) {
    $assert_session
      ->linkExists('Cats are cool ' . $j);
  }
  $assert_session
    ->linkByHrefExists('?page=1');

  // If we filter with extra spaces, we still show content.
  $edit = [
    'filters[wrapper][label]' => '  Cats   ',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
  foreach ([
    3,
    9,
  ] as $j) {
    $assert_session
      ->linkExists('Cats are cool ' . $j);
  }
  $this
    ->assertFieldByName('filters[wrapper][label]', 'Cats', 'The value is trimmed in the filter.');
}