View source
<?php
namespace Drupal\yamlform\Tests;
use Drupal\yamlform\Entity\YamlForm;
class YamlFormConfirmationTest extends YamlFormTestBase {
protected static $modules = [
'system',
'user',
'yamlform',
'yamlform_test',
];
public function testConfirmation() {
$this
->drupalLogin($this->adminFormUser);
$this
->drupalPostForm('yamlform/test_confirmation_message', [], t('Submit'));
$this
->assertRaw('This is a <b>custom</b> confirmation message.');
$this
->assertUrl('yamlform/test_confirmation_message');
$this
->drupalPostForm('yamlform/test_confirmation_message', [], t('Submit'), [
'query' => [
'custom' => 'param',
],
]);
$this
->assertUrl('yamlform/test_confirmation_message', [
'query' => [
'custom' => 'param',
],
]);
$yamlform_confirmation_inline = YamlForm::load('test_confirmation_inline');
$this
->drupalPostForm('yamlform/test_confirmation_inline', [], t('Submit'));
$this
->assertRaw('<a href="' . $yamlform_confirmation_inline
->toUrl()
->toString() . '" rel="back" title="Back to form">Back to form</a>');
$this
->assertUrl('yamlform/test_confirmation_inline', [
'query' => [
'yamlform_id' => $yamlform_confirmation_inline
->id(),
],
]);
$this
->drupalPostForm('yamlform/test_confirmation_inline', [], t('Submit'), [
'query' => [
'custom' => 'param',
],
]);
$this
->assertRaw('<a href="' . $yamlform_confirmation_inline
->toUrl()
->toString() . '?custom=param" rel="back" title="Back to form">Back to form</a>');
$this
->assertUrl('yamlform/test_confirmation_inline', [
'query' => [
'custom' => 'param',
'yamlform_id' => $yamlform_confirmation_inline
->id(),
],
]);
$yamlform_confirmation_page = YamlForm::load('test_confirmation_page');
$this
->drupalPostForm('yamlform/test_confirmation_page', [], t('Submit'));
$this
->assertRaw('This is a custom confirmation page.');
$this
->assertRaw('<a href="' . $yamlform_confirmation_page
->toUrl()
->toString() . '" rel="back" title="Back to form">Back to form</a>');
$this
->assertUrl('yamlform/test_confirmation_page/confirmation');
$this
->drupalGet('yamlform/test_confirmation_page/confirmation', [
'query' => [
'custom' => 'param',
],
]);
$this
->drupalPostForm('yamlform/test_confirmation_page', [], t('Submit'), [
'query' => [
'custom' => 'param',
],
]);
$this
->assertUrl('yamlform/test_confirmation_page/confirmation', [
'query' => [
'custom' => 'param',
],
]);
$yamlform_confirmation_page_custom = YamlForm::load('test_confirmation_page_custom');
$this
->drupalPostForm('yamlform/test_confirmation_page_custom', [], t('Submit'));
$this
->assertRaw('<div style="border: 10px solid red; padding: 1em;" class="yamlform-confirmation">');
$this
->assertRaw('<a href="' . $yamlform_confirmation_page_custom
->toUrl()
->toString() . '" rel="back" title="Custom back to link" class="button">Custom back to link</a>');
$yamlform_confirmation_page_custom
->setSetting('confirmation_back', FALSE);
$yamlform_confirmation_page_custom
->save();
$this
->drupalPostForm('yamlform/test_confirmation_page_custom', [], t('Submit'));
$this
->assertNoRaw('<a href="' . $yamlform_confirmation_page_custom
->toUrl()
->toString() . '" rel="back" title="Custom back to link" class="button">Custom back to link</a>');
$this
->drupalPostForm('yamlform/test_confirmation_url', [], t('Submit'));
$this
->assertNoRaw('<h2 class="visually-hidden">Status message</h2>');
$this
->assertUrl('<front>');
$this
->drupalPostForm('yamlform/test_confirmation_url_message', [], t('Submit'));
$this
->assertRaw('<h2 class="visually-hidden">Status message</h2>');
$this
->assertRaw('This is a custom confirmation message.');
$this
->assertUrl('<front>');
}
}