function CToolsWizardTest::testStepValidateAndSubmit

Same name in other branches
  1. 8.x-3.x tests/src/Functional/CToolsWizardTest.php \Drupal\Tests\ctools\Functional\CToolsWizardTest::testStepValidateAndSubmit()

Test wizard validate and submit.

File

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

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, $this->t('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, $this->t('Next'));
    // Redirected to the second step.
    $this->assertSession()
        ->pageTextContains('Form Two');
    $edit = [
        'two' => 'Second test',
    ];
    $this->submitForm($edit, $this->t('Finish'));
    // Check that the magic value triggered our submit callback.
    $this->assertSession()
        ->pageTextContains('Value One: Abraham');
    $this->assertSession()
        ->pageTextContains('Value Two: Second test');
}