protected function ViewsBulkOperationsBulkFormTest::assertBatchProcess in Views Bulk Operations (VBO) 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\Functional\ViewsBulkOperationsBulkFormTest::assertBatchProcess()
Helper function to test a batch process.
After checking if we're on a Batch API page, the iterations are executed, the finished page is opened and browser redirects to the final destination.
NOTE: As of Drupal 8.4, functional test automatically redirects user through all Batch API pages, so this function is not longer needed.
File
- tests/src/ Functional/ ViewsBulkOperationsBulkFormTest.php, line 62 
Class
- ViewsBulkOperationsBulkFormTest
- @coversDefaultClass \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm @group views_bulk_operations
Namespace
Drupal\Tests\views_bulk_operations\FunctionalCode
protected function assertBatchProcess() {
  // Get the current batch ID.
  $current_url = $this
    ->getUrl();
  $q = substr($current_url, strrpos($current_url, '/') + 1);
  $this
    ->assertEquals('batch?', substr($q, 0, 6), 'We are on a Batch API page.');
  preg_match('#id=([0-9]+)#', $q, $matches);
  $batch_id = $matches[1];
  // Proceed with the operations.
  // Assumption: all operations will be completed within a single request.
  // TODO: modify code to include an option when the assumption is false.
  do {
    $this
      ->drupalGet('batch', [
      'query' => [
        'id' => $batch_id,
        'op' => 'do_nojs',
      ],
    ]);
  } while (FALSE);
  // Get the finished page.
  $this
    ->drupalGet('batch', [
    'query' => [
      'id' => $batch_id,
      'op' => 'finished',
    ],
  ]);
}