1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use Test::More tests => 131;
BEGIN {
use_ok('WWW::Efa');
}
require_ok('WWW::Efa');
sub efa_conf {
my $ret = {
from => ['Essen', 'HBf'],
to => ['Koeln', 'HBf'],
};
foreach my $p (@_) {
$ret->{$p->[0]} = $p->[1];
}
return $ret;
}
sub efa_new {
return new_ok(
'WWW::Efa' => [%{efa_conf(@_)}]
);
}
sub is_efa_post {
my ($ck, $cv, @post) = @_;
my $efa = efa_new([$ck, $cv]);
my $ok = 1;
is_deeply(
$efa->{'config'}, efa_conf([$ck, $cv]),
"$ck => $cv: conf ok",
);
is(
$efa->{'error'}, undef,
"$ck => $cv: No error",
);
foreach my $ref (@post) {
my ($key, $value) = @{$ref};
if (not defined $efa->{'post'}->{"key"} and
not defined $value) {
next;
}
if ($efa->{'post'}->{"$key"} ne $value) {
$ok = 0;
last;
}
}
ok(
$ok,
"$ck => $cv: POST okay",
);
}
sub is_efa_err {
my ($key, $val, $str) = @_;
my $efa = efa_new([$key, $val]);
my $val_want = $val;
if (ref $val eq 'ARRAY') {
$val_want = join(q{ }, @{$val});
}
is_deeply(
$efa->{'config'}, efa_conf([$key, $val]),
"conf ok: $key => $val",
);
isa_ok($efa->{'error'}, 'WWW::Efa::Error::Setup');
is(
$efa->{'error'}->option(), $key,
"$key => $val: Error: Correct key",
);
is(
$efa->{'error'}->value(), $val_want,
"$key => $val: Error: Correct valuef",
);
is(
$efa->{'error'}->message(), $str,
"$key => $val: Error: String is '$str'",
);
}
is_efa_post('ignored', 'ignored');
my $efa = new_ok('WWW::Efa' => []);
isa_ok($efa->{'error'}, 'WWW::Efa::Error::Setup');
is($efa->{'error'}->{'key'}, 'place');
is($efa->{'error'}->{'value'}, 'origin');
is($efa->{'error'}->{'message'}, 'Need at least two elements');
is_efa_post(
'via', ['MH', 'HBf'],
['place_via', 'MH'],
['name_via', 'HBf'],
['type_via', 'stop'],
);
is_efa_post(
'from', ['D', 'Fuerstenwall 232', 'address'],
['place_origin', 'D'],
['name_origin', 'Fuerstenwall 232'],
['type_origin', 'address'],
);
is_efa_post(
'depart', '22:23',
['itdTripDateTimeDepArr', 'dep'],
['itdTimeHour', '22'],
['itdTimeMinute', '23'],
);
is_efa_post(
'arrive', '16:38',
['itdTripDateTimeDepArr', 'arr'],
['itdTimeHour', '16'],
['itdTimeMinute', '38'],
);
is_efa_err(
'depart', '37:00',
'Must match HH:MM',
);
is_efa_err(
'depart', '07',
'Must match HH:MM',
);
is_efa_post(
'date', '2.10.2009',
['itdDateDay', '2'],
['itdDateMonth', '10'],
['itdDateYear', '2009'],
);
is_efa_post(
'date', '26.12.',
['itdDateDay', '26'],
['itdDateMonth', '12'],
['itdDateYear', (localtime(time))[5] + 1900],
);
is_efa_err(
'date', '42.5.2003',
'Must match DD.MM.[YYYY]'
);
is_efa_err(
'date', '7.',
'Must match DD.MM.[YYYY]'
);
is_efa_post(
'exclude', [qw[zug]],
['inclMOT_0', undef],
);
is_efa_post(
'exclude', [qw[stadtbus schiff ast]],
['inclMOT_5', undef],
['inclMOT_9', undef],
['inclMOT_10', undef],
);
is_efa_err(
'exclude', [qw[sonstige invalid]],
'Must consist of '
. 'zug s-bahn u-bahn stadtbahn tram stadtbus regionalbus '
. 'schnellbus seilbahn schiff ast sonstige',
);
is_efa_post(
'prefer', 'speed',
['routeType', 'LEASTTIME'],
);
is_efa_post(
'prefer', 'nowait',
['routeType', 'LEASTINTERCHANGE'],
);
is_efa_post(
'prefer', 'nowalk',
['routeType', 'LEASTWALKING'],
);
is_efa_err(
'prefer', 'invalid',
'Must be either speed, nowait or nowalk',
);
is_efa_post(
'include', 'local',
['lineRestriction', 403],
);
is_efa_post(
'include', 'ic',
['lineRestriction', 401],
);
is_efa_post(
'include', 'ice',
['lineRestriction', 400],
);
is_efa_err(
'include', 'invalid',
'Must be one of local/ic/ice',
);
is_efa_post(
'walk_speed', 'normal',
['changeSpeed', 'normal'],
);
is_efa_err(
'walk_speed', 'invalid',
'Must be normal, fast or slow',
);
is_efa_post(
'max_interchanges', 5,
['maxChanges', 5],
);
is_efa_post(
'proximity', 1,
['useProxFootSearch', 1],
);
is_efa_post(
'bike', 1,
['bikeTakeAlong', 1],
);
|