View source
<?php
namespace Drupal\Tests\webform\FunctionalJavascript\Settings;
use Drupal\Tests\webform\FunctionalJavascript\WebformWebDriverTestBase;
use Drupal\webform\Entity\Webform;
class WebformSettingsAjaxJavaScriptTest extends WebformWebDriverTestBase {
protected static $testWebforms = [
'test_ajax',
'test_ajax_confirmation_inline',
'test_ajax_confirmation_message',
'test_ajax_confirmation_modal',
'test_ajax_confirmation_page',
'test_ajax_confirmation_url',
'test_ajax_confirmation_url_msg',
];
public function testAjax() {
$assert_session = $this
->assertSession();
$webform_ajax = Webform::load('test_ajax');
$this
->drupalPostForm($webform_ajax
->toUrl(), [
'textfield' => '',
], 'Submit');
$assert_session
->waitForElement('css', '.messages--error');
$assert_session
->responseContains('textfield field is required.');
$this
->drupalPostForm($webform_ajax
->toUrl(), [
'textfield' => 'test value',
], 'Preview');
$assert_session
->waitForElement('css', '.messages--warning');
$assert_session
->responseContains('Please review your submission. Your submission is not complete until you press the "Submit" button!');
$this
->drupalPostForm($webform_ajax
->toUrl(), [
'textfield' => 'test value',
], 'Submit');
$assert_session
->waitForElement('css', '.messages--status');
$assert_session
->responseContains('New submission added to Test: Ajax.');
$sid = $this
->getLastSubmissionId($webform_ajax);
$this
->assertEquals($sid, 1);
$assert_session
->fieldValueEquals('textfield', '');
$webform_ajax_confirmation_inline = Webform::load('test_ajax_confirmation_inline');
$this
->drupalPostForm($webform_ajax_confirmation_inline
->toUrl(), [], 'Submit');
$assert_session
->waitForElement('css', '.messages--status');
$assert_session
->waitForText('This is a custom inline confirmation message.');
$assert_session
->responseContains('This is a custom inline confirmation message.');
$this
->clickLink('Back to form');
$assert_session
->waitForButton('Submit');
$assert_session
->responseNotContains('This is a custom inline confirmation message.');
$assert_session
->responseContains('This webform will display the confirmation inline when submitted.');
$webform_ajax_confirmation_message = Webform::load('test_ajax_confirmation_message');
$this
->drupalPostForm($webform_ajax_confirmation_message
->toUrl(), [], 'Submit');
$assert_session
->waitForElement('css', '.messages--status');
$assert_session
->responseContains('This is a <b>custom</b> confirmation message.');
$assert_session
->responseContains('This webform will display a confirmation message when submitted.');
$webform_ajax_confirmation_modal = Webform::load('test_ajax_confirmation_modal');
$this
->drupalPostForm($webform_ajax_confirmation_modal
->toUrl(), [], 'Submit');
$assert_session
->waitForElementVisible('css', '.ui-dialog.webform-confirmation-modal');
$assert_session
->responseContains('This is a <b>custom</b> confirmation modal.');
$webform_ajax_confirmation_page = Webform::load('test_ajax_confirmation_page');
$this
->drupalPostForm($webform_ajax_confirmation_page
->toUrl(), [], 'Submit');
$assert_session
->waitForLink('Back to form');
$assert_session
->responseContains('This is a custom confirmation page.');
$webform_ajax_confirmation_url = Webform::load('test_ajax_confirmation_url');
$this
->drupalPostForm($webform_ajax_confirmation_url
->toUrl(), [], 'Submit');
$assert_session
->waitForElement('css', '.path-front');
$this
->assertSession()
->addressEquals('/');
$webform_ajax_confirmation_url_msg = Webform::load('test_ajax_confirmation_url_msg');
$this
->drupalPostForm($webform_ajax_confirmation_url_msg
->toUrl(), [], 'Submit');
$assert_session
->waitForElement('css', '.path-front');
$this
->assertSession()
->addressEquals('/');
$assert_session
->responseContains('This is a custom confirmation message.');
}
}