View source
<?php
include_once dirname(__FILE__) . '/webform.test';
class WebformSubmissionTestCase extends WebformTestCase {
public static function getInfo() {
return array(
'name' => t('Webform submission'),
'description' => t('Submits a sample webform and checks the database integrity.'),
'group' => t('Webform'),
);
}
function setUp() {
parent::setUp();
}
function tearDown() {
parent::tearDown();
}
function testWebformSubmission() {
$this
->drupalLogin($this->webform_users['admin']);
$this
->webformReset();
$this
->webformSubmissionExecute('sample');
$this
->drupalLogout();
}
function testWebformSubmissionDefault() {
$this
->drupalLogin($this->webform_users['admin']);
$this
->webformReset();
$this
->webformSubmissionExecute('default');
$this
->drupalLogout();
}
function webformSubmissionExecute($value_type = 'sample') {
$path = drupal_get_path('module', 'webform');
module_load_include('inc', 'webform', 'webform_submissions');
$node = $this
->testWebformForm();
$submission_values = $value_type == 'sample' ? $this
->testWebformPost() : array();
$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'));
$this
->drupalPost(NULL, $submission_values, 'Submit');
$this
->assertText($node->webform['confirmation'], t('Confirmation message "@confirmation" received.', array(
'@confirmation' => $node->webform['confirmation'],
)), t('Webform'));
$matches = array();
preg_match('/sid=([0-9]+)/', $this
->getUrl(), $matches);
$sid = $matches[1];
$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'));
}
}
}
}