View source
<?php
namespace Drupal\Tests\webform\Functional\Wizard;
use Drupal\webform\Entity\Webform;
use Drupal\webform\WebformInterface;
class WebformWizardConditionalTest extends WebformWizardTestBase {
protected static $testWebforms = [
'test_form_wizard_conditional',
];
public function testConditionalWizard() {
$webform = Webform::load('test_form_wizard_conditional');
$this
->drupalGet('/webform/test_form_wizard_conditional');
$edit = [
'trigger_pages[page_1]' => FALSE,
'trigger_pages[page_3]' => FALSE,
'trigger_pages[page_5]' => FALSE,
];
$this
->drupalPostForm('/webform/test_form_wizard_conditional', $edit, 'Next >');
$this
->assertCurrentPage('Page 2', 'page_2');
$this
->drupalPostForm(NULL, [], 'Next >');
$this
->assertCurrentPage('Page 4', 'page_4');
$this
->drupalPostForm(NULL, [], 'Submit');
$this
->assertCurrentPage('Complete', WebformInterface::PAGE_CONFIRMATION);
$sid = $this
->getLastSubmissionId($webform);
$this
->assertNotEmpty($sid);
$edit = [
'trigger_none' => TRUE,
];
$this
->drupalPostForm('/webform/test_form_wizard_conditional', $edit, 'Next >');
$this
->assertRaw('<div class="webform-progress">');
$this
->assertRaw('New submission added to Test: Webform: Wizard conditional.');
$this
->assertCurrentPage('Complete', WebformInterface::PAGE_CONFIRMATION);
$sid = $this
->getLastSubmissionId($webform);
$this
->assertNotEmpty($sid);
$webform
->setSetting('preview', 1);
$webform
->save();
$edit = [
'trigger_none' => TRUE,
];
$this
->drupalPostForm('/webform/test_form_wizard_conditional', $edit, 'Next >');
$this
->assertCurrentPage('Preview', WebformInterface::PAGE_PREVIEW);
$webform
->setSettings([
'preview' => 0,
'wizard_confirmation' => FALSE,
]);
$webform
->save();
$edit = [
'trigger_none' => TRUE,
];
$this
->drupalPostForm('/webform/test_form_wizard_conditional', $edit, 'Next >');
$this
->assertNoRaw('<div class="webform-progress">');
$this
->assertRaw('New submission added to Test: Webform: Wizard conditional.');
$last_sid = $this
->getLastSubmissionId($webform);
$this
->assertNotEqual($sid, $last_sid);
$webform
->setSetting('wizard_progress_states', 1);
$webform
->save();
$this
->drupalGet('/webform/test_form_wizard_conditional');
$edit = [
'trigger_pages[page_3]' => FALSE,
'trigger_pages[page_5]' => FALSE,
];
$this
->drupalPostForm('/webform/test_form_wizard_conditional', $edit, 'Next >');
$this
->assertNoPattern('|<li data-webform-page="5" class="webform-progress-bar__page">\\s+<b>Page 5</b>|');
}
}