You are here

function WebformSubmissionTestCase::testWebformSubmissionRequiredComponents in Webform 6.3

Same name and namespace in other branches
  1. 7.4 tests/WebformSubmissionTestCase.test \WebformSubmissionTestCase::testWebformSubmissionRequiredComponents()
  2. 7.3 tests/submission.test \WebformSubmissionTestCase::testWebformSubmissionRequiredComponents()

Test that required fields with no default value can't be submitted as-is.

File

tests/submission.test, line 69

Class

WebformSubmissionTestCase

Code

function testWebformSubmissionRequiredComponents() {
  $this
    ->drupalLogin($this->webform_users['admin']);
  $this
    ->webformReset();

  // Create the Webform test node, and set all components to be mandatory
  // with no default value.
  $node = $this
    ->testWebformForm();
  $node = node_load($node->nid);
  foreach ($node->webform['components'] as &$component) {
    $component['value'] = '';
    $component['mandatory'] = '1';
  }
  node_save($node);

  // Submit the webform with no data. We should get a message that all the
  // components are required. (The exceptions are hidden fields, which can't
  // be made mandatory, and date fields, which default to the current date
  // when no default value is provided; therefore, we don't expect a message
  // for those.)
  $this
    ->drupalPost('node/' . $node->nid, array(), 'Submit', array(), array(), 'webform-client-form-' . $node->nid);
  foreach ($node->webform['components'] as $component) {
    if ($component['type'] != 'hidden' && $component['type'] != 'date') {
      $this
        ->assertText(t('!name field is required.', array(
        '!name' => $component['name'],
      )));
    }
  }
  $this
    ->drupalLogout();
}