function WebformSubmissionTestCase::webformSubmissionExecute in Webform 6.2
Same name and namespace in other branches
- 6.3 tests/submission.test \WebformSubmissionTestCase::webformSubmissionExecute()
- 7.4 tests/WebformSubmissionTestCase.test \WebformSubmissionTestCase::webformSubmissionExecute()
- 7.3 tests/submission.test \WebformSubmissionTestCase::webformSubmissionExecute()
Execute the submission test.
Parameters
$value_type: The values to be submitted to the webform. Either "sample" or "default".
2 calls to WebformSubmissionTestCase::webformSubmissionExecute()
- WebformSubmissionTestCase::testWebformSubmission in tests/
submission.test - Test sending a submission and check database integrity.
- WebformSubmissionTestCase::testWebformSubmissionDefault in tests/
submission.test
File
- tests/
submission.test, line 59
Class
Code
function webformSubmissionExecute($value_type = 'sample') {
$path = drupal_get_path('module', 'webform');
module_load_include('inc', 'webform', 'webform_submissions');
// Create a new Webform test node.
$node = $this
->testWebformForm();
$submission_values = $value_type == 'sample' ? $this
->testWebformPost() : array();
// Visit the node page with the "foo=bar" query, to test %get[] default values.
$this
->drupalGet('node/' . $node->nid, array(
'query' => 'foo=bar',
));
$this
->assertText($node->body, t('Webform node created and accessible at !url', array(
'!url' => 'node/' . $node->nid,
)), t('Webform'));
// Submit our test data.
$this
->drupalPost(NULL, $submission_values, 'Submit');
// 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 = $matches[1];
// Pull in the database submission and check the values.
$actual_submission = (array) webform_get_submission($node->nid, $sid, TRUE);
$component_info = $this
->testWebformComponents();
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 = $actual_submission['data'][$cid]['value'];
$result = $this
->assertEqual($stable_value, $actual_value, t('Component @form_key data integrity check', array(
'@form_key' => $component['form_key'],
)), t('Webform'));
if (!$result || $result === 'fail') {
$this
->fail(t('Expected !expected', array(
'!expected' => print_r($stable_value, TRUE),
)) . "\n\n" . t('Recieved !recieved', array(
'!recieved' => print_r($actual_value, TRUE),
)), t('Webform'));
}
}
}