View source
<?php
namespace Drupal\Tests\webform\Functional\Wizard;
use Drupal\webform\Entity\Webform;
use Drupal\Core\Serialization\Yaml;
use Drupal\webform\WebformInterface;
class WebformWizardAdvancedTest extends WebformWizardTestBase {
protected static $testWebforms = [
'test_form_wizard_advanced',
];
public function testAdvancedWizard() {
$webform = Webform::load('test_form_wizard_advanced');
$this
->drupalGet('/webform/test_form_wizard_advanced');
$this
->assertPattern('#<li data-webform-page="information" class="webform-progress-bar__page webform-progress-bar__page--current"><b>Your Information</b><span></span></li>#');
$this
->assertRaw('1 of 5');
$this
->assertText('(0%)');
$this
->assertNoFieldById('edit-draft', 'Save Draft');
$this
->assertFieldById('edit-wizard-next', 'Next >');
$this
->assertFieldById('edit-first-name', 'John');
$account = $this
->drupalCreateUser();
$this
->drupalLogin($account);
$edit = [
'first_name' => 'Jane',
];
$this
->drupalPostForm('/webform/test_form_wizard_advanced', $edit, 'Next >');
$this
->assertPattern('#<li data-webform-page="information" class="webform-progress-bar__page webform-progress-bar__page--done"><b>Your Information</b><span></span></li>#');
$this
->assertPattern('#<li data-webform-page="contact" class="webform-progress-bar__page webform-progress-bar__page--current"><b>Contact Information</b></li>#');
$this
->assertRaw('2 of 5');
$this
->assertText('(25%)');
$this
->assertFieldById('edit-draft', 'Save Draft');
$this
->assertFieldById('edit-wizard-prev', '< Previous');
$this
->assertFieldById('edit-wizard-next', 'Next >');
$this
->assertFieldById('edit-email', 'johnsmith@example.com');
$edit = [
'email' => 'janesmith@example.com',
];
$this
->drupalPostForm(NULL, $edit, '< Previous');
$this
->assertPattern('#<li data-webform-page="information" class="webform-progress-bar__page webform-progress-bar__page--current"><b>Your Information</b><span></span></li>#');
$this
->assertRaw('js-webform-unsaved');
$this
->assertNoRaw('data-webform-unsaved');
$this
->assertRaw('1 of 5');
$this
->assertText('(0%)');
$this
->assertFieldById('edit-first-name', 'Jane');
$this
->assertFieldChecked('edit-gender-male');
$edit = [
'gender' => 'Female',
];
$this
->drupalPostForm(NULL, $edit, 'Save Draft');
$this
->assertFieldById('edit-first-name', 'Jane');
$this
->assertFieldChecked('edit-gender-female');
$this
->drupalPostForm('/webform/test_form_wizard_advanced', [], 'Next >');
$this
->assertRaw('js-webform-unsaved');
$this
->assertRaw('data-webform-unsaved');
$this
->assertCurrentPage('Contact Information', 'contact');
$this
->assertRaw('2 of 5');
$this
->assertText('(25%)');
$this
->assertFieldById('edit-email', 'janesmith@example.com');
$edit = [
'phone' => '111-111-1111',
];
$this
->drupalPostForm(NULL, $edit, 'Save Draft');
$this
->drupalGet('/webform/test_form_wizard_advanced');
$this
->assertCurrentPage('Contact Information', 'contact');
$this
->drupalPostForm(NULL, [], 'Next >');
$this
->assertCurrentPage('Your Feedback', 'feedback');
$this
->assertFieldById('edit-wizard-prev', '< Previous');
$this
->assertFieldById('edit-preview-next', 'Preview');
$this
->assertFieldById('edit-submit', 'Submit');
$edit = [
'comments' => 'This is working fine.',
];
$this
->drupalPostForm(NULL, $edit, 'Preview');
$this
->assertCurrentPage('Preview', WebformInterface::PAGE_PREVIEW);
$this
->assertRaw('4 of 5');
$this
->assertText('(75%)');
$this
->assertRaw('<label>First Name</label>');
$this
->assertRaw('Jane');
$this
->assertRaw('<label>Last Name</label>');
$this
->assertRaw('Smith');
$this
->assertRaw('<label>Gender</label>');
$this
->assertRaw('Female');
$this
->assertRaw('<label>Email</label>');
$this
->assertRaw('<a href="mailto:janesmith@example.com">janesmith@example.com</a>');
$this
->assertRaw('<label>Phone</label>');
$this
->assertRaw('<a href="tel:111-111-1111">111-111-1111</a>');
$this
->assertRaw('<div class="webform-element webform-element-type-textarea js-form-item form-item js-form-type-item form-item-comments js-form-item-comments form-no-label" id="test_form_wizard_advanced--comments">');
$this
->assertRaw('This is working fine.');
$this
->drupalPostForm(NULL, [], 'Submit');
$this
->assertCurrentPage('Complete', WebformInterface::PAGE_CONFIRMATION);
$this
->assertRaw('5 of 5');
$this
->assertText('(100%)');
$this
->drupalLogout();
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_wizard_next_button_label', '{global wizard next}')
->set('settings.default_wizard_prev_button_label', '{global wizard previous}')
->save();
$this
->drupalPostForm('/webform/test_form_wizard_advanced', [], '{global wizard next}');
$this
->assertRaw('class="webform-progress-bar"');
$this
->assertFieldById('edit-wizard-prev', '{global wizard previous}');
$this
->assertFieldById('edit-wizard-next', '{global wizard next}');
$webform
->setElementProperties('actions', [
'#type' => 'webform_actions',
'#wizard_next__label' => '{webform wizard next}',
'#wizard_prev__label' => '{webform wizard previous}',
'#preview_next__label' => '{webform preview next}',
'#preview_prev__label' => '{webform preview previous}',
]);
$webform
->save();
$this
->drupalPostForm('/webform/test_form_wizard_advanced', [], '{webform wizard next}');
$this
->assertFieldById('edit-actions-wizard-prev', '{webform wizard previous}');
$this
->assertFieldById('edit-actions-wizard-next', '{webform wizard next}');
$elements = Yaml::decode($webform
->get('elements'));
$elements['contact']['#next_button_label'] = '{elements wizard next}';
$elements['contact']['#prev_button_label'] = '{elements wizard previous}';
$webform
->set('elements', Yaml::encode($elements));
$webform
->save();
$this
->drupalPostForm('/webform/test_form_wizard_advanced', [], '{webform wizard next}');
$this
->assertFieldById('edit-actions-wizard-prev', '{elements wizard previous}');
$this
->assertFieldById('edit-actions-wizard-next', '{elements wizard next}');
$webform
->setSettings([
'wizard_progress_bar' => FALSE,
'wizard_progress_pages' => TRUE,
'wizard_progress_percentage' => TRUE,
] + $webform
->getSettings());
$webform
->save();
$this
->drupalGet('/webform/test_form_wizard_advanced');
$this
->assertNoRaw('class="webform-progress-bar"');
$this
->assertRaw('1 of 5');
$this
->assertText('(0%)');
$webform
->setSettings([
'wizard_progress_bar' => TRUE,
] + $webform
->getSettings());
$webform
->save();
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_wizard_confirmation_label', '{global complete}')
->save();
$this
->drupalGet('/webform/test_form_wizard_advanced');
$this
->assertRaw('{global complete}');
$webform
->setSettings([
'wizard_progress_bar' => TRUE,
'wizard_confirmation_label' => '{webform complete}',
] + $webform
->getSettings());
$webform
->save();
$this
->drupalGet('/webform/test_form_wizard_advanced');
$this
->assertRaw('{webform complete}');
$webform
->setSettings([
'wizard_confirmation' => FALSE,
] + $webform
->getSettings());
$webform
->save();
$this
->drupalGet('/webform/test_form_wizard_advanced');
$this
->assertRaw('class="webform-progress-bar"');
$this
->assertNoRaw('{webform complete}');
$this
->drupalGet('/webform/test_form_wizard_advanced/confirmation');
$this
->assertNoRaw('class="webform-progress-bar"');
}
}