View source
<?php
namespace Drupal\Tests\webform\Functional\Settings;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformSettingsConfirmationTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_confirmation_message',
'test_confirmation_modal',
'test_confirmation_inline',
'test_confirmation_page',
'test_confirmation_page_custom',
'test_confirmation_url',
'test_confirmation_url_message',
'test_confirmation_none',
];
protected function setUp() {
parent::setUp();
\Drupal::configFactory()
->getEditable('system.site')
->set('page.front', '/node')
->save();
}
public function testConfirmation() {
$this
->drupalLogin($this->rootUser);
$webform_confirmation_message = Webform::load('test_confirmation_message');
$this
->postSubmission($webform_confirmation_message);
$this
->assertRaw('This is a <b>custom</b> confirmation message.');
$this
->assertNoRaw('New submission added to <em class="placeholder">Test: Confirmation: Message</em>');
$this
->assertUrl('webform/test_confirmation_message');
$sid = $this
->postSubmission($webform_confirmation_message, [], NULL, [
'query' => [
'custom' => 'param',
],
]);
$this
->assertUrl('webform/test_confirmation_message', [
'query' => [
'custom' => 'param',
],
]);
sleep(1);
$this
->drupalPostForm("/admin/structure/webform/manage/test_confirmation_message/submission/{$sid}/edit", [], 'Save');
$this
->assertNoRaw('This is a <b>custom</b> confirmation message. (test: )');
$this
->assertRaw('Submission updated in <em class="placeholder">Test: Confirmation: Message</em>.');
$webform_confirmation_message
->setSetting('confirmation_update', TRUE)
->save();
$this
->drupalPostForm("/admin/structure/webform/manage/test_confirmation_message/submission/{$sid}/edit", [], 'Save');
$this
->assertRaw('This is a <b>custom</b> confirmation message. (test: )');
$this
->assertNoRaw('Submission updated in <em class="placeholder">Test: Confirmation: Message</em>.');
$webform_confirmation_modal = Webform::load('test_confirmation_modal');
$sid = $this
->postSubmission($webform_confirmation_modal, [
'test' => 'value',
]);
$this
->assertRaw('This is a <b>custom</b> confirmation modal.');
$this
->assertRaw('<div class="js-hide webform-confirmation-modal js-webform-confirmation-modal webform-message js-webform-message js-form-wrapper form-wrapper" data-drupal-selector="edit-webform-confirmation-modal" id="edit-webform-confirmation-modal">');
$this
->assertRaw('<div role="contentinfo" aria-label="Status message">');
$this
->assertRaw('<b class="webform-confirmation-modal--title">Custom confirmation modal</b><br />');
$this
->assertRaw('<div class="webform-confirmation-modal--content">This is a <b>custom</b> confirmation modal. (test: value)</div>');
$this
->assertUrl('webform/test_confirmation_modal');
$this
->drupalPostForm("/admin/structure/webform/manage/test_confirmation_modal/submission/{$sid}/edit", [], 'Save');
$this
->assertRaw('Submission updated in <em class="placeholder">Test: Confirmation: Modal</em>.');
$webform_confirmation_modal
->setSetting('confirmation_update', TRUE)
->save();
$this
->drupalPostForm("/admin/structure/webform/manage/test_confirmation_modal/submission/{$sid}/edit", [], 'Save');
$this
->assertRaw('<b class="webform-confirmation-modal--title">Custom confirmation modal</b><br /><div class="webform-confirmation-modal--content">This is a <b>custom</b> confirmation modal. (test: value)</div>');
$webform_confirmation_inline = Webform::load('test_confirmation_inline');
$this
->drupalPostForm('/webform/test_confirmation_inline', [], 'Submit');
$this
->assertRaw('<a href="' . $webform_confirmation_inline
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString() . '" rel="prev">Back to form</a>');
$this
->assertUrl('webform/test_confirmation_inline');
$this
->drupalPostForm('/webform/test_confirmation_inline', [], 'Submit', [
'query' => [
'custom' => 'param',
],
]);
$this
->assertRaw('<a href="' . $webform_confirmation_inline
->toUrl('canonical', [
'absolute' => TRUE,
'query' => [
'custom' => 'param',
],
])
->toString() . '" rel="prev">Back to form</a>');
$this
->assertUrl('webform/test_confirmation_inline', [
'query' => [
'custom' => 'param',
],
]);
$webform_confirmation_page = Webform::load('test_confirmation_page');
$sid = $this
->postSubmission($webform_confirmation_page);
$webform_submission = WebformSubmission::load($sid);
$this
->assertRaw('This is a custom confirmation page.');
$this
->assertRaw('<a href="' . $webform_confirmation_page
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString() . '" rel="prev">Back to form</a>');
$this
->assertUrl('webform/test_confirmation_page/confirmation', [
'query' => [
'token' => $webform_submission
->getToken(),
],
]);
$this
->drupalGet('/webform/test_confirmation_page/confirmation', [
'query' => [
'custom' => 'param',
],
]);
$sid = $this
->postSubmission($webform_confirmation_page, [], NULL, [
'query' => [
'custom' => 'param',
],
]);
$webform_submission = WebformSubmission::load($sid);
$this
->assertUrl('webform/test_confirmation_page/confirmation', [
'query' => [
'custom' => 'param',
'token' => $webform_submission
->getToken(),
],
]);
$webform_confirmation_page
->setSetting('confirmation_exclude_token', TRUE);
$webform_confirmation_page
->save();
$this
->postSubmission($webform_confirmation_page, [], NULL, [
'query' => [
'custom' => 'param',
],
]);
$this
->assertUrl('webform/test_confirmation_page/confirmation', [
'query' => [
'custom' => 'param',
],
]);
$webform_confirmation_page
->setSetting('confirmation_exclude_query', TRUE);
$webform_confirmation_page
->save();
$this
->postSubmission($webform_confirmation_page);
$this
->assertUrl('webform/test_confirmation_page/confirmation');
$webform_confirmation_page_custom = Webform::load('test_confirmation_page_custom');
$this
->postSubmission($webform_confirmation_page_custom);
$this
->assertRaw('<h1>Custom confirmation page title</h1>');
$this
->assertRaw('<div style="border: 10px solid red; padding: 1em;" class="webform-confirmation">');
$this
->assertRaw('<a href="' . $webform_confirmation_page_custom
->toUrl()
->setAbsolute()
->toString() . '" rel="prev" class="button">Custom back to link</a>');
$webform_confirmation_page_custom
->setSetting('confirmation_back', FALSE);
$webform_confirmation_page_custom
->save();
$this
->postSubmission($webform_confirmation_page_custom);
$this
->assertNoRaw('<a href="' . $webform_confirmation_page_custom
->toUrl()
->toString() . '" rel="prev" class="button">Custom back to link</a>');
$webform_confirmation_url = Webform::load('test_confirmation_url');
$this
->postSubmission($webform_confirmation_url);
$this
->assertNoRaw('<h2 class="visually-hidden">Status message</h2>');
$this
->assertUrl('/');
$webform_confirmation_url
->setSetting('confirmation_url', 'internal:/some-internal-path')
->save();
$this
->postSubmission($webform_confirmation_url);
$this
->assertUrl('/some-internal-path');
$webform_confirmation_url_message = Webform::load('test_confirmation_url_message');
$this
->postSubmission($webform_confirmation_url_message);
$this
->assertRaw('<h2 class="visually-hidden">Status message</h2>');
$this
->assertRaw('This is a custom confirmation message.');
$this
->assertUrl('/');
$this
->drupalLogout();
$webform_confirmation_url_message = Webform::load('test_confirmation_none');
$this
->postSubmission($webform_confirmation_url_message);
$this
->assertNoRaw('<h2 class="visually-hidden">Status message</h2>');
}
}