WebformStatesPreviewTest.php in Webform 8.5
File
tests/src/Functional/States/WebformStatesPreviewTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\States;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformStatesPreviewTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_states_server_preview',
'test_states_server_save',
'test_states_server_clear',
];
public function testStatesValidatorElementVisible() {
$webform_preview = Webform::load('test_states_server_preview');
$this
->postSubmission($webform_preview, [], 'Preview');
$this
->assertRaw('trigger_checkbox');
$this
->assertNoRaw('dependent_checkbox');
$this
->assertNoRaw('dependent_markup');
$this
->assertNoRaw('dependent_message');
$this
->assertNoRaw('dependent_fieldset');
$this
->assertNoRaw('nested_textfield');
$this
->postSubmission($webform_preview, [
'trigger_checkbox' => TRUE,
], 'Preview');
$this
->assertRaw('trigger_checkbox');
$this
->assertRaw('dependent_checkbox');
$this
->assertRaw('dependent_markup');
$this
->assertRaw('dependent_message');
$this
->assertRaw('dependent_fieldset');
$this
->assertRaw('nested_textfield');
$webform_save = Webform::load('test_states_server_save');
$this
->postSubmission($webform_save, [
'trigger_checkbox' => FALSE,
], 'Submit');
$this
->assertRaw("trigger_checkbox: 0\ndependent_hidden: ''\ndependent_checkbox: ''\ndependent_value: ''\ndependent_textfield: ''\ndependent_textfield_multiple: { }\ndependent_details_textfield: ''");
$this
->postSubmission($webform_save, [
'trigger_checkbox' => TRUE,
], 'Submit');
$this
->assertRaw("trigger_checkbox: 1\ndependent_hidden: '{dependent_hidden}'\ndependent_checkbox: 0\ndependent_value: '{value}'\ndependent_textfield: '{dependent_textfield}'\ndependent_textfield_multiple:\n - '{dependent_textfield}'\ndependent_details_textfield: '{dependent_details_textfield}'");
$webform_clear = Webform::load('test_states_server_clear');
$this
->postSubmission($webform_clear, [
'trigger_checkbox' => FALSE,
], 'Submit');
$this
->assertRaw("trigger_checkbox: 0\ndependent_hidden: '{dependent_hidden}'\ndependent_checkbox: 1\ndependent_radios: One\ndependent_value: '{value}'\ndependent_textfield: '{dependent_textfield}'\ndependent_textfield_multiple:\n - '{dependent_textfield}'\ndependent_webform_name:\n - title: ''\n first: John\n middle: ''\n last: Smith\n suffix: ''\n degree: ''\ndependent_details_textfield: '{dependent_details_textfield}'");
}
}