Namespace
Drupal\Tests\ctools\Functional
File
-
tests/src/Functional/CToolsWizardTest.php
View source
<?php
namespace Drupal\Tests\ctools\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class CToolsWizardTest extends BrowserTestBase {
use StringTranslationTrait;
protected static $modules = [
'ctools',
'ctools_wizard_test',
];
protected $defaultTheme = 'stark';
public function testWizardSteps() {
$this->drupalGet('ctools/wizard');
$this->assertSession()
->pageTextContains('Form One');
$this->assertSession()
->pageTextContains('Xylophone');
$edit = [
'one' => 'test',
];
$this->drupalGet('ctools/wizard');
$this->submitForm($edit, 'Next');
$this->assertSession()
->pageTextContains('Form Two');
$this->assertSession()
->pageTextContains('Dynamic value submitted: Xylophone');
$this->assertSession()
->pageTextContains('Zebra');
$this->submitForm([], 'Previous');
$this->assertSession()
->fieldValueEquals('one', 'test');
$this->assertSession()
->pageTextContains('Xylophone');
$this->submitForm([], 'Next');
$edit = [
'two' => 'Second test',
];
$this->submitForm($edit, 'Finish');
$this->assertSession()
->pageTextContains('Value One: test');
$this->assertSession()
->pageTextContains('Value Two: Second test');
}
public function testStepValidateAndSubmit() {
$this->drupalGet('ctools/wizard');
$this->assertSession()
->pageTextContains('Form One');
$edit = [
'one' => 'wrong',
];
$this->drupalGet('ctools/wizard');
$this->submitForm($edit, 'Next');
$this->assertSession()
->pageTextContains('Form One');
$this->assertSession()
->pageTextContains('Cannot set the value to "wrong".');
$edit = [
'one' => 'magic',
];
$this->drupalGet('ctools/wizard');
$this->submitForm($edit, 'Next');
$this->assertSession()
->pageTextContains('Form Two');
$edit = [
'two' => 'Second test',
];
$this->submitForm($edit, 'Finish');
$this->assertSession()
->pageTextContains('Value One: Abraham');
$this->assertSession()
->pageTextContains('Value Two: Second test');
}
public function testEntityWizard() {
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
]));
$this->drupalGet('admin/structure/ctools_wizard_test_config_entity/add');
$this->assertSession()
->pageTextContains('Example entity');
$this->assertSession()
->pageTextNotContains('Existing entity');
$edit = [
'id' => 'test123',
'label' => 'Test Config Entity 123',
];
$this->submitForm($edit, 'Next');
$edit = [
'one' => 'The first bit',
];
$this->submitForm($edit, 'Next');
$edit = [
'two' => 'The second bit',
];
$this->submitForm($edit, 'Finish');
$this->assertSession()
->addressEquals('admin/structure/ctools_wizard_test_config_entity');
$this->assertSession()
->pageTextContains('Test Config Entity 123');
$this->clickLink($this->t('Edit'));
$this->assertSession()
->pageTextContains('Existing entity');
$this->assertSession()
->fieldValueEquals('label', 'Test Config Entity 123');
$this->clickLink($this->t('Form One'));
$this->assertSession()
->fieldValueEquals('one', 'The first bit');
$previous = $this->getUrl();
$this->clickLink($this->t('Show on dialog'));
$this->assertSession()
->responseContains('Value from one: The first bit');
$this->drupalGet($previous);
$this->submitForm([
'one' => 'New value',
], 'Next');
$this->assertSession()
->fieldValueEquals('two', 'The second bit');
$this->submitForm([], 'Next');
$this->assertSession()
->pageTextContains('This step only shows if the entity is already existing!');
$this->submitForm([], 'Finish');
$this->assertSession()
->addressEquals('admin/structure/ctools_wizard_test_config_entity');
$this->clickLink($this->t('Edit'));
$this->clickLink($this->t('Form One'));
$this->assertSession()
->fieldValueEquals('one', 'New value');
}
}
Classes