Projet

Général

Profil

Paste
Télécharger (33,7 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / tests / WebformTestCase.test @ 8d02775b

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 modules.
16
    $modules = array('webform', 'token');
17
    parent::setUp(array_merge($modules, $added_modules));
18

    
19
    // Create a profile field to test [user:?] tokens.
20
    $field = array(
21
      'field_name' => 'gender',
22
      'type' => 'text',
23
      'cardinality' => 1,
24
    );
25
    $instance = array(
26
      'field_name' => 'gender',
27
      'entity_type' => 'user',
28
      'bundle' => 'user',
29
      'label' => 'Gender',
30
      'widget' => array(
31
        'type' => 'text_textfield',
32
        'label' => 'Gender',
33
      ),
34
    );
35
    field_create_field($field);
36
    field_create_instance($instance);
37

    
38
    // Create a normal user that can view their own submissions.
39
    $permissions['userAccess'] = array(
40
      'access content',
41
      'access own webform submissions',
42
    );
43

    
44
    // Create a normal user than can edit their own submissions.
45
    $permissions['userEdit'] = array(
46
      'access content',
47
      'edit own webform submissions',
48
    );
49

    
50
    // Create a webform editor to test creating and editing own content.
51
    $permissions['editor'] = array(
52
      'access content',
53
      'create webform content',
54
      'edit own webform content',
55
      'access all webform results',
56
    );
57

    
58
    // Create a webform admin that will do all node creation.
59
    $permissions['admin'] = array(
60
      'access content',
61
      'administer nodes',
62
      'create webform content',
63
      'edit any webform content',
64
      'access all webform results',
65
      'edit all webform submissions',
66
      'delete all webform submissions',
67
    );
68

    
69
    foreach ($permissions as $user_key => $role_permissions) {
70
      $this->webform_users[$user_key] = $this->drupalCreateUser($role_permissions);
71
      $this->webform_users[$user_key]->gender = array(LANGUAGE_NONE => array(array('value' => 'Female')));
72
      user_save($this->webform_users[$user_key]);
73
    }
74
  }
75

    
76
  /**
77
   * {@inheritdoc}
78
   */
79
  public function tearDown() {
80
    // Delete the webform admin and any created nodes.
81
    foreach ($this->webform_users as $account) {
82
      $uid = $account->uid;
83
      $result = db_select('node')
84
        ->fields('node')
85
        ->condition('uid', $uid)
86
        ->execute();
87
      foreach ($result as $node) {
88
        node_delete($node->nid);
89
      }
90
      user_cancel(array(), $uid, 'user_cancel_delete');
91
    }
92

    
93
    parent::tearDown();
94
  }
95

    
96
  /**
97
   * Reset the form.
98
   */
99
  public function webformReset() {
100
    $this->_webform_node = NULL;
101
    $this->_webform_components = NULL;
102
  }
103

    
104
  /**
105
   * Provide a list of components to test throughout the suite.
106
   *
107
   * Each component provides:
108
   *   - A default configuration for the component.
109
   *   - Values to try setting via POST
110
   *   - Values that should match the database storage when set via POST
111
   *   - Values that should match the database storage when using the default
112
   *     values.
113
   *
114
   * @return array
115
   *   An array of each component settings.
116
   */
117
  public function webformComponents() {
118
    if (isset($this->_webform_components)) {
119
      return $this->_webform_components;
120
    }
121

    
122
    $this->_webform_components = array(
123
      // Test date components.
124
      'date' => array(
125
        'component' => array(
126
          'form_key' => 'date',
127
          'name' => 'Date',
128
          'type' => 'date',
129
          'value' => '19 Nov 1978',
130
          'extra' => array(
131
            'timezone' => 'site',
132
            'start_date' => '-100 years',
133
            'end_date' => '+2 years',
134
          ),
135
          'required' => '0',
136
          'pid' => '0',
137
          'weight' => '-15',
138
        ),
139
        'sample values' => array('day' => '30', 'month' => '9', 'year' => '1982'),
140
        'database values' => array('1982-09-30'),
141
        'database default values' => array('1978-11-19'),
142
        // Conditionals match against the 'sample values'.
143
        'match conditional values' => array(
144
          'equal' => '1982/9/30',
145
          'before' => '1982/10/1',
146
          'before_equal' => '1982/9/30',
147
          'after' => '1982/9/29',
148
          'after_equal' => '1982/9/29',
149
        ),
150
        'mismatch conditional values' => array(
151
          'equal' => '1981/9/30',
152
          'before' => '1982/9/30',
153
          'before_equal' => '1982/9/29',
154
          'after' => '1982/9/30',
155
          'after_equal' => '1982/10/1',
156
        ),
157
      ),
158

    
159
      // Test grid components.
160
      'grid' => array(
161
        'component' => array(
162
          'form_key' => 'grid',
163
          'name' => 'Grid',
164
          'type' => 'grid',
165
          'value' => '',
166
          'extra' => array(
167
            // Left side.
168
            'questions' => "0|Ålphå\n1|ıé†å\n2|Î鬆å",
169
            // Top.
170
            'options' => "0|øne\n1|twö\n2|ǼBƇ\n3|€Euro",
171
          ),
172
          'required' => '0',
173
          'pid' => '2',
174
          'weight' => '-19',
175
        ),
176
        'sample values' => array('0' => '0', '1' => '1', '2' => '2'),
177
        'database values' => array('0' => '0', '1' => '1', '2' => '2'),
178
        'database default values' => array('', '', ''),
179
      ),
180
      'grid_keyed' => array(
181
        'component' => array(
182
          'form_key' => 'grid_keyed',
183
          'name' => 'Grid Keyed',
184
          'type' => 'grid',
185
          'value' => '',
186
          'extra' => array(
187
            // Left side.
188
            'questions' => "one|What's your option?\ntwo|Agåin?|Again, right text\nthree|One more time!",
189
            // Top.
190
            'options' => "one|Option one\ntwo|Option 2\nthree| Three is me",
191
            'title_display' => 'internal',
192
          ),
193
          'required' => '0',
194
          'pid' => '0',
195
          'weight' => '-15',
196
        ),
197
        'sample values' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
198
        'database values' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
199
        'database default values' => array('one' => '', 'two' => '', 'three' => ''),
200
      ),
201

    
202
      // Test select components.
203
      'checkboxes' => array(
204
        'component' => array(
205
          'form_key' => 'checkboxes',
206
          'name' => 'Checkboxes',
207
          'type' => 'select',
208
          'value' => 'two',
209
          'extra' => array(
210
            'items' => "one|one\ntwo|two\nthree|three",
211
            'multiple' => 1,
212
          ),
213
          'required' => '0',
214
          'pid' => '0',
215
          'weight' => '-15',
216
        ),
217
        'sample values' => array('one' => TRUE, 'two' => FALSE, 'three' => TRUE),
218
        'database values' => array('one', 'three'),
219
        'database default values' => array('two'),
220
        // Conditionals match against the 'sample values'.
221
        'match conditional values' => array(
222
          // ANDed together match.
223
          'equal' => array('one', 'three'),
224
          'not_equal' => array('two'),
225
        ),
226
        'mismatch conditional values' => array(
227
          'equal' => array('one', 'two'),
228
          'not_equal' => array('two', 'three'),
229
        ),
230
      ),
231
      'checkboxes_zero' => array(
232
        'component' => array(
233
          'form_key' => 'checkboxes_zero',
234
          'name' => 'Checkboxes zero',
235
          'type' => 'select',
236
          'value' => '0',
237
          'extra' => array(
238
            'items' => "0|zero\n1|one\n2|two",
239
            'multiple' => 1,
240
          ),
241
          'required' => '1',
242
          'pid' => '0',
243
          'weight' => '-9',
244
        ),
245
        'sample values' => array('0' => TRUE),
246
        'database values' => array('0'),
247
        'database default values' => array('0'),
248
        // Conditionals match against the 'sample values'.
249
        'match conditional values' => array(
250
          'equal' => '0',
251
          'not_equal' => '1',
252
        ),
253
        'mismatch conditional values' => array(
254
          'equal' => '1',
255
          'not_equal' => '0',
256
        ),
257
      ),
258
      'radios' => array(
259
        'component' => array(
260
          'form_key' => 'radios',
261
          'name' => 'Radios',
262
          'type' => 'select',
263
          'value' => 'two',
264
          'extra' => array(
265
            'items' => "one|one\ntwo|two\nthree|three",
266
          ),
267
          'required' => '1',
268
          'pid' => '0',
269
          'weight' => '-9',
270
        ),
271
        'sample values' => 'one',
272
        'database values' => array('one'),
273
        'database default values' => array('two'),
274
        // Conditionals match against the 'sample values'.
275
        'match conditional values' => array(
276
          'equal' => 'one',
277
          'not_equal' => 'two',
278
        ),
279
        'mismatch conditional values' => array(
280
          'equal' => 'two',
281
          'not_equal' => 'one',
282
        ),
283
      ),
284
      'radios_zero' => array(
285
        'component' => array(
286
          'form_key' => 'radios_zero',
287
          'name' => 'Radios zero',
288
          'type' => 'select',
289
          'value' => '0',
290
          'extra' => array(
291
            'items' => "0|zero\n1|one\n2|two",
292
          ),
293
          'required' => '1',
294
          'pid' => '0',
295
          'weight' => '-9',
296
        ),
297
        'sample values' => '0',
298
        'database values' => array('0'),
299
        'database default values' => array('0'),
300
        // Conditionals match against the 'sample values'.
301
        'match conditional values' => array(
302
          'equal' => '0',
303
          'not_equal' => '1',
304
        ),
305
        'mismatch conditional values' => array(
306
          'equal' => '1',
307
          'not_equal' => '0',
308
        ),
309
      ),
310
      'radios_relative' => array(
311
        'component' => array(
312
          'form_key' => 'radios_relative',
313
          'name' => 'Radios relative',
314
          'type' => 'select',
315
          'value' => 'one',
316
          'extra' => array(
317
            'items' => "zero|Zero\none|One\ntwo|Two\nthree|Three\n",
318
          ),
319
          'required' => '1',
320
          'pid' => '0',
321
          'weight' => '-9',
322
        ),
323
        'sample values' => 'one',
324
        'database values' => array('one'),
325
        'database default values' => array('one'),
326
        // Conditionals match against the 'sample values'.
327
        'match conditional values' => array(
328
          'equal' => 'one',
329
          'not_equal' => 'zero',
330
          'less_than' => 'two',
331
          'less_than_equal' => 'one',
332
          'greater_than' => 'zero',
333
          'greater_than_equal' => 'zero',
334
        ),
335
        'mismatch conditional values' => array(
336
          'equal' => 'zero',
337
          'not_equal' => 'one',
338
          'less_than' => 'one',
339
          'less_than_equal' => 'zero',
340
          'greater_than' => 'two',
341
          'greater_than_equal' => 'two',
342
        ),
343
      ),
344
      'select' => array(
345
        'component' => array(
346
          'form_key' => 'select',
347
          'name' => 'Select',
348
          'type' => 'select',
349
          'value' => 'one',
350
          'extra' => array(
351
            'description' => 'Description here',
352
            'items' => "one|one\ntwo|two\nthree|three\nfour|four\nfive|five\nsix|six",
353
            'aslist' => 1,
354
          ),
355
          'required' => '1',
356
          'pid' => '0',
357
          'weight' => '-15',
358
        ),
359
        'sample values' => 'two',
360
        'database values' => array('two'),
361
        'database default values' => array('one'),
362
        // Conditionals match against the 'sample values'.
363
        'match conditional values' => array(
364
          'equal' => 'two',
365
          'not_equal' => 'one',
366
        ),
367
        'mismatch conditional values' => array(
368
          'equal' => 'one',
369
          'not_equal' => 'two',
370
        ),
371
      ),
372
      'select_zero' => array(
373
        'component' => array(
374
          'form_key' => 'select_zero',
375
          'name' => 'Select zero',
376
          'type' => 'select',
377
          'value' => '0',
378
          'extra' => array(
379
            'description' => 'Tests saving zero as a value.',
380
            'items' => "0|zero\n1|one\n2|two",
381
            'aslist' => 1,
382
          ),
383
          'required' => '1',
384
          'pid' => '0',
385
          'weight' => '-15',
386
        ),
387
        'sample values' => '0',
388
        'database values' => array('0'),
389
        'database default values' => array('0'),
390
        // Conditionals match against the 'sample values'.
391
        'match conditional values' => array(
392
          'equal' => '0',
393
          'not_equal' => '1',
394
        ),
395
        'mismatch conditional values' => array(
396
          'equal' => '1',
397
          'not_equal' => '0',
398
        ),
399
      ),
400
      'select_no_default' => array(
401
        'component' => array(
402
          'form_key' => 'select_no_default',
403
          'name' => 'Select no default',
404
          'type' => 'select',
405
          'value' => '',
406
          'extra' => array(
407
            'description' => 'Description here',
408
            'items' => "one|one\ntwo|two\nthree|three\nfour|four\nfive|five\nsix|six",
409
            'aslist' => 1,
410
          ),
411
          'required' => '0',
412
          'pid' => '0',
413
          'weight' => '-15',
414
        ),
415
        'sample values' => 'two',
416
        'database values' => array('two'),
417
        'database default values' => array(''),
418
        // Conditionals match against the 'sample values'.
419
        'match conditional values' => array(
420
          'equal' => 'two',
421
          'not_equal' => '',
422
        ),
423
        'mismatch conditional values' => array(
424
          'equal' => '',
425
          'not_equal' => 'two',
426
        ),
427
      ),
428
      'select_no_default_zero' => array(
429
        'component' => array(
430
          'form_key' => 'select_no_default_zero',
431
          'name' => 'Select no default zero',
432
          'type' => 'select',
433
          'value' => '',
434
          'extra' => array(
435
            'description' => 'Tests saving zero as a value.',
436
            'items' => "0|zero\n1|one\n2|two",
437
            'aslist' => 1,
438
          ),
439
          'required' => '0',
440
          'pid' => '0',
441
          'weight' => '-15',
442
        ),
443
        'sample values' => '0',
444
        'database values' => array('0'),
445
        'database default values' => array(''),
446
        // Conditionals match against the 'sample values'.
447
        'match conditional values' => array(
448
          'equal' => '0',
449
          'not_equal' => '',
450
        ),
451
        'mismatch conditional values' => array(
452
          'equal' => '',
453
          'not_equal' => '0',
454
        ),
455
      ),
456
      'select_optgroup' => array(
457
        'component' => array(
458
          'form_key' => 'select_optgroup',
459
          'name' => 'Select Optgroup',
460
          'type' => 'select',
461
          'value' => 'option 1-2',
462
          'extra' => array(
463
            'description' => 'Tests saving zero as a value.',
464
            '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",
465
            'aslist' => 1,
466
          ),
467
          'required' => '1',
468
          'pid' => '0',
469
          'weight' => '-15',
470
        ),
471
        'sample values' => 'option 2-2',
472
        'database values' => array('option 2-2'),
473
        'database default values' => array('option 1-2'),
474
      ),
475
      'select_email' => array(
476
        'component' => array(
477
          'form_key' => 'select_email',
478
          'name' => 'Select e-mails',
479
          'type' => 'select',
480
          'value' => 'nate@localhost.localhost',
481
          'extra' => array(
482
            'items' => "nate@localhost.localhost|one\nadmin@localhost.localhost|two",
483
          ),
484
          'required' => '0',
485
          'pid' => '2',
486
          'weight' => '-17',
487
        ),
488
        'sample values' => 'admin@localhost.localhost',
489
        'database values' => array('admin@localhost.localhost'),
490
        'database default values' => array('nate@localhost.localhost'),
491
      ),
492
      'select_multiple' => array(
493
        'component' => array(
494
          'form_key' => 'select_multiple',
495
          'name' => 'Select Multiple',
496
          'type' => 'select',
497
          'value' => 'one,two',
498
          'extra' => array(
499
            'items' => "one|one\ntwo|two\nthree|three",
500
            'multiple' => 1,
501
            'aslist' => 1,
502
          ),
503
          'required' => '0',
504
          'pid' => '0',
505
          'weight' => '-10',
506
        ),
507
        // @todo: I'd like to test a value, but SimpleTest can't set multiple values.
508
        'sample values' => NULL,
509
        'database values' => array('one', 'two'),
510
        'database default values' => array('one', 'two'),
511
      ),
512
      'select_relative' => array(
513
        'component' => array(
514
          'form_key' => 'select_relative',
515
          'name' => 'Select relative',
516
          'type' => 'select',
517
          'value' => 'one',
518
          'extra' => array(
519
            'items' => "zero|Zero\none|One\ntwo|Two\nthree|Three\n",
520
            'aslist' => 1,
521
          ),
522
          'required' => '1',
523
          'pid' => '0',
524
          'weight' => '-9',
525
        ),
526
        'sample values' => 'one',
527
        'database values' => array('one'),
528
        'database default values' => array('one'),
529
        // Conditionals match against the 'sample values'.
530
        'match conditional values' => array(
531
          'equal' => 'one',
532
          'not_equal' => 'zero',
533
          'less_than' => 'two',
534
          'less_than_equal' => 'one',
535
          'greater_than' => 'zero',
536
          'greater_than_equal' => 'zero',
537
        ),
538
        'mismatch conditional values' => array(
539
          'equal' => 'zero',
540
          'not_equal' => 'one',
541
          'less_than' => 'one',
542
          'less_than_equal' => 'zero',
543
          'greater_than' => 'two',
544
          'greater_than_equal' => 'two',
545
        ),
546
      ),
547

    
548
      // Test date components.
549
      'date_textfield' => array(
550
        'component' => array(
551
          'form_key' => 'date_textfield',
552
          'name' => 'Date Textfield',
553
          'type' => 'date',
554
          'value' => 'Nov 19 1978',
555
          'extra' => array(
556
            'timezone' => 'site',
557
            'start_date' => '-100 years',
558
            'end_date' => '+2 years',
559
            'year_textfield' => 1,
560
          ),
561
          'required' => '1',
562
          'pid' => '0',
563
          'weight' => '-7',
564
        ),
565
        'sample values' => array('day' => '30', 'month' => '9', 'year' => '1982'),
566
        'database values' => array('1982-09-30'),
567
        'database default values' => array('1978-11-19'),
568
        // Conditionals match against the 'sample values'.
569
        'match conditional values' => array(
570
          'equal' => '1982/9/30',
571
          'before' => '1982/10/1',
572
          'before_equal' => '1982/9/30',
573
          'after' => '1982/9/29',
574
          'after_equal' => '1982/9/29',
575
        ),
576
        'mismatch conditional values' => array(
577
          'equal' => '1981/9/30',
578
          'before' => '1982/9/30',
579
          'before_equal' => '1982/9/29',
580
          'after' => '1982/9/30',
581
          'after_equal' => '1982/10/1',
582
        ),
583
      ),
584

    
585
      // Test email components.
586
      'email' => array(
587
        'component' => array(
588
          'form_key' => 'email',
589
          'name' => 'E-mail',
590
          'type' => 'email',
591
          'value' => '[current-user:mail]',
592
          'required' => '0',
593
          'extra' => array(
594
            // SimpleTest does not support type="email" input fields.
595
            'attributes' => array('type' => 'text'),
596
          ),
597
          'pid' => '0',
598
          'weight' => '-5',
599
        ),
600
        'sample values' => 'admin@localhost.localhost',
601
        'database values' => array('admin@localhost.localhost'),
602
        'database default values' => array($this->webform_users['admin']->mail),
603
        // Conditionals match against the 'sample values'.
604
        'match conditional values' => array(
605
          'equal' => 'admin@localhost.localhost',
606
          'not_equal' => '',
607
          'contains' => 'admin',
608
          'does_not_contain' => 'foo',
609
          'begins_with' => 'admin',
610
          'ends_with' => 'localhost',
611
          'not_empty' => TRUE,
612
        ),
613
        'mismatch conditional values' => array(
614
          'equal' => 'foo@localhost.localhost',
615
          'not_equal' => 'admin@localhost.localhost',
616
          'contains' => 'foo',
617
          'does_not_contain' => 'admin',
618
          'begins_with' => 'localhost',
619
          'ends_with' => 'admin',
620
          'empty' => TRUE,
621
        ),
622
      ),
623

    
624
      // Test hidden components.
625
      'hidden' => array(
626
        'component' => array(
627
          'form_key' => 'hidden',
628
          'name' => 'Hidden',
629
          'type' => 'hidden',
630
          'value' => 'default hidden value',
631
          'required' => '1',
632
          'pid' => '0',
633
          'weight' => '-4',
634
        ),
635
        'sample values' => NULL,
636
        'database values' => array('default hidden value'),
637
        'database default values' => array('default hidden value'),
638
        // Conditionals match against the 'sample values'.
639
        'match conditional values' => array(
640
          'equal' => 'default hidden value',
641
          'not_equal' => '',
642
          'contains' => 'hidden',
643
          'does_not_contain' => 'foo',
644
          'begins_with' => 'default',
645
          'ends_with' => 'value',
646
          'not_empty' => TRUE,
647
        ),
648
        'mismatch conditional values' => array(
649
          'equal' => '',
650
          'not_equal' => 'default hidden value',
651
          'contains' => 'foo',
652
          'does_not_contain' => 'hidden',
653
          'begins_with' => 'value',
654
          'ends_with' => 'default',
655
          'empty' => TRUE,
656
        ),
657
      ),
658

    
659
      // Test textarea components.
660
      'textarea' => array(
661
        'component' => array(
662
          'form_key' => 'textarea',
663
          'name' => 'Textarea',
664
          'type' => 'textarea',
665
          'value' => 'sample textarea default value',
666
          'extra' => array(),
667
          'required' => '0',
668
          'pid' => '0',
669
          'weight' => '15',
670
        ),
671
        'sample values' => 'sample textarea value',
672
        'database values' => array('sample textarea value'),
673
        'database default values' => array('sample textarea default value'),
674
        // Conditionals match against the 'sample values'.
675
        'match conditional values' => array(
676
          'equal' => 'sample textarea value',
677
          'not_equal' => '',
678
          'contains' => 'sample',
679
          'does_not_contain' => 'foo',
680
          'begins_with' => 'sample',
681
          'ends_with' => 'value',
682
          'not_empty' => TRUE,
683
        ),
684
        'mismatch conditional values' => array(
685
          'equal' => '',
686
          'not_equal' => 'sample textarea value',
687
          'contains' => 'foo',
688
          'does_not_contain' => 'sample',
689
          'begins_with' => 'value',
690
          'ends_with' => 'sample',
691
          'empty' => TRUE,
692
        ),
693
      ),
694

    
695
      // Test textfield components.
696
      'textfield' => array(
697
        'component' => array(
698
          'form_key' => 'textfield',
699
          'name' => 'Textfield',
700
          'type' => 'textfield',
701
          'value' => '',
702
          'required' => '0',
703
          'pid' => '0',
704
          'weight' => '-14',
705
        ),
706
        'sample values' => '',
707
        'database values' => array(''),
708
        'database default values' => array(''),
709
      ),
710
      'textfield_disabled' => array(
711
        'component' => array(
712
          'form_key' => 'textfield_disabled',
713
          'name' => 'Textfield Disabled',
714
          'type' => 'textfield',
715
          'value' => '[current-page:query:foo]',
716
          'extra' => array(
717
            'disabled' => 1,
718
          ),
719
          'required' => '0',
720
          'pid' => '0',
721
          'weight' => '-15',
722
        ),
723
        'sample values' => NULL,
724
        'database values' => array('bar'),
725
        'database default values' => array('bar'),
726
      ),
727
      'textfield_profile' => array(
728
        'component' => array(
729
          'form_key' => 'textfield_profile',
730
          'name' => 'Textfield Profile',
731
          'type' => 'textfield',
732
          'value' => '[current-user:gender]',
733
          'extra' => array(
734
            'width' => '20',
735
          ),
736
          'required' => '0',
737
          'pid' => '0',
738
          'weight' => '-6',
739
        ),
740
        'sample values' => 'Female',
741
        'database values' => array('Female'),
742
        'database default values' => array($this->webform_users['admin']->gender[LANGUAGE_NONE][0]['value']),
743
      ),
744

    
745
      // Test time components.
746
      'time' => array(
747
        'component' => array(
748
          'form_key' => 'time',
749
          'name' => 'Time',
750
          'type' => 'time',
751
          'value' => '10:30pm',
752
          'extra' => array(
753
            'timezone' => 'site',
754
            'hourformat' => '12-hour',
755
          ),
756
          'required' => '0',
757
          'pid' => '0',
758
          'weight' => '16',
759
        ),
760
        'sample values' => array('hour' => '12', 'minute' => '0', 'ampm' => 'pm'),
761
        'database values' => array('12:00:00'),
762
        'database default values' => array('22:30:00'),
763
        // Conditionals match against the 'sample values'.
764
        'match conditional values' => array(
765
          'equal' => '12:00pm',
766
          'before' => '1:00pm',
767
          'before_equal' => '12:00pm',
768
          'after' => '11:00am',
769
          'after_equal' => '11:00am',
770
        ),
771
        'mismatch conditional values' => array(
772
          'equal' => '12:00am',
773
          'before' => '12:00pm',
774
          'before_equal' => '11:00am',
775
          'after' => '12:00pm',
776
        ),
777
      ),
778
      'time_24h' => array(
779
        'component' => array(
780
          'form_key' => 'time_24h',
781
          'name' => 'Time 24H',
782
          'type' => 'time',
783
          'value' => '10:30pm',
784
          'extra' => array(
785
            'timezone' => 'site',
786
            'hourformat' => '24-hour',
787
          ),
788
          'required' => '0',
789
          'pid' => '0',
790
          'weight' => '17',
791
        ),
792
        'sample values' => array('hour' => '5', 'minute' => '0'),
793
        'database values' => array('05:00:00'),
794
        'database default values' => array('22:30:00'),
795
        // Conditionals match against the 'sample values'.
796
        'match conditional values' => array(
797
          'equal' => '5:00',
798
          'before' => '24:00',
799
          'before_equal' => '5:00',
800
          'after' => '00:00',
801
          'after_equal' => '00:00',
802
        ),
803
        'mismatch conditional values' => array(
804
          'equal' => '5:01',
805
          'before' => '5:00',
806
          'before_equal' => '4:59',
807
          'after' => '5:00',
808
          'after_equal' => '5:01',
809
        ),
810
      ),
811

    
812
      // Test number components.
813
      'integer' => array(
814
        'component' => array(
815
          'form_key' => 'integer',
816
          'name' => 'Integer',
817
          'type' => 'number',
818
          'value' => '1',
819
          'extra' => array(
820
            'type' => 'textfield',
821
            'integer' => 1,
822
            'max' => '100',
823
            // SimpleTest does not support type="number" input fields.
824
            'attributes' => array('type' => 'text'),
825
          ),
826
          'required' => '0',
827
          'pid' => '0',
828
          'weight' => '18',
829
        ),
830
        'sample values' => '2',
831
        'database values' => array('2'),
832
        'database default values' => array('1'),
833
        // Conditionals match against the 'sample values'.
834
        'match conditional values' => array(
835
          'equal' => '2',
836
          'not_equal' => '0',
837
          'less_than' => '3',
838
          'less_than_equal' => '2',
839
          'greater_than' => '1',
840
          'greater_than_equal' => '1',
841
          'not_empty' => TRUE,
842
        ),
843
        'mismatch conditional values' => array(
844
          'equal' => '0',
845
          'not_equal' => '2',
846
          'less_than' => '2',
847
          'less_than_equal' => '1',
848
          'greater_than' => '2',
849
          'greater_than_equal' => '3',
850
          'empty' => TRUE,
851
        ),
852
        'error values' => array(
853
          '1.5' => t('!name field value of @value must be an integer.', array('!name' => 'Integer', '@value' => '1.5')),
854
          '101' => t('!name field value must be less than @max.', array('!name' => 'Integer', '@max' => '100')),
855
        ),
856
      ),
857
      'integer_range' => array(
858
        'component' => array(
859
          'form_key' => 'integer_range',
860
          'name' => 'Integer Range',
861
          'type' => 'number',
862
          'value' => '50',
863
          'extra' => array(
864
            'type' => 'select',
865
            'min' => '10',
866
            'max' => '50',
867
            'step' => 5,
868
            'integer' => 1,
869
          ),
870
          'required' => '0',
871
          'pid' => '0',
872
          'weight' => '19',
873
        ),
874
        'sample values' => '10',
875
        'database values' => array('10'),
876
        'database default values' => array('50'),
877
      ),
878
      'decimal_positive' => array(
879
        'component' => array(
880
          'form_key' => 'decimal_positive',
881
          'name' => 'Decimal positive',
882
          'type' => 'number',
883
          'value' => '1',
884
          'extra' => array(
885
            'type' => 'textfield',
886
            'field_prefix' => '$',
887
            'field_suffix' => 'lbs',
888
            'min' => '0',
889
            'decimals' => '2',
890
            'point' => '.',
891
            'separator' => ',',
892
            // SimpleTest does not support type="number" input fields.
893
            'attributes' => array('type' => 'text'),
894
          ),
895
          'required' => '0',
896
          'pid' => '0',
897
          'weight' => '20',
898
        ),
899
        'sample values' => '2.00',
900
        'database values' => array('2.00'),
901
        'database default values' => array('1'),
902
        // Conditionals match against the 'sample values'.
903
        'match conditional values' => array(
904
          'equal' => '2',
905
          'not_equal' => '0',
906
          'less_than' => '3.000',
907
          'greater_than' => '1.000',
908
          'not_empty' => TRUE,
909
        ),
910
        'mismatch conditional values' => array(
911
          'equal' => '0',
912
          'not_equal' => '2',
913
          'less_than' => '2.0',
914
          'greater_than' => '2.00',
915
          'empty' => TRUE,
916
        ),
917
        'error values' => array(
918
          '-1' => t('!name field value must be greater than @min.', array('!name' => 'Decimal positive', '@min' => '0')),
919
        ),
920
      ),
921
      'decimal_range' => array(
922
        'component' => array(
923
          'form_key' => 'decimal_range',
924
          'name' => 'Decimal range',
925
          'type' => 'number',
926
          'value' => '1',
927
          'extra' => array(
928
            'type' => 'textfield',
929
            'field_prefix' => '$',
930
            'field_suffix' => 'lbs',
931
            'min' => '1',
932
            'max' => '12',
933
            'step' => '1.5',
934
            // SimpleTest does not support type="number" input fields.
935
            'attributes' => array('type' => 'text'),
936
          ),
937
          'required' => '0',
938
          'pid' => '0',
939
          'weight' => '21',
940
        ),
941
        'sample values' => '11.5',
942
        'database values' => array('11.5'),
943
        'database default values' => array('1'),
944
        'error values' => array(
945
          '2' => t('!name field value must be @start plus a multiple of @step.', array('!name' => 'Decimal range', '@start' => '1', '@step' => '1.5')),
946
          '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')),
947
        ),
948
      ),
949
      'decimal_range_select' => array(
950
        'component' => array(
951
          'form_key' => 'decimal_range_select',
952
          'name' => 'Decimal range select',
953
          'type' => 'number',
954
          'value' => '1',
955
          'extra' => array(
956
            'type' => 'select',
957
            'field_prefix' => '$',
958
            'field_suffix' => 'lbs',
959
            'min' => '1',
960
            'max' => '12',
961
            'step' => '1.5',
962
          ),
963
          'required' => '0',
964
          'pid' => '0',
965
          'weight' => '21',
966
        ),
967
        'sample values' => '10',
968
        'database values' => array('10'),
969
        'database default values' => array('1'),
970
        // Conditionals match against the 'sample values'.
971
        'match conditional values' => array(
972
          'equal' => '10',
973
          'not_equal' => '2.5',
974
          'less_than' => '11.5',
975
          'greater_than' => '1',
976
        ),
977
        'mismatch conditional values' => array(
978
          'equal' => '2.5',
979
          'not_equal' => '10',
980
          'less_than' => '10',
981
          'greater_than' => '11.5',
982
        ),
983
      ),
984
    );
985

    
986
    return $this->_webform_components;
987
  }
988

    
989
  /**
990
   * Create a sample Webform node.
991
   */
992
  public function webformForm() {
993
    if (isset($this->_webform_node)) {
994
      return $this->_webform_node;
995
    }
996

    
997
    $settings = array(
998
      'type' => 'webform',
999
      'language'  => LANGUAGE_NONE,
1000
      'uid' => '1',
1001
      'status' => '1',
1002
      'promote' => '1',
1003
      'moderate' => '0',
1004
      'sticky' => '0',
1005
      'tnid' => '0',
1006
      'translate' => '0',
1007
      'title' => 'Test Webform',
1008
      'log' => '',
1009
      'format' => '1',
1010
      'webform' => array(
1011
        'confirmation' => 'Thanks!',
1012
      ) + webform_node_defaults(),
1013
    );
1014

    
1015
    $cid = 0;
1016
    foreach ($this->webformComponents() as $key => $component_info) {
1017
      $cid++;
1018
      $settings['webform']['components'][$cid] = $component_info['component'];
1019
      $settings['webform']['components'][$cid]['cid'] = $cid;
1020
      $settings['webform']['components'][$cid]['pid'] = 0;
1021
    }
1022

    
1023
    $this->_webform_node = $this->drupalCreateNode($settings);
1024

    
1025
    return $this->_webform_node;
1026
  }
1027

    
1028
  /**
1029
   * Generate a list of all values that would result in a valid submission.
1030
   *
1031
   * @param $input_values
1032
   *   An array of input values keyed by the component form key. If none
1033
   *   are specified, the defaults will be pulled from webformComponents().
1034
   */
1035
  public function webformPost($input_values = NULL) {
1036
    $edit = array();
1037

    
1038
    if (empty($input_values)) {
1039
      $input_values = array();
1040
      foreach ($this->webformComponents() as $key => $component_info) {
1041
        $input_values[$key] = $component_info['sample values'];
1042
      }
1043
    }
1044

    
1045
    foreach ($input_values as $key => $values) {
1046
      if (is_array($values)) {
1047
        foreach ($values as $subkey => $value) {
1048
          $edit["submitted[$key][$subkey]"] = $value;
1049
        }
1050
      }
1051
      elseif ($values != NULL) {
1052
        $value = $values;
1053
        // Multiple selects have a funky extra empty bracket in the name.
1054
        $extra = $key == 'select_multiple' ? '[]' : '';
1055
        $edit["submitted[$key]$extra"] = $value;
1056
      }
1057
    }
1058
    return $edit;
1059
  }
1060

    
1061
  /**
1062
   * Utility function to print out the current page being tested.
1063
   */
1064
  public function webformPrintPage() {
1065
    $this->verbose($this->drupalGetContent());
1066
  }
1067

    
1068
}