You are here

public function ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsAjaxUi in Views Bulk Operations (VBO) 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/FunctionalJavascript/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\FunctionalJavaScript\ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsAjaxUi()

Tests the VBO bulk form without dynamic insertion.

File

tests/src/FunctionalJavascript/ViewsBulkOperationsBulkFormTest.php, line 119

Class

ViewsBulkOperationsBulkFormTest
@coversDefaultClass \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm @group views_bulk_operations

Namespace

Drupal\Tests\views_bulk_operations\FunctionalJavaScript

Code

public function testViewsBulkOperationsAjaxUi() {

  // Make sure a checkbox appears on all rows and the button exists.
  $this->assertSession
    ->buttonExists('Simple test action');
  for ($i = 0; $i < $this->testViewParams['items_per_page']; $i++) {
    $this->assertSession
      ->fieldExists('edit-views-bulk-operations-bulk-form-' . $i);
  }

  // Select some items on the first page.
  foreach ([
    0,
    1,
    3,
  ] as $selected_index) {
    $this->selectedIndexes[] = $selected_index;
    $this->page
      ->checkField('views_bulk_operations_bulk_form[' . $selected_index . ']');
  }

  // Go to the next page and select some more.
  $this->page
    ->clickLink('Go to next page');
  $this->assertSession
    ->assertWaitOnAjaxRequest();
  foreach ([
    1,
    2,
  ] as $selected_index) {

    // This is page one so indexes are incremented by page count and
    // checkbox selectors start from 0 again.
    $this->selectedIndexes[] = $selected_index + $this->testViewParams['items_per_page'];
    $this->page
      ->checkField('views_bulk_operations_bulk_form[' . $selected_index . ']');
  }

  // Execute test operation.
  $this->page
    ->pressButton('Simple test action');

  // Assert if only the selected nodes were processed.
  foreach ($this->testNodes as $delta => $node) {
    if (in_array($delta, $this->selectedIndexes, TRUE)) {
      $this->assertSession
        ->pageTextContains(sprintf('Test action (preconfig: Test setting, label: %s)', $node
        ->label()));
    }
    else {
      $this->assertSession
        ->pageTextNotContains(sprintf('Test action (preconfig: Test setting, label: %s)', $node
        ->label()));
    }
  }
  $this->assertSession
    ->pageTextContains(sprintf('Action processing results: Test (%s)', count($this->selectedIndexes)));
}