You are here

function WebformSubmissionTestCase::webformSubmissionValidateExecute in Webform 6.3

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

Execute a validation check for a single component.

Parameters

$value_type: The values to be submitted to the webform. Either "sample" or "default".

1 call to WebformSubmissionTestCase::webformSubmissionValidateExecute()
WebformSubmissionTestCase::testWebformSubmissionValidate in tests/submission.test
Test validation errors on each component that has specialized validation.

File

tests/submission.test, line 147

Class

WebformSubmissionTestCase

Code

function webformSubmissionValidateExecute() {
  $path = drupal_get_path('module', 'webform');
  module_load_include('inc', 'webform', 'includes/webform.submissions');

  // Create a new Webform test node.
  $node = $this
    ->testWebformForm();

  // Visit the node page.
  $this
    ->drupalGet('node/' . $node->nid);
  foreach ($this
    ->testWebformComponents() as $key => $component_info) {
    if (isset($component_info['error values'])) {
      foreach ($component_info['error values'] as $value => $error_message) {
        $submission_values = array();
        $submission_values["submitted[{$key}]"] = $value;

        // Submit our test data.
        $this
          ->drupalPost('node/' . $node->nid, $submission_values, 'Submit', array(), array(), 'webform-client-form-' . $node->nid);

        // Confirm that the validation error occurred and the submission did not save.
        $this
          ->assertRaw($error_message, t('Validation message properly thrown: "%message".', array(
          '%message' => $error_message,
        )), t('Webform'));
        $this
          ->assertFalse(preg_match('/sid=([0-9]+)/', $this
          ->getUrl()), t('Submission not saved.'));
      }
    }
  }
}