1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Webform module tests.
|
5
|
*/
|
6
|
class WebformTestCase extends DrupalWebTestCase {
|
7
|
private $_webform_node;
|
8
|
private $_webform_components;
|
9
|
public $webform_users;
|
10
|
|
11
|
/**
|
12
|
* {@inheritdoc}
|
13
|
*/
|
14
|
public function setUp($added_modules = array()) {
|
15
|
// Enable Webform and Token module if available.
|
16
|
if (module_exists('token')) {
|
17
|
$modules = array('webform', 'token');
|
18
|
}
|
19
|
else {
|
20
|
$modules = array('webform');
|
21
|
}
|
22
|
parent::setUp(array_merge($modules, $added_modules));
|
23
|
|
24
|
// Create a profile field to test [user:?] tokens.
|
25
|
$field = array(
|
26
|
'field_name' => 'gender',
|
27
|
'type' => 'text',
|
28
|
'cardinality' => 1,
|
29
|
);
|
30
|
$instance = array(
|
31
|
'field_name' => 'gender',
|
32
|
'entity_type' => 'user',
|
33
|
'bundle' => 'user',
|
34
|
'label' => 'Gender',
|
35
|
'widget' => array(
|
36
|
'type' => 'text_textfield',
|
37
|
'label' => 'Gender',
|
38
|
),
|
39
|
);
|
40
|
field_create_field($field);
|
41
|
field_create_instance($instance);
|
42
|
|
43
|
// Create a normal user that can view their own submissions.
|
44
|
$permissions['userAccess'] = array(
|
45
|
'access content',
|
46
|
'access own webform submissions',
|
47
|
);
|
48
|
|
49
|
// Create a normal user than can edit their own submissions.
|
50
|
$permissions['userEdit'] = array(
|
51
|
'access content',
|
52
|
'edit own webform submissions',
|
53
|
);
|
54
|
|
55
|
// Create a webform editor to test creating and editing own content.
|
56
|
$permissions['editor'] = array(
|
57
|
'access content',
|
58
|
'create webform content',
|
59
|
'edit own webform content',
|
60
|
'access all webform results',
|
61
|
);
|
62
|
|
63
|
// Create a webform admin that will do all node creation.
|
64
|
$permissions['admin'] = array(
|
65
|
'access content',
|
66
|
'administer nodes',
|
67
|
'create webform content',
|
68
|
'edit any webform content',
|
69
|
'access all webform results',
|
70
|
'edit all webform submissions',
|
71
|
'delete all webform submissions',
|
72
|
);
|
73
|
|
74
|
foreach ($permissions as $user_key => $role_permissions) {
|
75
|
$this->webform_users[$user_key] = $this->drupalCreateUser($role_permissions);
|
76
|
$this->webform_users[$user_key]->gender = array(LANGUAGE_NONE => array(array('value' => 'Female')));
|
77
|
user_save($this->webform_users[$user_key]);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* {@inheritdoc}
|
83
|
*/
|
84
|
public function tearDown() {
|
85
|
// Delete the webform admin and any created nodes.
|
86
|
foreach ($this->webform_users as $account) {
|
87
|
$uid = $account->uid;
|
88
|
$result = db_select('node')
|
89
|
->fields('node')
|
90
|
->condition('uid', $uid)
|
91
|
->execute();
|
92
|
foreach ($result as $node) {
|
93
|
node_delete($node->nid);
|
94
|
}
|
95
|
user_cancel(array(), $uid, 'user_cancel_delete');
|
96
|
}
|
97
|
|
98
|
parent::tearDown();
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Reset the form.
|
103
|
*/
|
104
|
public function webformReset() {
|
105
|
$this->_webform_node = NULL;
|
106
|
$this->_webform_components = NULL;
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Provide a list of components to test throughout the suite.
|
111
|
*
|
112
|
* Each component provides:
|
113
|
* - A default configuration for the component.
|
114
|
* - Values to try setting via POST
|
115
|
* - Values that should match the database storage when set via POST
|
116
|
* - Values that should match the database storage when using the default
|
117
|
* values.
|
118
|
*
|
119
|
* @return array
|
120
|
* An array of each component settings.
|
121
|
*/
|
122
|
public function webformComponents() {
|
123
|
if (isset($this->_webform_components)) {
|
124
|
return $this->_webform_components;
|
125
|
}
|
126
|
|
127
|
$this->_webform_components = array(
|
128
|
// Test date components.
|
129
|
'date' => array(
|
130
|
'component' => array(
|
131
|
'form_key' => 'date',
|
132
|
'name' => 'Date',
|
133
|
'type' => 'date',
|
134
|
'value' => '19 Nov 1978',
|
135
|
'extra' => array(
|
136
|
'timezone' => 'site',
|
137
|
'start_date' => '-100 years',
|
138
|
'end_date' => '+2 years',
|
139
|
),
|
140
|
'required' => '0',
|
141
|
'pid' => '0',
|
142
|
'weight' => '-15',
|
143
|
),
|
144
|
'sample values' => array('day' => '30', 'month' => '9', 'year' => '1982'),
|
145
|
'database values' => array('1982-09-30'),
|
146
|
'database default values' => array('1978-11-19'),
|
147
|
// Conditionals match against the 'sample values'.
|
148
|
'match conditional values' => array(
|
149
|
'equal' => '1982/9/30',
|
150
|
'before' => '1982/10/1',
|
151
|
'before_equal' => '1982/9/30',
|
152
|
'after' => '1982/9/29',
|
153
|
'after_equal' => '1982/9/29',
|
154
|
),
|
155
|
'mismatch conditional values' => array(
|
156
|
'equal' => '1981/9/30',
|
157
|
'before' => '1982/9/30',
|
158
|
'before_equal' => '1982/9/29',
|
159
|
'after' => '1982/9/30',
|
160
|
'after_equal' => '1982/10/1',
|
161
|
),
|
162
|
),
|
163
|
|
164
|
// Test grid components.
|
165
|
'grid' => array(
|
166
|
'component' => array(
|
167
|
'form_key' => 'grid',
|
168
|
'name' => 'Grid',
|
169
|
'type' => 'grid',
|
170
|
'value' => '',
|
171
|
'extra' => array(
|
172
|
// Left side.
|
173
|
'questions' => "0|Ålphå\n1|ıé†å\n2|Î鬆å",
|
174
|
// Top.
|
175
|
'options' => "0|øne\n1|twö\n2|ǼBƇ\n3|€Euro",
|
176
|
),
|
177
|
'required' => '0',
|
178
|
'pid' => '2',
|
179
|
'weight' => '-19',
|
180
|
),
|
181
|
'sample values' => array('0' => '0', '1' => '1', '2' => '2'),
|
182
|
'database values' => array('0' => '0', '1' => '1', '2' => '2'),
|
183
|
'database default values' => array('', '', ''),
|
184
|
),
|
185
|
'grid_keyed' => array(
|
186
|
'component' => array(
|
187
|
'form_key' => 'grid_keyed',
|
188
|
'name' => 'Grid Keyed',
|
189
|
'type' => 'grid',
|
190
|
'value' => '',
|
191
|
'extra' => array(
|
192
|
// Left side.
|
193
|
'questions' => "one|What's your option?\ntwo|Agåin?\nthree|One more time!",
|
194
|
// Top.
|
195
|
'options' => "one|Option one\ntwo|Option 2\nthree| Three is me",
|
196
|
),
|
197
|
'required' => '0',
|
198
|
'pid' => '0',
|
199
|
'weight' => '-15',
|
200
|
),
|
201
|
'sample values' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
|
202
|
'database values' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
|
203
|
'database default values' => array('one' => '', 'two' => '', 'three' => ''),
|
204
|
),
|
205
|
|
206
|
// Test select components.
|
207
|
'checkboxes' => array(
|
208
|
'component' => array(
|
209
|
'form_key' => 'checkboxes',
|
210
|
'name' => 'Checkboxes',
|
211
|
'type' => 'select',
|
212
|
'value' => 'two',
|
213
|
'extra' => array(
|
214
|
'items' => "one|one\ntwo|two\nthree|three",
|
215
|
'multiple' => 1,
|
216
|
),
|
217
|
'required' => '0',
|
218
|
'pid' => '0',
|
219
|
'weight' => '-15',
|
220
|
),
|
221
|
'sample values' => array('one' => TRUE, 'two' => FALSE, 'three' => TRUE),
|
222
|
'database values' => array('one', 'three'),
|
223
|
'database default values' => array('two'),
|
224
|
// Conditionals match against the 'sample values'.
|
225
|
'match conditional values' => array(
|
226
|
// ANDed together match.
|
227
|
'equal' => array('one', 'three'),
|
228
|
'not_equal' => array('two'),
|
229
|
),
|
230
|
'mismatch conditional values' => array(
|
231
|
'equal' => array('one', 'two'),
|
232
|
'not_equal' => array('two', 'three'),
|
233
|
),
|
234
|
),
|
235
|
'checkboxes_zero' => array(
|
236
|
'component' => array(
|
237
|
'form_key' => 'checkboxes_zero',
|
238
|
'name' => 'Checkboxes zero',
|
239
|
'type' => 'select',
|
240
|
'value' => '0',
|
241
|
'extra' => array(
|
242
|
'items' => "0|zero\n1|one\n2|two",
|
243
|
'multiple' => 1,
|
244
|
),
|
245
|
'required' => '1',
|
246
|
'pid' => '0',
|
247
|
'weight' => '-9',
|
248
|
),
|
249
|
'sample values' => array('0' => TRUE),
|
250
|
'database values' => array('0'),
|
251
|
'database default values' => array('0'),
|
252
|
// Conditionals match against the 'sample values'.
|
253
|
'match conditional values' => array(
|
254
|
'equal' => '0',
|
255
|
'not_equal' => '1',
|
256
|
),
|
257
|
'mismatch conditional values' => array(
|
258
|
'equal' => '1',
|
259
|
'not_equal' => '0',
|
260
|
),
|
261
|
),
|
262
|
'radios' => array(
|
263
|
'component' => array(
|
264
|
'form_key' => 'radios',
|
265
|
'name' => 'Radios',
|
266
|
'type' => 'select',
|
267
|
'value' => 'two',
|
268
|
'extra' => array(
|
269
|
'items' => "one|one\ntwo|two\nthree|three",
|
270
|
),
|
271
|
'required' => '1',
|
272
|
'pid' => '0',
|
273
|
'weight' => '-9',
|
274
|
),
|
275
|
'sample values' => 'one',
|
276
|
'database values' => array('one'),
|
277
|
'database default values' => array('two'),
|
278
|
// Conditionals match against the 'sample values'.
|
279
|
'match conditional values' => array(
|
280
|
'equal' => 'one',
|
281
|
'not_equal' => 'two',
|
282
|
),
|
283
|
'mismatch conditional values' => array(
|
284
|
'equal' => 'two',
|
285
|
'not_equal' => 'one',
|
286
|
),
|
287
|
),
|
288
|
'radios_zero' => array(
|
289
|
'component' => array(
|
290
|
'form_key' => 'radios_zero',
|
291
|
'name' => 'Radios zero',
|
292
|
'type' => 'select',
|
293
|
'value' => '0',
|
294
|
'extra' => array(
|
295
|
'items' => "0|zero\n1|one\n2|two",
|
296
|
),
|
297
|
'required' => '1',
|
298
|
'pid' => '0',
|
299
|
'weight' => '-9',
|
300
|
),
|
301
|
'sample values' => '0',
|
302
|
'database values' => array('0'),
|
303
|
'database default values' => array('0'),
|
304
|
// Conditionals match against the 'sample values'.
|
305
|
'match conditional values' => array(
|
306
|
'equal' => '0',
|
307
|
'not_equal' => '1',
|
308
|
),
|
309
|
'mismatch conditional values' => array(
|
310
|
'equal' => '1',
|
311
|
'not_equal' => '0',
|
312
|
),
|
313
|
),
|
314
|
'radios_relative' => array(
|
315
|
'component' => array(
|
316
|
'form_key' => 'radios_relative',
|
317
|
'name' => 'Radios relative',
|
318
|
'type' => 'select',
|
319
|
'value' => 'one',
|
320
|
'extra' => array(
|
321
|
'items' => "zero|Zero\none|One\ntwo|Two\nthree|Three\n",
|
322
|
),
|
323
|
'required' => '1',
|
324
|
'pid' => '0',
|
325
|
'weight' => '-9',
|
326
|
),
|
327
|
'sample values' => 'one',
|
328
|
'database values' => array('one'),
|
329
|
'database default values' => array('one'),
|
330
|
// Conditionals match against the 'sample values'.
|
331
|
'match conditional values' => array(
|
332
|
'equal' => 'one',
|
333
|
'not_equal' => 'zero',
|
334
|
'less_than' => 'two',
|
335
|
'less_than_equal' => 'one',
|
336
|
'greater_than' => 'zero',
|
337
|
'greater_than_equal' => 'zero',
|
338
|
),
|
339
|
'mismatch conditional values' => array(
|
340
|
'equal' => 'zero',
|
341
|
'not_equal' => 'one',
|
342
|
'less_than' => 'one',
|
343
|
'less_than_equal' => 'zero',
|
344
|
'greater_than' => 'two',
|
345
|
'greater_than_equal' => 'two',
|
346
|
),
|
347
|
),
|
348
|
'select' => array(
|
349
|
'component' => array(
|
350
|
'form_key' => 'select',
|
351
|
'name' => 'Select',
|
352
|
'type' => 'select',
|
353
|
'value' => 'one',
|
354
|
'extra' => array(
|
355
|
'description' => 'Description here',
|
356
|
'items' => "one|one\ntwo|two\nthree|three\nfour|four\nfive|five\nsix|six",
|
357
|
'aslist' => 1,
|
358
|
),
|
359
|
'required' => '1',
|
360
|
'pid' => '0',
|
361
|
'weight' => '-15',
|
362
|
),
|
363
|
'sample values' => 'two',
|
364
|
'database values' => array('two'),
|
365
|
'database default values' => array('one'),
|
366
|
// Conditionals match against the 'sample values'.
|
367
|
'match conditional values' => array(
|
368
|
'equal' => 'two',
|
369
|
'not_equal' => 'one',
|
370
|
),
|
371
|
'mismatch conditional values' => array(
|
372
|
'equal' => 'one',
|
373
|
'not_equal' => 'two',
|
374
|
),
|
375
|
),
|
376
|
'select_zero' => array(
|
377
|
'component' => array(
|
378
|
'form_key' => 'select_zero',
|
379
|
'name' => 'Select zero',
|
380
|
'type' => 'select',
|
381
|
'value' => '0',
|
382
|
'extra' => array(
|
383
|
'description' => 'Tests saving zero as a value.',
|
384
|
'items' => "0|zero\n1|one\n2|two",
|
385
|
'aslist' => 1,
|
386
|
),
|
387
|
'required' => '1',
|
388
|
'pid' => '0',
|
389
|
'weight' => '-15',
|
390
|
),
|
391
|
'sample values' => '0',
|
392
|
'database values' => array('0'),
|
393
|
'database default values' => array('0'),
|
394
|
// Conditionals match against the 'sample values'.
|
395
|
'match conditional values' => array(
|
396
|
'equal' => '0',
|
397
|
'not_equal' => '1',
|
398
|
),
|
399
|
'mismatch conditional values' => array(
|
400
|
'equal' => '1',
|
401
|
'not_equal' => '0',
|
402
|
),
|
403
|
),
|
404
|
'select_no_default' => array(
|
405
|
'component' => array(
|
406
|
'form_key' => 'select_no_default',
|
407
|
'name' => 'Select no default',
|
408
|
'type' => 'select',
|
409
|
'value' => '',
|
410
|
'extra' => array(
|
411
|
'description' => 'Description here',
|
412
|
'items' => "one|one\ntwo|two\nthree|three\nfour|four\nfive|five\nsix|six",
|
413
|
'aslist' => 1,
|
414
|
),
|
415
|
'required' => '0',
|
416
|
'pid' => '0',
|
417
|
'weight' => '-15',
|
418
|
),
|
419
|
'sample values' => 'two',
|
420
|
'database values' => array('two'),
|
421
|
'database default values' => array(''),
|
422
|
// Conditionals match against the 'sample values'.
|
423
|
'match conditional values' => array(
|
424
|
'equal' => 'two',
|
425
|
'not_equal' => '',
|
426
|
),
|
427
|
'mismatch conditional values' => array(
|
428
|
'equal' => '',
|
429
|
'not_equal' => 'two',
|
430
|
),
|
431
|
),
|
432
|
'select_no_default_zero' => array(
|
433
|
'component' => array(
|
434
|
'form_key' => 'select_no_default_zero',
|
435
|
'name' => 'Select no default zero',
|
436
|
'type' => 'select',
|
437
|
'value' => '',
|
438
|
'extra' => array(
|
439
|
'description' => 'Tests saving zero as a value.',
|
440
|
'items' => "0|zero\n1|one\n2|two",
|
441
|
'aslist' => 1,
|
442
|
),
|
443
|
'required' => '0',
|
444
|
'pid' => '0',
|
445
|
'weight' => '-15',
|
446
|
),
|
447
|
'sample values' => '0',
|
448
|
'database values' => array('0'),
|
449
|
'database default values' => array(''),
|
450
|
// Conditionals match against the 'sample values'.
|
451
|
'match conditional values' => array(
|
452
|
'equal' => '0',
|
453
|
'not_equal' => '',
|
454
|
),
|
455
|
'mismatch conditional values' => array(
|
456
|
'equal' => '',
|
457
|
'not_equal' => '0',
|
458
|
),
|
459
|
),
|
460
|
'select_optgroup' => array(
|
461
|
'component' => array(
|
462
|
'form_key' => 'select_optgroup',
|
463
|
'name' => 'Select Optgroup',
|
464
|
'type' => 'select',
|
465
|
'value' => 'option 1-2',
|
466
|
'extra' => array(
|
467
|
'description' => 'Tests saving zero as a value.',
|
468
|
'items' => "<Group 1>\noption 1-1|option 1-1\noption 1-2|option 1-2\noption 1-3|option 1-3\n<Group 2>\noption 2-1|option 2-1\noption 2-2|option 2-2\noption 2-3|option 2-3",
|
469
|
'aslist' => 1,
|
470
|
),
|
471
|
'required' => '1',
|
472
|
'pid' => '0',
|
473
|
'weight' => '-15',
|
474
|
),
|
475
|
'sample values' => 'option 2-2',
|
476
|
'database values' => array('option 2-2'),
|
477
|
'database default values' => array('option 1-2'),
|
478
|
),
|
479
|
'select_email' => array(
|
480
|
'component' => array(
|
481
|
'form_key' => 'select_email',
|
482
|
'name' => 'Select e-mails',
|
483
|
'type' => 'select',
|
484
|
'value' => 'nate@localhost.localhost',
|
485
|
'extra' => array(
|
486
|
'items' => "nate@localhost.localhost|one\nadmin@localhost.localhost|two",
|
487
|
),
|
488
|
'required' => '0',
|
489
|
'pid' => '2',
|
490
|
'weight' => '-17',
|
491
|
),
|
492
|
'sample values' => 'admin@localhost.localhost',
|
493
|
'database values' => array('admin@localhost.localhost'),
|
494
|
'database default values' => array('nate@localhost.localhost'),
|
495
|
),
|
496
|
'select_multiple' => array(
|
497
|
'component' => array(
|
498
|
'form_key' => 'select_multiple',
|
499
|
'name' => 'Select Multiple',
|
500
|
'type' => 'select',
|
501
|
'value' => 'one,two',
|
502
|
'extra' => array(
|
503
|
'items' => "one|one\ntwo|two\nthree|three",
|
504
|
'multiple' => 1,
|
505
|
'aslist' => 1,
|
506
|
),
|
507
|
'required' => '0',
|
508
|
'pid' => '0',
|
509
|
'weight' => '-10',
|
510
|
),
|
511
|
// @todo: I'd like to test a value, but SimpleTest can't set multiple values.
|
512
|
'sample values' => NULL,
|
513
|
'database values' => array('one', 'two'),
|
514
|
'database default values' => array('one', 'two'),
|
515
|
),
|
516
|
'select_relative' => array(
|
517
|
'component' => array(
|
518
|
'form_key' => 'select_relative',
|
519
|
'name' => 'Select relative',
|
520
|
'type' => 'select',
|
521
|
'value' => 'one',
|
522
|
'extra' => array(
|
523
|
'items' => "zero|Zero\none|One\ntwo|Two\nthree|Three\n",
|
524
|
'aslist' => 1,
|
525
|
),
|
526
|
'required' => '1',
|
527
|
'pid' => '0',
|
528
|
'weight' => '-9',
|
529
|
),
|
530
|
'sample values' => 'one',
|
531
|
'database values' => array('one'),
|
532
|
'database default values' => array('one'),
|
533
|
// Conditionals match against the 'sample values'.
|
534
|
'match conditional values' => array(
|
535
|
'equal' => 'one',
|
536
|
'not_equal' => 'zero',
|
537
|
'less_than' => 'two',
|
538
|
'less_than_equal' => 'one',
|
539
|
'greater_than' => 'zero',
|
540
|
'greater_than_equal' => 'zero',
|
541
|
),
|
542
|
'mismatch conditional values' => array(
|
543
|
'equal' => 'zero',
|
544
|
'not_equal' => 'one',
|
545
|
'less_than' => 'one',
|
546
|
'less_than_equal' => 'zero',
|
547
|
'greater_than' => 'two',
|
548
|
'greater_than_equal' => 'two',
|
549
|
),
|
550
|
),
|
551
|
|
552
|
// Test date components.
|
553
|
'date_textfield' => array(
|
554
|
'component' => array(
|
555
|
'form_key' => 'date_textfield',
|
556
|
'name' => 'Date Textfield',
|
557
|
'type' => 'date',
|
558
|
'value' => 'Nov 19 1978',
|
559
|
'extra' => array(
|
560
|
'timezone' => 'site',
|
561
|
'start_date' => '-100 years',
|
562
|
'end_date' => '+2 years',
|
563
|
'year_textfield' => 1,
|
564
|
),
|
565
|
'required' => '1',
|
566
|
'pid' => '0',
|
567
|
'weight' => '-7',
|
568
|
),
|
569
|
'sample values' => array('day' => '30', 'month' => '9', 'year' => '1982'),
|
570
|
'database values' => array('1982-09-30'),
|
571
|
'database default values' => array('1978-11-19'),
|
572
|
// Conditionals match against the 'sample values'.
|
573
|
'match conditional values' => array(
|
574
|
'equal' => '1982/9/30',
|
575
|
'before' => '1982/10/1',
|
576
|
'before_equal' => '1982/9/30',
|
577
|
'after' => '1982/9/29',
|
578
|
'after_equal' => '1982/9/29',
|
579
|
),
|
580
|
'mismatch conditional values' => array(
|
581
|
'equal' => '1981/9/30',
|
582
|
'before' => '1982/9/30',
|
583
|
'before_equal' => '1982/9/29',
|
584
|
'after' => '1982/9/30',
|
585
|
'after_equal' => '1982/10/1',
|
586
|
),
|
587
|
),
|
588
|
|
589
|
// Test email components.
|
590
|
'email' => array(
|
591
|
'component' => array(
|
592
|
'form_key' => 'email',
|
593
|
'name' => 'E-mail',
|
594
|
'type' => 'email',
|
595
|
'value' => '[current-user:mail]',
|
596
|
'required' => '0',
|
597
|
'extra' => array(
|
598
|
// SimpleTest does not support type="email" input fields.
|
599
|
'attributes' => array('type' => 'text'),
|
600
|
),
|
601
|
'pid' => '0',
|
602
|
'weight' => '-5',
|
603
|
),
|
604
|
'sample values' => 'admin@localhost.localhost',
|
605
|
'database values' => array('admin@localhost.localhost'),
|
606
|
'database default values' => array($this->webform_users['admin']->mail),
|
607
|
// Conditionals match against the 'sample values'.
|
608
|
'match conditional values' => array(
|
609
|
'equal' => 'admin@localhost.localhost',
|
610
|
'not_equal' => '',
|
611
|
'contains' => 'admin',
|
612
|
'does_not_contain' => 'foo',
|
613
|
'begins_with' => 'admin',
|
614
|
'ends_with' => 'localhost',
|
615
|
'not_empty' => TRUE,
|
616
|
),
|
617
|
'mismatch conditional values' => array(
|
618
|
'equal' => 'foo@localhost.localhost',
|
619
|
'not_equal' => 'admin@localhost.localhost',
|
620
|
'contains' => 'foo',
|
621
|
'does_not_contain' => 'admin',
|
622
|
'begins_with' => 'localhost',
|
623
|
'ends_with' => 'admin',
|
624
|
'empty' => TRUE,
|
625
|
),
|
626
|
),
|
627
|
|
628
|
// Test hidden components.
|
629
|
'hidden' => array(
|
630
|
'component' => array(
|
631
|
'form_key' => 'hidden',
|
632
|
'name' => 'Hidden',
|
633
|
'type' => 'hidden',
|
634
|
'value' => 'default hidden value',
|
635
|
'required' => '1',
|
636
|
'pid' => '0',
|
637
|
'weight' => '-4',
|
638
|
),
|
639
|
'sample values' => NULL,
|
640
|
'database values' => array('default hidden value'),
|
641
|
'database default values' => array('default hidden value'),
|
642
|
// Conditionals match against the 'sample values'.
|
643
|
'match conditional values' => array(
|
644
|
'equal' => 'default hidden value',
|
645
|
'not_equal' => '',
|
646
|
'contains' => 'hidden',
|
647
|
'does_not_contain' => 'foo',
|
648
|
'begins_with' => 'default',
|
649
|
'ends_with' => 'value',
|
650
|
'not_empty' => TRUE,
|
651
|
),
|
652
|
'mismatch conditional values' => array(
|
653
|
'equal' => '',
|
654
|
'not_equal' => 'default hidden value',
|
655
|
'contains' => 'foo',
|
656
|
'does_not_contain' => 'hidden',
|
657
|
'begins_with' => 'value',
|
658
|
'ends_with' => 'default',
|
659
|
'empty' => TRUE,
|
660
|
),
|
661
|
),
|
662
|
|
663
|
// Test textarea components.
|
664
|
'textarea' => array(
|
665
|
'component' => array(
|
666
|
'form_key' => 'textarea',
|
667
|
'name' => 'Textarea',
|
668
|
'type' => 'textarea',
|
669
|
'value' => 'sample textarea default value',
|
670
|
'extra' => array(),
|
671
|
'required' => '0',
|
672
|
'pid' => '0',
|
673
|
'weight' => '15',
|
674
|
),
|
675
|
'sample values' => 'sample textarea value',
|
676
|
'database values' => array('sample textarea value'),
|
677
|
'database default values' => array('sample textarea default value'),
|
678
|
// Conditionals match against the 'sample values'.
|
679
|
'match conditional values' => array(
|
680
|
'equal' => 'sample textarea value',
|
681
|
'not_equal' => '',
|
682
|
'contains' => 'sample',
|
683
|
'does_not_contain' => 'foo',
|
684
|
'begins_with' => 'sample',
|
685
|
'ends_with' => 'value',
|
686
|
'not_empty' => TRUE,
|
687
|
),
|
688
|
'mismatch conditional values' => array(
|
689
|
'equal' => '',
|
690
|
'not_equal' => 'sample textarea value',
|
691
|
'contains' => 'foo',
|
692
|
'does_not_contain' => 'sample',
|
693
|
'begins_with' => 'value',
|
694
|
'ends_with' => 'sample',
|
695
|
'empty' => TRUE,
|
696
|
),
|
697
|
),
|
698
|
|
699
|
// Test textfield components.
|
700
|
'textfield' => array(
|
701
|
'component' => array(
|
702
|
'form_key' => 'textfield',
|
703
|
'name' => 'Textfield',
|
704
|
'type' => 'textfield',
|
705
|
'value' => '',
|
706
|
'required' => '0',
|
707
|
'pid' => '0',
|
708
|
'weight' => '-14',
|
709
|
),
|
710
|
'sample values' => '',
|
711
|
'database values' => array(''),
|
712
|
'database default values' => array(''),
|
713
|
),
|
714
|
'textfield_disabled' => array(
|
715
|
'component' => array(
|
716
|
'form_key' => 'textfield_disabled',
|
717
|
'name' => 'Textfield Disabled',
|
718
|
'type' => 'textfield',
|
719
|
'value' => '[current-page:query:foo]',
|
720
|
'extra' => array(
|
721
|
'disabled' => 1,
|
722
|
),
|
723
|
'required' => '0',
|
724
|
'pid' => '0',
|
725
|
'weight' => '-15',
|
726
|
),
|
727
|
// Manually hard-code the input if token is not available.
|
728
|
// @todo: Update after http://drupal.org/node/1347790 is finished.
|
729
|
'sample values' => module_exists('token') ? NULL : 'bar',
|
730
|
'database values' => array('bar'),
|
731
|
'database default values' => module_exists('token') ? array('bar') : array(''),
|
732
|
),
|
733
|
'textfield_profile' => array(
|
734
|
'component' => array(
|
735
|
'form_key' => 'textfield_profile',
|
736
|
'name' => 'Textfield Profile',
|
737
|
'type' => 'textfield',
|
738
|
'value' => '[current-user:gender]',
|
739
|
'extra' => array(
|
740
|
'width' => '20',
|
741
|
),
|
742
|
'required' => '0',
|
743
|
'pid' => '0',
|
744
|
'weight' => '-6',
|
745
|
),
|
746
|
'sample values' => 'Female',
|
747
|
'database values' => array('Female'),
|
748
|
// The default value will be blank if token does not exist.
|
749
|
// @todo: Update after http://drupal.org/node/1347790 is finished.
|
750
|
'database default values' => module_exists('token') ? array($this->webform_users['admin']->gender[LANGUAGE_NONE][0]['value']) : array(''),
|
751
|
),
|
752
|
|
753
|
// Test time components.
|
754
|
'time' => array(
|
755
|
'component' => array(
|
756
|
'form_key' => 'time',
|
757
|
'name' => 'Time',
|
758
|
'type' => 'time',
|
759
|
'value' => '10:30pm',
|
760
|
'extra' => array(
|
761
|
'timezone' => 'site',
|
762
|
'hourformat' => '12-hour',
|
763
|
),
|
764
|
'required' => '0',
|
765
|
'pid' => '0',
|
766
|
'weight' => '16',
|
767
|
),
|
768
|
'sample values' => array('hour' => '12', 'minute' => '0', 'ampm' => 'pm'),
|
769
|
'database values' => array('12:00:00'),
|
770
|
'database default values' => array('22:30:00'),
|
771
|
// Conditionals match against the 'sample values'.
|
772
|
'match conditional values' => array(
|
773
|
'equal' => '12:00pm',
|
774
|
'before' => '1:00pm',
|
775
|
'before_equal' => '12:00pm',
|
776
|
'after' => '11:00am',
|
777
|
'after_equal' => '11:00am',
|
778
|
),
|
779
|
'mismatch conditional values' => array(
|
780
|
'equal' => '12:00am',
|
781
|
'before' => '12:00pm',
|
782
|
'before_equal' => '11:00am',
|
783
|
'after' => '12:00pm',
|
784
|
),
|
785
|
),
|
786
|
'time_24h' => array(
|
787
|
'component' => array(
|
788
|
'form_key' => 'time_24h',
|
789
|
'name' => 'Time 24H',
|
790
|
'type' => 'time',
|
791
|
'value' => '10:30pm',
|
792
|
'extra' => array(
|
793
|
'timezone' => 'site',
|
794
|
'hourformat' => '24-hour',
|
795
|
),
|
796
|
'required' => '0',
|
797
|
'pid' => '0',
|
798
|
'weight' => '17',
|
799
|
),
|
800
|
'sample values' => array('hour' => '5', 'minute' => '0'),
|
801
|
'database values' => array('05:00:00'),
|
802
|
'database default values' => array('22:30:00'),
|
803
|
// Conditionals match against the 'sample values'.
|
804
|
'match conditional values' => array(
|
805
|
'equal' => '5:00',
|
806
|
'before' => '24:00',
|
807
|
'before_equal' => '5:00',
|
808
|
'after' => '00:00',
|
809
|
'after_equal' => '00:00',
|
810
|
),
|
811
|
'mismatch conditional values' => array(
|
812
|
'equal' => '5:01',
|
813
|
'before' => '5:00',
|
814
|
'before_equal' => '4:59',
|
815
|
'after' => '5:00',
|
816
|
'after_equal' => '5:01',
|
817
|
),
|
818
|
),
|
819
|
|
820
|
// Test number components.
|
821
|
'integer' => array(
|
822
|
'component' => array(
|
823
|
'form_key' => 'integer',
|
824
|
'name' => 'Integer',
|
825
|
'type' => 'number',
|
826
|
'value' => '1',
|
827
|
'extra' => array(
|
828
|
'type' => 'textfield',
|
829
|
'integer' => 1,
|
830
|
'max' => '100',
|
831
|
// SimpleTest does not support type="number" input fields.
|
832
|
'attributes' => array('type' => 'text'),
|
833
|
),
|
834
|
'required' => '0',
|
835
|
'pid' => '0',
|
836
|
'weight' => '18',
|
837
|
),
|
838
|
'sample values' => '2',
|
839
|
'database values' => array('2'),
|
840
|
'database default values' => array('1'),
|
841
|
// Conditionals match against the 'sample values'.
|
842
|
'match conditional values' => array(
|
843
|
'equal' => '2',
|
844
|
'not_equal' => '0',
|
845
|
'less_than' => '3',
|
846
|
'less_than_equal' => '2',
|
847
|
'greater_than' => '1',
|
848
|
'greater_than_equal' => '1',
|
849
|
'not_empty' => TRUE,
|
850
|
),
|
851
|
'mismatch conditional values' => array(
|
852
|
'equal' => '0',
|
853
|
'not_equal' => '2',
|
854
|
'less_than' => '2',
|
855
|
'less_than_equal' => '1',
|
856
|
'greater_than' => '2',
|
857
|
'greater_than_equal' => '3',
|
858
|
'empty' => TRUE,
|
859
|
),
|
860
|
'error values' => array(
|
861
|
'1.5' => t('!name field value of @value must be an integer.', array('!name' => 'Integer', '@value' => '1.5')),
|
862
|
'101' => t('!name field value must be less than @max.', array('!name' => 'Integer', '@max' => '100')),
|
863
|
),
|
864
|
),
|
865
|
'integer_range' => array(
|
866
|
'component' => array(
|
867
|
'form_key' => 'integer_range',
|
868
|
'name' => 'Integer Range',
|
869
|
'type' => 'number',
|
870
|
'value' => '50',
|
871
|
'extra' => array(
|
872
|
'type' => 'select',
|
873
|
'min' => '10',
|
874
|
'max' => '50',
|
875
|
'step' => 5,
|
876
|
'integer' => 1,
|
877
|
),
|
878
|
'required' => '0',
|
879
|
'pid' => '0',
|
880
|
'weight' => '19',
|
881
|
),
|
882
|
'sample values' => '10',
|
883
|
'database values' => array('10'),
|
884
|
'database default values' => array('50'),
|
885
|
),
|
886
|
'decimal_positive' => array(
|
887
|
'component' => array(
|
888
|
'form_key' => 'decimal_positive',
|
889
|
'name' => 'Decimal positive',
|
890
|
'type' => 'number',
|
891
|
'value' => '1',
|
892
|
'extra' => array(
|
893
|
'type' => 'textfield',
|
894
|
'field_prefix' => '$',
|
895
|
'field_suffix' => 'lbs',
|
896
|
'min' => '0',
|
897
|
'decimals' => '2',
|
898
|
'point' => '.',
|
899
|
'separator' => ',',
|
900
|
// SimpleTest does not support type="number" input fields.
|
901
|
'attributes' => array('type' => 'text'),
|
902
|
),
|
903
|
'required' => '0',
|
904
|
'pid' => '0',
|
905
|
'weight' => '20',
|
906
|
),
|
907
|
'sample values' => '2.00',
|
908
|
'database values' => array('2.00'),
|
909
|
'database default values' => array('1'),
|
910
|
// Conditionals match against the 'sample values'.
|
911
|
'match conditional values' => array(
|
912
|
'equal' => '2',
|
913
|
'not_equal' => '0',
|
914
|
'less_than' => '3.000',
|
915
|
'greater_than' => '1.000',
|
916
|
'not_empty' => TRUE,
|
917
|
),
|
918
|
'mismatch conditional values' => array(
|
919
|
'equal' => '0',
|
920
|
'not_equal' => '2',
|
921
|
'less_than' => '2.0',
|
922
|
'greater_than' => '2.00',
|
923
|
'empty' => TRUE,
|
924
|
),
|
925
|
'error values' => array(
|
926
|
'-1' => t('!name field value must be greater than @min.', array('!name' => 'Decimal positive', '@min' => '0')),
|
927
|
),
|
928
|
),
|
929
|
'decimal_range' => array(
|
930
|
'component' => array(
|
931
|
'form_key' => 'decimal_range',
|
932
|
'name' => 'Decimal range',
|
933
|
'type' => 'number',
|
934
|
'value' => '1',
|
935
|
'extra' => array(
|
936
|
'type' => 'textfield',
|
937
|
'field_prefix' => '$',
|
938
|
'field_suffix' => 'lbs',
|
939
|
'min' => '1',
|
940
|
'max' => '12',
|
941
|
'step' => '1.5',
|
942
|
// SimpleTest does not support type="number" input fields.
|
943
|
'attributes' => array('type' => 'text'),
|
944
|
),
|
945
|
'required' => '0',
|
946
|
'pid' => '0',
|
947
|
'weight' => '21',
|
948
|
),
|
949
|
'sample values' => '11.5',
|
950
|
'database values' => array('11.5'),
|
951
|
'database default values' => array('1'),
|
952
|
'error values' => array(
|
953
|
'2' => t('!name field value must be @start plus a multiple of @step.', array('!name' => 'Decimal range', '@start' => '1', '@step' => '1.5')),
|
954
|
'13' => t('!name field value of @value should be in the range @min to @max.', array('!name' => 'Decimal range', '@value' => '13', '@min' => '1', '@max' => '12')),
|
955
|
),
|
956
|
),
|
957
|
'decimal_range_select' => array(
|
958
|
'component' => array(
|
959
|
'form_key' => 'decimal_range_select',
|
960
|
'name' => 'Decimal range select',
|
961
|
'type' => 'number',
|
962
|
'value' => '1',
|
963
|
'extra' => array(
|
964
|
'type' => 'select',
|
965
|
'field_prefix' => '$',
|
966
|
'field_suffix' => 'lbs',
|
967
|
'min' => '1',
|
968
|
'max' => '12',
|
969
|
'step' => '1.5',
|
970
|
),
|
971
|
'required' => '0',
|
972
|
'pid' => '0',
|
973
|
'weight' => '21',
|
974
|
),
|
975
|
'sample values' => '10',
|
976
|
'database values' => array('10'),
|
977
|
'database default values' => array('1'),
|
978
|
// Conditionals match against the 'sample values'.
|
979
|
'match conditional values' => array(
|
980
|
'equal' => '10',
|
981
|
'not_equal' => '2.5',
|
982
|
'less_than' => '11.5',
|
983
|
'greater_than' => '1',
|
984
|
),
|
985
|
'mismatch conditional values' => array(
|
986
|
'equal' => '2.5',
|
987
|
'not_equal' => '10',
|
988
|
'less_than' => '10',
|
989
|
'greater_than' => '11.5',
|
990
|
),
|
991
|
),
|
992
|
);
|
993
|
|
994
|
return $this->_webform_components;
|
995
|
}
|
996
|
|
997
|
/**
|
998
|
* Create a sample Webform node.
|
999
|
*/
|
1000
|
public function webformForm() {
|
1001
|
if (isset($this->_webform_node)) {
|
1002
|
return $this->_webform_node;
|
1003
|
}
|
1004
|
|
1005
|
$settings = array(
|
1006
|
'type' => 'webform',
|
1007
|
'language' => LANGUAGE_NONE,
|
1008
|
'uid' => '1',
|
1009
|
'status' => '1',
|
1010
|
'promote' => '1',
|
1011
|
'moderate' => '0',
|
1012
|
'sticky' => '0',
|
1013
|
'tnid' => '0',
|
1014
|
'translate' => '0',
|
1015
|
'title' => 'Test Webform',
|
1016
|
'log' => '',
|
1017
|
'format' => '1',
|
1018
|
'webform' => array(
|
1019
|
'confirmation' => 'Thanks!',
|
1020
|
) + webform_node_defaults(),
|
1021
|
);
|
1022
|
|
1023
|
$cid = 0;
|
1024
|
foreach ($this->webformComponents() as $key => $component_info) {
|
1025
|
$cid++;
|
1026
|
$settings['webform']['components'][$cid] = $component_info['component'];
|
1027
|
$settings['webform']['components'][$cid]['cid'] = $cid;
|
1028
|
$settings['webform']['components'][$cid]['pid'] = 0;
|
1029
|
}
|
1030
|
|
1031
|
$this->_webform_node = $this->drupalCreateNode($settings);
|
1032
|
|
1033
|
return $this->_webform_node;
|
1034
|
}
|
1035
|
|
1036
|
/**
|
1037
|
* Generate a list of all values that would result in a valid submission.
|
1038
|
*
|
1039
|
* @param $input_values
|
1040
|
* An array of input values keyed by the component form key. If none
|
1041
|
* are specified, the defaults will be pulled from webformComponents().
|
1042
|
*/
|
1043
|
public function webformPost($input_values = NULL) {
|
1044
|
$edit = array();
|
1045
|
|
1046
|
if (empty($input_values)) {
|
1047
|
$input_values = array();
|
1048
|
foreach ($this->webformComponents() as $key => $component_info) {
|
1049
|
$input_values[$key] = $component_info['sample values'];
|
1050
|
}
|
1051
|
}
|
1052
|
|
1053
|
foreach ($input_values as $key => $values) {
|
1054
|
if (is_array($values)) {
|
1055
|
foreach ($values as $subkey => $value) {
|
1056
|
$edit["submitted[$key][$subkey]"] = $value;
|
1057
|
}
|
1058
|
}
|
1059
|
elseif ($values != NULL) {
|
1060
|
$value = $values;
|
1061
|
// Multiple selects have a funky extra empty bracket in the name.
|
1062
|
$extra = $key == 'select_multiple' ? '[]' : '';
|
1063
|
$edit["submitted[$key]$extra"] = $value;
|
1064
|
}
|
1065
|
}
|
1066
|
return $edit;
|
1067
|
}
|
1068
|
|
1069
|
/**
|
1070
|
* Utility function to print out the current page being tested.
|
1071
|
*/
|
1072
|
public function webformPrintPage() {
|
1073
|
$this->verbose($this->drupalGetContent());
|
1074
|
}
|
1075
|
|
1076
|
}
|