function ProcessingTest::testBatchFormMultistep

Tests batches defined in a multistep form.

File

core/modules/system/tests/src/Functional/Batch/ProcessingTest.php, line 125

Class

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

Namespace

Drupal\Tests\system\Functional\Batch

Code

public function testBatchFormMultistep() {
  $this->drupalGet('batch-test/multistep');
  $this->assertNoEscaped('<');
  $this->assertText('step 1', 'Form is displayed in step 1.');
  // First step triggers batch 1.
  $this->drupalPostForm(NULL, [], 'Submit');
  $this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch for step 1 performed successfully.');
  $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.');
  $this->assertText('step 2', 'Form is displayed in step 2.');
  $this->assertNoEscaped('<');
  // Second step triggers batch 2.
  $this->drupalPostForm(NULL, [], 'Submit');
  $this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch for step 2 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.');
  $this->assertNoEscaped('<');
  // Extra query arguments will trigger logic that will add them to the
  // redirect URL. Make sure they are persisted.
  $this->drupalGet('batch-test/multistep', [
    'query' => [
      'big_tree' => 'small_axe',
    ],
  ]);
  $this->drupalPostForm(NULL, [], 'Submit');
  $this->assertText('step 2', 'Form is displayed in step 2.');
  $this->assertStringContainsString('batch-test/multistep?big_tree=small_axe', $this->getUrl(), 'Query argument was persisted and another extra argument was added.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.