You are here

function ProcessingTest::testBatchFormMultipleBatches in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Batch/ProcessingTest.php \Drupal\system\Tests\Batch\ProcessingTest::testBatchFormMultipleBatches()

Tests batches defined in different submit handlers on the same form.

File

core/modules/system/src/Tests/Batch/ProcessingTest.php, line 120
Contains \Drupal\system\Tests\Batch\ProcessingTest.

Class

ProcessingTest
Tests batch processing in form and non-form workflow.

Namespace

Drupal\system\Tests\Batch

Code

function testBatchFormMultipleBatches() {

  // Batches 1, 2 and 3 are triggered in sequence by different submit
  // handlers. Each submit handler modify the submitted 'value'.
  $value = rand(0, 255);
  $edit = array(
    'value' => $value,
  );
  $this
    ->drupalPostForm('batch-test/chained', $edit, 'Submit');

  // Check that result messages are present and in the correct order.
  $this
    ->assertBatchMessages($this
    ->_resultMessages('chained'), 'Batches defined in separate submit handlers performed successfully.');

  // The stack contains execution order of batch callbacks and submit
  // handlers and logging of corresponding $form_state->getValues().
  $this
    ->assertEqual(batch_test_stack(), $this
    ->_resultStack('chained', $value), 'Execution order was correct, and $form_state is correctly persisted.');
  $this
    ->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
}