| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id$ 3 4 /** 5 * @file 6 * Webform module submission tests. 7 */ 8 9 include_once(dirname(__FILE__) . '/webform.test'); 10 11 class WebformSubmissionTestCase extends WebformTestCase { 12 /** 13 * Implementation of getInfo(). 14 */ 15 public static function getInfo() { 16 return array( 17 'name' => t('Webform submission'), 18 'description' => t('Submits a sample webform and checks the database integrity.'), 19 'group' => t('Webform'), 20 ); 21 } 22 23 /** 24 * Implementation of setUp(). 25 */ 26 function setUp() { 27 parent::setUp(); 28 } 29 30 /** 31 * Implementation of tearDown(). 32 */ 33 function tearDown() { 34 parent::tearDown(); 35 } 36 37 /** 38 * Test sending a submission and check database integrity. 39 */ 40 function testWebformSubmission() { 41 $this->drupalLogin($this->webform_users['admin']); 42 $this->webformReset(); 43 $this->webformSubmissionExecute('sample'); 44 $this->drupalLogout(); 45 } 46 47 function testWebformSubmissionDefault() { 48 $this->drupalLogin($this->webform_users['admin']); 49 $this->webformReset(); 50 $this->webformSubmissionExecute('default'); 51 $this->drupalLogout(); 52 } 53 54 /** 55 * Execute the submission test. 56 * 57 * @param $value_type 58 * The values to be submitted to the webform. Either "sample" or "default". 59 */ 60 function webformSubmissionExecute($value_type = 'sample') { 61 $path = drupal_get_path('module', 'webform'); 62 module_load_include('inc', 'webform', 'includes/webform.submissions'); 63 64 // Create a new Webform test node. 65 $node = $this->testWebformForm(); 66 $submission_values = $value_type == 'sample' ? $this->testWebformPost() : array(); 67 68 // Visit the node page with the "foo=bar" query, to test %get[] default values. 69 $this->drupalGet('node/' . $node->nid, array('query' => 'foo=bar')); 70 $this->assertText($node->body, t('Webform node created and accessible at !url', array('!url' => 'node/' . $node->nid)), t('Webform')); 71 72 // Submit our test data. 73 $this->drupalPost(NULL, $submission_values, 'Submit'); 74 75 // Confirm that the submission has been created. 76 $this->assertText($node->webform['confirmation'], t('Confirmation message "@confirmation" received.', array('@confirmation' => $node->webform['confirmation'])), t('Webform')); 77 78 // Get the SID of the new submission. 79 $matches = array(); 80 preg_match('/sid=([0-9]+)/', $this->getUrl(), $matches); 81 $sid = $matches[1]; 82 83 // Pull in the database submission and check the values. 84 $actual_submission = webform_get_submission($node->nid, $sid, TRUE); 85 86 $component_info = $this->testWebformComponents(); 87 foreach ($node->webform['components'] as $cid => $component) { 88 $stable_value = $value_type == 'sample' ? $component_info[$component['form_key']]['database values'] : $component_info[$component['form_key']]['database default values']; 89 $actual_value = $actual_submission->data[$cid]['value']; 90 $result = $this->assertEqual($stable_value, $actual_value, t('Component @form_key data integrity check', array('@form_key' => $component['form_key'])), t('Webform')); 91 if (!$result || $result === 'fail') { 92 $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')); 93 } 94 } 95 } 96 97 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |