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->dumpHeaders = TRUE;
$this
->assertSession()
->pageTextContains('Xylophone');
$edit = [
'one' => 'test',
];
$this
->drupalPostForm('ctools/wizard', $edit, $this
->t('Next'));
$this
->assertSession()
->pageTextContains('Form Two');
$this
->assertSession()
->pageTextContains('Dynamic value submitted: Xylophone');
$this
->assertSession()
->pageTextContains('Zebra');
$this
->drupalPostForm(NULL, [], $this
->t('Previous'));
$this
->assertSession()
->fieldValueEquals('one', 'test');
$this
->assertSession()
->pageTextContains('Xylophone');
$this
->drupalPostForm(NULL, [], $this
->t('Next'));
$edit = [
'two' => 'Second test',
];
$this
->drupalPostForm(NULL, $edit, $this
->t('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
->drupalPostForm('ctools/wizard', $edit, $this
->t('Next'));
$this
->assertSession()
->pageTextContains('Form One');
$this
->assertSession()
->pageTextContains('Cannot set the value to "wrong".');
$edit = [
'one' => 'magic',
];
$this
->drupalPostForm('ctools/wizard', $edit, $this
->t('Next'));
$this
->assertSession()
->pageTextContains('Form Two');
$edit = [
'two' => 'Second test',
];
$this
->drupalPostForm(NULL, $edit, $this
->t('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
->drupalPostForm(NULL, $edit, $this
->t('Next'));
$edit = [
'one' => 'The first bit',
];
$this
->drupalPostForm(NULL, $edit, $this
->t('Next'));
$edit = [
'two' => 'The second bit',
];
$this
->drupalPostForm(NULL, $edit, $this
->t('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
->drupalPostForm(NULL, [
'one' => 'New value',
], $this
->t('Next'));
$this
->assertSession()
->fieldValueEquals('two', 'The second bit');
$this
->drupalPostForm(NULL, [], $this
->t('Next'));
$this
->assertSession()
->pageTextContains('This step only shows if the entity is already existing!');
$this
->drupalPostForm(NULL, [], $this
->t('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');
}
}