Namespace
Drupal\Tests\form_api_example\Functional
File
-
modules/form_api_example/tests/src/Functional/MultistepFormTest.php
View source
<?php
namespace Drupal\Tests\form_api_example\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class MultistepFormTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'form_api_example',
];
public function testWizardForm() {
$this->drupalGet(Url::fromRoute('form_api_example.multistep_form'));
$page = $this->getSession()
->getPage();
$h1 = $page->find('css', 'h1');
$this->assertStringContainsString('Multistep form', $h1->getText());
$desc = $page->find('css', '#edit-description label');
$this->assertStringContainsString('page 1', $desc->getText());
$this->submitForm([
'first_name' => 'Bozo',
'last_name' => 'Di Clown',
'birth_year' => 1980,
], 'Next');
$page2 = $this->getSession()
->getPage();
$desc = $page2->find('css', '#edit-description label');
$this->assertStringContainsString('page 2', $desc->getText());
$this->submitForm([], 'Back');
$page1 = $this->getSession()
->getPage();
$desc = $page1->find('css', '#edit-description label');
$this->assertStringContainsString('page 1', $desc->getText());
$first_name = $page1->findField('first_name')
->getValue();
$this->assertEquals('Bozo', $first_name);
$second_name = $page1->findField('last_name')
->getValue();
$this->assertEquals('Di Clown', $second_name);
$birth_year = $page1->findField('birth_year')
->getValue();
$this->assertEquals('1980', $birth_year);
$this->click('#edit-next');
$page2 = $this->getSession()
->getPage();
$desc = $page2->find('css', '#edit-description label');
$this->assertStringContainsString('page 2', $desc->getText());
$this->submitForm([
'color' => 'neon green',
], 'Submit');
$messages = $this->getSession()
->getPage()
->find('css', 'div[data-drupal-messages] ul');
$message_text = $messages->getHtml();
$this->assertStringContainsString('Bozo Di Clown', $message_text);
$this->assertStringContainsString('1980', $message_text);
$this->assertStringContainsString('neon green', $message_text);
}
}
Classes