You are here

public function WebformSubmissionTestCase::webformSubmissionExecute in Webform 7.4

Same name and namespace in other branches
  1. 6.3 tests/submission.test \WebformSubmissionTestCase::webformSubmissionExecute()
  2. 6.2 tests/submission.test \WebformSubmissionTestCase::webformSubmissionExecute()
  3. 7.3 tests/submission.test \WebformSubmissionTestCase::webformSubmissionExecute()

Execute the submission test.

Parameters

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

bool $save_draft: Whether to save a draft or a final submission.

array $webform_settings: Settings to use for this form. Any unspecific settings will be default.

3 calls to WebformSubmissionTestCase::webformSubmissionExecute()
WebformSubmissionTestCase::testWebformSubmission in tests/WebformSubmissionTestCase.test
Test sending a submission and check database integrity.
WebformSubmissionTestCase::testWebformSubmissionDefault in tests/WebformSubmissionTestCase.test
Test a submission that uses default values, and check database integrity.
WebformSubmissionTestCase::testWebformSubmissionDownload in tests/WebformSubmissionTestCase.test
Test that the correct submissions are offered for download.

File

tests/WebformSubmissionTestCase.test, line 312

Class

WebformSubmissionTestCase
Webform module submission tests.

Code

public function webformSubmissionExecute($value_type = 'sample', $save_draft = FALSE, array $webform_settings = array()) {
  $path = drupal_get_path('module', 'webform');
  module_load_include('inc', 'webform', 'includes/webform.submissions');

  // Create a new Webform test node.
  $node = $this
    ->webformForm($webform_settings);
  $submission_values = $value_type == 'sample' ? $this
    ->webformPost() : array();

  // Visit the node page with the "foo=bar" query, to test
  // [current-page:query:?] default values.
  $this
    ->drupalGet('node/' . $node->nid, array(
    'query' => array(
      'foo' => 'bar',
    ),
  ));
  $this
    ->assertText($node->title, t('Webform node created and accessible at !url', array(
    '!url' => 'node/' . $node->nid,
  )), t('Webform'));

  // Submit our test data.
  $this
    ->drupalPost(NULL, $submission_values, $save_draft ? 'Save Draft' : 'Submit', array(), array(), 'webform-client-form-' . $node->nid);
  if ($save_draft) {
    $this
      ->assertText(t('Submission saved. You may return to this form later and it will restore the current values.'), t('Save draft message displayed.'), t('Webform'));
    return;
  }

  // Confirm that the submission has been created.
  $this
    ->assertText($node->webform['confirmation'], t('Confirmation message "@confirmation" received.', array(
    '@confirmation' => $node->webform['confirmation'],
  )), t('Webform'));

  // Get the SID of the new submission.
  $matches = array();
  preg_match('/sid=([0-9]+)/', $this
    ->getUrl(), $matches);
  $sid = isset($matches[1]) ? $matches[1] : NULL;

  // Pull in the database submission and check the values.
  drupal_static_reset('webform_get_submission');
  $actual_submission = webform_get_submission($node->nid, $sid);
  $component_info = $this
    ->webformComponents();
  foreach ($node->webform['components'] as $cid => $component) {
    $stable_value = $value_type == 'sample' ? $component_info[$component['form_key']]['database values'] : $component_info[$component['form_key']]['database default values'];
    $actual_value = isset($actual_submission->data[$cid]) ? $actual_submission->data[$cid] : NULL;
    $result = $this
      ->assertEqual($stable_value, $actual_value, t('Component @form_key data integrity check when using @type values.', array(
      '@form_key' => $component['form_key'],
      '@type' => $value_type,
    )), t('Webform'));
    if (!$result || $result === 'fail') {
      $this
        ->fail(t("Expected !expected\n\nRecieved !recieved", array(
        '!expected' => print_r($stable_value, TRUE),
        '!recieved' => print_r($actual_value, TRUE),
      )), t('Webform'));
    }
  }
}