function ProcessingTest::testBatchForm

Tests batches defined in a form submit handler.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Batch/ProcessingTest.php, line 46
Definition of Drupal\system\Tests\Batch\ProcessingTest.

Class

ProcessingTest
Tests the Batch API.

Namespace

Drupal\system\Tests\Batch

Code

function testBatchForm() {

  // Batch 0: no operation.
  $edit = array(
    'batch' => 'batch_0',
  );
  $this
    ->drupalPost('batch-test/simple', $edit, 'Submit');
  $this
    ->assertBatchMessages($this
    ->_resultMessages('batch_0'), 'Batch with no operation performed successfully.');
  $this
    ->assertText('Redirection successful.', 'Redirection after batch execution is correct.');

  // Batch 1: several simple operations.
  $edit = array(
    'batch' => 'batch_1',
  );
  $this
    ->drupalPost('batch-test/simple', $edit, 'Submit');
  $this
    ->assertBatchMessages($this
    ->_resultMessages('batch_1'), 'Batch with simple operations performed successfully.');
  $this
    ->assertEqual(batch_test_stack(), $this
    ->_resultStack('batch_1'), 'Execution order was correct.');
  $this
    ->assertText('Redirection successful.', 'Redirection after batch execution is correct.');

  // Batch 2: one multistep operation.
  $edit = array(
    'batch' => 'batch_2',
  );
  $this
    ->drupalPost('batch-test/simple', $edit, 'Submit');
  $this
    ->assertBatchMessages($this
    ->_resultMessages('batch_2'), 'Batch with multistep operation performed successfully.');
  $this
    ->assertEqual(batch_test_stack(), $this
    ->_resultStack('batch_2'), 'Execution order was correct.');
  $this
    ->assertText('Redirection successful.', 'Redirection after batch execution is correct.');

  // Batch 3: simple + multistep combined.
  $edit = array(
    'batch' => 'batch_3',
  );
  $this
    ->drupalPost('batch-test/simple', $edit, 'Submit');
  $this
    ->assertBatchMessages($this
    ->_resultMessages('batch_3'), 'Batch with simple and multistep operations performed successfully.');
  $this
    ->assertEqual(batch_test_stack(), $this
    ->_resultStack('batch_3'), 'Execution order was correct.');
  $this
    ->assertText('Redirection successful.', 'Redirection after batch execution is correct.');

  // Batch 4: nested batch.
  $edit = array(
    'batch' => 'batch_4',
  );
  $this
    ->drupalPost('batch-test/simple', $edit, 'Submit');
  $this
    ->assertBatchMessages($this
    ->_resultMessages('batch_4'), 'Nested batch performed successfully.');
  $this
    ->assertEqual(batch_test_stack(), $this
    ->_resultStack('batch_4'), 'Execution order was correct.');
  $this
    ->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
}