Révision 7b2d1845
Ajouté par Assos Assos il y a presque 4 ans
drupal7/sites/all/modules/webform/tests/WebformSubmissionTestCase.test | ||
---|---|---|
29 | 29 |
$this->drupalLogout(); |
30 | 30 |
|
31 | 31 |
// Test webform_get_submission_count(). |
32 |
// Counting the anonymous submission doesn't work because |
|
33 |
// $_SESSION['webform_submission'] is not populated in testing. |
|
32 | 34 |
$this->webformSubmissionExecute('sample'); |
33 | 35 |
|
34 | 36 |
$count = webform_get_submission_count($this->webformForm()->nid); |
... | ... | |
37 | 39 |
$count = webform_get_submission_count($this->webformForm()->nid, $loggedInUser->uid); |
38 | 40 |
$this->assertIdentical((int) $count, 1, 'webform_get_submission_count() counts 1 submission from loggedInUser.'); |
39 | 41 |
|
40 |
// Counting the anonymous submission doesn't work because |
|
41 |
// $_SESSION['webform_submission'] is not populated in testing. |
|
42 |
|
|
43 | 42 |
// Test _webform_submission_prepare_mail(). |
44 | 43 |
$node = node_load($this->webformForm()->nid); |
45 | 44 |
$submission = webform_get_submissions($node->nid); |
... | ... | |
61 | 60 |
$this->assertIdentical($prepared_email['mail_params']['email']['from'], '"from@example.com via Default \'From\' Name" <default-from@example.com>', 'From address is correctly set in _webform_submission_prepare_mail().'); |
62 | 61 |
} |
63 | 62 |
|
63 |
/** |
|
64 |
* Test that the correct submissions are offered for download. |
|
65 |
*/ |
|
66 |
public function testWebformSubmissionDownload() { |
|
67 |
$this->drupalLogin($this->webform_users['userAccess']); |
|
68 |
$this->webformReset(); |
|
69 |
|
|
70 |
// Create Webform which allows drafts and submit a draft. |
|
71 |
$webform_settings = array( |
|
72 |
'allow_draft' => '1', |
|
73 |
); |
|
74 |
$this->webformSubmissionExecute('sample', TRUE, $webform_settings); |
|
75 |
|
|
76 |
$nid = $this->webformForm()->nid; |
|
77 |
|
|
78 |
// This submit should complete the draft. |
|
79 |
$this->webformSubmissionExecute('sample'); |
|
80 |
// Create another draft. |
|
81 |
$this->webformSubmissionExecute('sample', TRUE); |
|
82 |
|
|
83 |
// Create finished and draft submission as another user. |
|
84 |
$this->drupalLogin($this->webform_users['editor']); |
|
85 |
$this->webformSubmissionExecute('sample'); |
|
86 |
$this->webformSubmissionExecute('sample', TRUE); |
|
87 |
|
|
88 |
// Create finished submission as anonymous. |
|
89 |
$this->drupalLogout(); |
|
90 |
$this->webformSubmissionExecute('sample'); |
|
91 |
$this->drupalLogin($this->webform_users['editor']); |
|
92 |
|
|
93 |
// Test webform_download_sids(). |
|
94 |
$sids = webform_download_sids($nid, array('range_type' => 'new', 'completion_type' => 'finished'), (int) $this->webform_users['editor']->uid); |
|
95 |
$this->assertIdentical($sids, array('1', '3', '5'), 'webform_download_sids() shows correct finished submissions.'); |
|
96 |
$sids = webform_download_sids($nid, array('range_type' => 'new', 'completion_type' => 'draft'), (int) $this->webform_users['editor']->uid); |
|
97 |
$this->assertIdentical($sids, array('2', '4'), 'webform_download_sids() shows correct draft submissions.'); |
|
98 |
|
|
99 |
// The timestamp of the Webform results download simulated by the call to |
|
100 |
// webform_update_webform_last_download() needs to be after the timestamps |
|
101 |
// of the submissions made above. This ensures that the call to time() will |
|
102 |
// be after the submission timestamps. |
|
103 |
sleep(1); |
|
104 |
|
|
105 |
// Record that submissions so-far have been downloaded. |
|
106 |
// Parameter $sid is not used, so it's value doesn't matter. |
|
107 |
webform_update_webform_last_download($this->webformForm(), (int) $this->webform_users['editor']->uid, 0, time()); |
|
108 |
|
|
109 |
// Following the simulated download, there are none to download. |
|
110 |
$sids = webform_download_sids($nid, array('range_type' => 'new', 'completion_type' => 'finished'), (int) $this->webform_users['editor']->uid); |
|
111 |
$this->assertIdentical($sids, array(), 'webform_download_sids() shows correct finished submissions.'); |
|
112 |
$sids = webform_download_sids($nid, array('range_type' => 'new', 'completion_type' => 'draft'), (int) $this->webform_users['editor']->uid); |
|
113 |
$this->assertIdentical($sids, array(), 'webform_download_sids() shows correct draft submissions.'); |
|
114 |
|
|
115 |
// Finish the draft, add a new draft, and re-check submission lists. |
|
116 |
$this->webformSubmissionExecute('sample'); |
|
117 |
$this->webformSubmissionExecute('sample', TRUE); |
|
118 |
$sids = webform_download_sids($nid, array('range_type' => 'new', 'completion_type' => 'finished'), (int) $this->webform_users['editor']->uid); |
|
119 |
$this->assertIdentical($sids, array('4'), 'webform_download_sids() shows correct finished submissions.'); |
|
120 |
$sids = webform_download_sids($nid, array('range_type' => 'new', 'completion_type' => 'draft'), (int) $this->webform_users['editor']->uid); |
|
121 |
$this->assertIdentical($sids, array('6'), 'webform_download_sids() shows correct draft submissions.'); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Test Webform submission utility functions. |
|
126 |
* |
|
127 |
* Test webform_update_webform_last_download() and |
|
128 |
* webform_download_last_download_info(). |
|
129 |
*/ |
|
130 |
public function testWebformSubmissionFunctions() { |
|
131 |
$node = (object) array('nid' => 1); |
|
132 |
$uid = 1; |
|
133 |
|
|
134 |
$result = webform_update_webform_last_download($node, $uid, 10, 1000); |
|
135 |
$this->assertIdentical($result, MergeQuery::STATUS_INSERT, 'webform_update_webform_last_download() reports successful insert.'); |
|
136 |
$result = webform_download_last_download_info($node->nid, $uid); |
|
137 |
$test = array( |
|
138 |
'nid' => '1', |
|
139 |
'uid' => '1', |
|
140 |
'sid' => '10', |
|
141 |
'requested' => '1000', |
|
142 |
'serial' => NULL, |
|
143 |
); |
|
144 |
$this->assertIdentical($result, $test, 'webform_download_last_download_info() returned correct result.'); |
|
145 |
|
|
146 |
$result = webform_update_webform_last_download($node, $uid, 20, 2000); |
|
147 |
$this->assertIdentical($result, MergeQuery::STATUS_UPDATE, 'webform_update_webform_last_download() reports successful update.'); |
|
148 |
$result = webform_download_last_download_info($node->nid, $uid); |
|
149 |
$test = array( |
|
150 |
'nid' => '1', |
|
151 |
'uid' => '1', |
|
152 |
'sid' => '20', |
|
153 |
'requested' => '2000', |
|
154 |
'serial' => NULL, |
|
155 |
); |
|
156 |
$this->assertIdentical($result, $test, 'webform_download_last_download_info() returned correct result.'); |
|
157 |
} |
|
158 |
|
|
64 | 159 |
/** |
65 | 160 |
* Test a submission that uses default values, and check database integrity. |
66 | 161 |
*/ |
... | ... | |
151 | 246 |
$this->assertNoPattern('/ cannot be (longer|shorter) than /'); |
152 | 247 |
} |
153 | 248 |
|
249 |
/** |
|
250 |
* Test webform_submission_data() function. |
|
251 |
* |
|
252 |
* Do not save components that do not collect data, for example, markup. |
|
253 |
*/ |
|
254 |
public function testPlainComponentsSubmission() { |
|
255 |
$node = (object) [ |
|
256 |
'webform' => [ |
|
257 |
'components' => [ |
|
258 |
['type' => 'date'], |
|
259 |
['type' => 'email'], |
|
260 |
['type' => 'grid'], |
|
261 |
['type' => 'hidden'], |
|
262 |
['type' => 'number'], |
|
263 |
['type' => 'select'], |
|
264 |
['type' => 'textarea'], |
|
265 |
['type' => 'textfield'], |
|
266 |
['type' => 'time'], |
|
267 |
['type' => 'fieldset'], |
|
268 |
['type' => 'markup'], |
|
269 |
['type' => 'pagebreak'], |
|
270 |
], |
|
271 |
], |
|
272 |
]; |
|
273 |
$submitted = [ |
|
274 |
'date', |
|
275 |
'email', |
|
276 |
['value' => 'grid'], |
|
277 |
'hidden', |
|
278 |
'number', |
|
279 |
'select', |
|
280 |
'textarea', |
|
281 |
'textfield', |
|
282 |
'time', |
|
283 |
'fieldset', |
|
284 |
'markup', |
|
285 |
'pagebreak', |
|
286 |
]; |
|
287 |
$test_data = webform_submission_data($node, $submitted); |
|
288 |
$sample_data = [ |
|
289 |
['date'], |
|
290 |
['email'], |
|
291 |
['value' => 'grid'], |
|
292 |
['hidden'], |
|
293 |
['number'], |
|
294 |
['select'], |
|
295 |
['textarea'], |
|
296 |
['textfield'], |
|
297 |
['time'], |
|
298 |
]; |
|
299 |
$this->assertIdentical($test_data, $sample_data, 'webform_submission_data() generates correct data array.'); |
|
300 |
} |
|
301 |
|
|
154 | 302 |
/** |
155 | 303 |
* Execute the submission test. |
156 | 304 |
* |
157 | 305 |
* @param string $value_type |
158 | 306 |
* The values to be submitted to the webform. Either "sample" or "default". |
307 |
* @param bool $save_draft |
|
308 |
* Whether to save a draft or a final submission. |
|
309 |
* @param array $webform_settings |
|
310 |
* Settings to use for this form. Any unspecific settings will be default. |
|
159 | 311 |
*/ |
160 |
public function webformSubmissionExecute($value_type = 'sample') { |
|
312 |
public function webformSubmissionExecute($value_type = 'sample', $save_draft = FALSE, array $webform_settings = array()) {
|
|
161 | 313 |
$path = drupal_get_path('module', 'webform'); |
162 | 314 |
module_load_include('inc', 'webform', 'includes/webform.submissions'); |
163 | 315 |
|
164 | 316 |
// Create a new Webform test node. |
165 |
$node = $this->webformForm(); |
|
317 |
$node = $this->webformForm($webform_settings);
|
|
166 | 318 |
$submission_values = $value_type == 'sample' ? $this->webformPost() : array(); |
167 | 319 |
|
168 | 320 |
// Visit the node page with the "foo=bar" query, to test |
... | ... | |
171 | 323 |
$this->assertText($node->title, t('Webform node created and accessible at !url', array('!url' => 'node/' . $node->nid)), t('Webform')); |
172 | 324 |
|
173 | 325 |
// Submit our test data. |
174 |
$this->drupalPost(NULL, $submission_values, 'Submit', array(), array(), 'webform-client-form-' . $node->nid); |
|
326 |
$this->drupalPost(NULL, $submission_values, $save_draft ? 'Save Draft' : 'Submit', array(), array(), 'webform-client-form-' . $node->nid); |
|
327 |
|
|
328 |
if ($save_draft) { |
|
329 |
$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')); |
|
330 |
return; |
|
331 |
} |
|
175 | 332 |
|
176 | 333 |
// Confirm that the submission has been created. |
177 | 334 |
$this->assertText($node->webform['confirmation'], t('Confirmation message "@confirmation" received.', array('@confirmation' => $node->webform['confirmation'])), t('Webform')); |
Formats disponibles : Unified diff
Weekly update of contrib modules