1 |
65389548
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Unit test Webform Validation module.
|
5 |
|
|
*/
|
6 |
|
|
class WebformValidationUnitTestCase extends DrupalUnitTestCase {
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* {@inheritdoc}
|
10 |
|
|
*/
|
11 |
|
|
public static function getInfo() {
|
12 |
|
|
return array(
|
13 |
|
|
'name' => t('Webform Validation Unit Tests'),
|
14 |
|
|
'description' => t('Unit tests for Webform Validation module.'),
|
15 |
|
|
'group' => t('Webform'),
|
16 |
|
|
);
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* {@inheritdoc}
|
21 |
|
|
*/
|
22 |
|
|
public function setUp() {
|
23 |
|
|
parent::setUp();
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* The tests.
|
28 |
|
|
*/
|
29 |
|
|
public function test() {
|
30 |
|
|
|
31 |
|
|
$validator_name = 'comparison';
|
32 |
|
|
$items = array(
|
33 |
|
|
'one' => array(
|
34 |
|
|
'hour' => 12,
|
35 |
|
|
'minute' => 1,
|
36 |
|
|
'ampm' => 'AM',
|
37 |
|
|
),
|
38 |
|
|
'two' => array(
|
39 |
|
|
'hour' => 12,
|
40 |
|
|
'minute' => 4,
|
41 |
|
|
'ampm' => 'AM',
|
42 |
|
|
),
|
43 |
|
|
);
|
44 |
|
|
$components = array(
|
45 |
|
|
'one' => array(
|
46 |
|
|
'type' => 'time',
|
47 |
|
|
),
|
48 |
|
|
'two' => array(
|
49 |
|
|
'type' => 'time',
|
50 |
|
|
),
|
51 |
|
|
);
|
52 |
|
|
$rule = array(
|
53 |
|
|
'data' => '<',
|
54 |
|
|
'components' => $components,
|
55 |
|
|
'error_message' => 'Error message.',
|
56 |
|
|
);
|
57 |
|
|
$test_value = webform_validation_webform_validation_validate($validator_name, $items, $components, $rule);
|
58 |
|
|
$value = array();
|
59 |
|
|
$this->assertIdentical($test_value, $value, 'No error for passing validation.');
|
60 |
|
|
|
61 |
|
|
$rule['data'] = '>';
|
62 |
|
|
$test_value = webform_validation_webform_validation_validate($validator_name, $items, $components, $rule);
|
63 |
|
|
$value = array('two' => 'Error message.');
|
64 |
|
|
$this->assertIdentical($test_value, $value, 'Error for failing validation.');
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
} |