function CToolsWizardTest::testStepValidateAndSubmit

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/CToolsWizardTest.php \Drupal\Tests\ctools\Functional\CToolsWizardTest::testStepValidateAndSubmit()

Test wizard validate and submit.

File

tests/src/Functional/CToolsWizardTest.php, line 61

Class

CToolsWizardTest
Tests basic wizard functionality.

Namespace

Drupal\Tests\ctools\Functional

Code

public function testStepValidateAndSubmit() {
    $this->drupalGet('ctools/wizard');
    $this->assertSession()
        ->pageTextContains('Form One');
    // Submit first step in the wizard.
    $edit = [
        'one' => 'wrong',
    ];
    $this->drupalGet('ctools/wizard');
    $this->submitForm($edit, 'Next');
    // We're still on the first form and the error is present.
    $this->assertSession()
        ->pageTextContains('Form One');
    $this->assertSession()
        ->pageTextContains('Cannot set the value to "wrong".');
    // Try again with the magic value.
    $edit = [
        'one' => 'magic',
    ];
    $this->drupalGet('ctools/wizard');
    $this->submitForm($edit, 'Next');
    // Redirected to the second step.
    $this->assertSession()
        ->pageTextContains('Form Two');
    $edit = [
        'two' => 'Second test',
    ];
    $this->submitForm($edit, 'Finish');
    // Check that the magic value triggered our submit callback.
    $this->assertSession()
        ->pageTextContains('Value One: Abraham');
    $this->assertSession()
        ->pageTextContains('Value Two: Second test');
}