You are here

public function WebformWizardValidateTest::testWizardValidate in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/Wizard/WebformWizardValidateTest.php \Drupal\Tests\webform\Functional\Wizard\WebformWizardValidateTest::testWizardValidate()

Test webform wizard validation.

File

tests/src/Functional/Wizard/WebformWizardValidateTest.php, line 29

Class

WebformWizardValidateTest
Tests for webform wizard validation.

Namespace

Drupal\Tests\webform\Functional\Wizard

Code

public function testWizardValidate() {
  $this
    ->drupalGet('/webform/test_form_wizard_validate');

  /**************************************************************************/

  // Basic validation.

  /**************************************************************************/

  // Check validation errors.
  $this
    ->drupalPostForm('/webform/test_form_wizard_validate', [], 'Next >');
  $this
    ->assertRaw('wizard_1_textfield field is required.');
  $this
    ->assertRaw('wizard_1_select_other field is required.');
  $this
    ->assertRaw('wizard_1_datelist field is required.');

  // Check submiting page #1.
  $edit = [
    'wizard_1_textfield' => '{wizard_1_textfield}',
    'wizard_1_select_other[select]' => 'one',
    'wizard_1_datelist[items][0][_item_][year]' => '2001',
    'wizard_1_datelist[items][0][_item_][month]' => '1',
    'wizard_1_datelist[items][0][_item_][day]' => '1',
    'wizard_1_datelist[items][0][_item_][hour]' => '1',
    'wizard_1_datelist[items][0][_item_][minute]' => '10',
  ];
  $this
    ->drupalPostForm('/webform/test_form_wizard_validate', $edit, 'Next >');
  $this
    ->assertRaw("wizard_1_textfield: '{wizard_1_textfield}'\nwizard_1_select_other: one\nwizard_1_datelist:\n  - '2001-01-01T01:10:00+1100'\nwizard_2_textfield: ''\nwizard_2_select_other: null\nwizard_2_datelist: {  }");

  // Check submiting page #2.
  $edit = [
    'wizard_2_textfield' => '{wizard_2_textfield}',
    'wizard_2_select_other[select]' => 'two',
    'wizard_2_datelist[items][0][_item_][year]' => '2002',
    'wizard_2_datelist[items][0][_item_][month]' => '2',
    'wizard_2_datelist[items][0][_item_][day]' => '2',
    'wizard_2_datelist[items][0][_item_][hour]' => '2',
    'wizard_2_datelist[items][0][_item_][minute]' => '20',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Next >');
  $this
    ->assertRaw("wizard_1_textfield: '{wizard_1_textfield}'\nwizard_1_select_other: one\nwizard_1_datelist:\n  - '2001-01-01T01:10:00+1100'\nwizard_2_textfield: '{wizard_2_textfield}'\nwizard_2_select_other: two\nwizard_2_datelist:\n  - '2002-02-02T02:20:00+1100'");

  /**************************************************************************/

  // Composite validation.

  /**************************************************************************/

  // Check validation errors.
  $this
    ->drupalPostForm('/webform/test_form_wizard_validate_comp', [], 'Next >');

  // $this->assertRaw('The <em class="placeholder">datelist</em> date is required.');
  $this
    ->assertRaw('textfield field is required.');

  // Check submiting page #1.
  $edit = [
    'wizard_1_custom_composite[items][0][datelist][year]' => '2001',
    'wizard_1_custom_composite[items][0][datelist][month]' => '1',
    'wizard_1_custom_composite[items][0][datelist][day]' => '1',
    'wizard_1_custom_composite[items][0][datelist][hour]' => '1',
    'wizard_1_custom_composite[items][0][datelist][minute]' => '10',
    'wizard_1_custom_composite[items][0][textfield]' => '{wizard_1_custom_composite_textfield}',
    'wizard_1_test_composite[textfield]' => '{wizard_1_test_composite_textfield}',
    'wizard_1_test_composite[datelist][year]' => '2001',
    'wizard_1_test_composite[datelist][month]' => '1',
    'wizard_1_test_composite[datelist][day]' => '1',
    'wizard_1_test_composite[datelist][hour]' => '1',
    'wizard_1_test_composite[datelist][minute]' => '10',
    'wizard_1_test_composite_multiple[items][0][_item_][textfield]' => '{wizard_1_test_composite_multiple_textfield}',
    'wizard_1_test_composite_multiple[items][0][_item_][datelist][year]' => '2001',
    'wizard_1_test_composite_multiple[items][0][_item_][datelist][month]' => '1',
    'wizard_1_test_composite_multiple[items][0][_item_][datelist][day]' => '1',
    'wizard_1_test_composite_multiple[items][0][_item_][datelist][hour]' => '1',
    'wizard_1_test_composite_multiple[items][0][_item_][datelist][minute]' => '10',
  ];
  $this
    ->drupalPostForm('/webform/test_form_wizard_validate_comp', $edit, 'Next >');
  $this
    ->assertRaw("wizard_1_custom_composite:\n  - datelist: '2001-01-01T01:10:00+1100'\n    textfield: '{wizard_1_custom_composite_textfield}'\nwizard_1_test_composite:\n  textfield: '{wizard_1_test_composite_textfield}'\n  datelist: '2001-01-01T01:10:00+1100'\n  nested_tel: ''\n  nested_select: ''\n  email: ''\n  webform_email_confirm: ''\n  tel: ''\n  select: ''\n  radios: ''\n  date: ''\n  webform_entity_select: ''\n  entity_autocomplete: null\n  datetime: ''\n  nested_radios: ''\nwizard_1_test_composite_multiple:\n  - textfield: '{wizard_1_test_composite_multiple_textfield}'\n    datelist: '2001-01-01T01:10:00+1100'\n    nested_tel: ''\n    nested_select: ''\n    email: ''\n    webform_email_confirm: ''\n    tel: ''\n    select: ''\n    radios: null\n    date: ''\n    webform_entity_select: ''\n    entity_autocomplete: null\n    datetime: ''\n    nested_radios: null\nwizard_2_custom_composite: {  }\nwizard_2_test_composite: null\nwizard_2_test_composite_multiple: {  }");

  // Check submiting page #2.
  $edit = [
    'wizard_2_custom_composite[items][0][datelist][year]' => '2002',
    'wizard_2_custom_composite[items][0][datelist][month]' => '2',
    'wizard_2_custom_composite[items][0][datelist][day]' => '2',
    'wizard_2_custom_composite[items][0][datelist][hour]' => '2',
    'wizard_2_custom_composite[items][0][datelist][minute]' => '20',
    'wizard_2_custom_composite[items][0][textfield]' => '{wizard_2_custom_composite_textfield}',
    'wizard_2_test_composite[textfield]' => '{wizard_2_test_composite_textfield}',
    'wizard_2_test_composite[datelist][year]' => '2002',
    'wizard_2_test_composite[datelist][month]' => '2',
    'wizard_2_test_composite[datelist][day]' => '2',
    'wizard_2_test_composite[datelist][hour]' => '2',
    'wizard_2_test_composite[datelist][minute]' => '20',
    'wizard_2_test_composite_multiple[items][0][_item_][textfield]' => '{wizard_2_test_composite_multiple_textfield}',
    'wizard_2_test_composite_multiple[items][0][_item_][datelist][year]' => '2002',
    'wizard_2_test_composite_multiple[items][0][_item_][datelist][month]' => '2',
    'wizard_2_test_composite_multiple[items][0][_item_][datelist][day]' => '2',
    'wizard_2_test_composite_multiple[items][0][_item_][datelist][hour]' => '2',
    'wizard_2_test_composite_multiple[items][0][_item_][datelist][minute]' => '20',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Next >');
  $raw = "wizard_1_custom_composite:\n  - datelist: '2001-01-01T01:10:00+1100'\n    textfield: '{wizard_1_custom_composite_textfield}'\nwizard_1_test_composite:\n  textfield: '{wizard_1_test_composite_textfield}'\n  datelist: '2001-01-01T01:10:00+1100'\n  nested_tel: ''\n  nested_select: ''\n  email: ''\n  webform_email_confirm: ''\n  tel: ''\n  select: ''\n  radios: ''\n  date: ''\n  webform_entity_select: ''\n  entity_autocomplete: null\n  datetime: ''\n  nested_radios: ''\nwizard_1_test_composite_multiple:\n  - textfield: '{wizard_1_test_composite_multiple_textfield}'\n    datelist: '2001-01-01T01:10:00+1100'\n    nested_tel: ''\n    nested_select: ''\n    email: ''\n    webform_email_confirm: ''\n    tel: ''\n    select: ''\n    radios: null\n    date: ''\n    webform_entity_select: ''\n    entity_autocomplete: null\n    datetime: ''\n    nested_radios: null\nwizard_2_custom_composite:\n  - datelist: '2002-02-02T02:20:00+1100'\n    textfield: '{wizard_2_custom_composite_textfield}'\nwizard_2_test_composite:\n  textfield: '{wizard_2_test_composite_textfield}'\n  datelist: '2002-02-02T02:20:00+1100'\n  nested_tel: ''\n  nested_select: ''\n  email: ''\n  webform_email_confirm: ''\n  tel: ''\n  select: ''\n  radios: ''\n  date: ''\n  webform_entity_select: ''\n  entity_autocomplete: null\n  datetime: ''\n  nested_radios: ''\nwizard_2_test_composite_multiple:\n  - textfield: '{wizard_2_test_composite_multiple_textfield}'\n    datelist: '2002-02-02T02:20:00+1100'\n    nested_tel: ''\n    nested_select: ''\n    email: ''\n    webform_email_confirm: ''\n    tel: ''\n    select: ''\n    radios: null\n    date: ''\n    webform_entity_select: ''\n    entity_autocomplete: null\n    datetime: ''\n    nested_radios: null";
  $this
    ->assertRaw($raw);

  // Make sure navigating back and next through the
  // previous pages does not lose any data.
  $this
    ->drupalPostForm(NULL, [], '< Previous');
  $this
    ->assertRaw($raw);
  $this
    ->drupalPostForm(NULL, [], '< Previous');
  $this
    ->assertRaw($raw);
  $this
    ->drupalPostForm(NULL, [], 'Next >');
  $this
    ->assertRaw($raw);
  $this
    ->drupalPostForm(NULL, [], 'Next >');
  $this
    ->assertRaw($raw);
}