function ProcessingTest::testBatchFormMultistep

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Batch/ProcessingTest.php \Drupal\Tests\system\Functional\Batch\ProcessingTest::testBatchFormMultistep()
  2. 8.9.x core/modules/system/tests/src/Functional/Batch/ProcessingTest.php \Drupal\Tests\system\Functional\Batch\ProcessingTest::testBatchFormMultistep()
  3. 10 core/modules/system/tests/src/Functional/Batch/ProcessingTest.php \Drupal\Tests\system\Functional\Batch\ProcessingTest::testBatchFormMultistep()

Tests batches defined in a multistep form.

File

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

Class

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

Namespace

Drupal\Tests\system\Functional\Batch

Code

public function testBatchFormMultistep() : void {
    $this->drupalGet('batch-test/multistep');
    $this->assertSession()
        ->assertNoEscaped('<');
    $this->assertSession()
        ->pageTextContains('step 1');
    // First step triggers batch 1.
    $this->submitForm([], 'Submit');
    $this->assertBatchMessages($this->_resultMessages('batch_1'));
    $this->assertEquals($this->_resultStack('batch_1'), batch_test_stack(), 'Execution order was correct.');
    $this->assertSession()
        ->pageTextContains('step 2');
    $this->assertSession()
        ->assertNoEscaped('<');
    // Second step triggers batch 2.
    $this->submitForm([], 'Submit');
    $this->assertBatchMessages($this->_resultMessages('batch_2'));
    $this->assertEquals($this->_resultStack('batch_2'), batch_test_stack(), 'Execution order was correct.');
    $this->assertSession()
        ->pageTextContains('Redirection successful.');
    $this->assertSession()
        ->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->submitForm([], 'Submit');
    $this->assertSession()
        ->pageTextContains('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.