From b53f3398eaf581b9029b688428bc75fcb0648594 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 23 May 2011 09:21:38 +0200 Subject: Rename to Net::Travel::DE::VRR --- t/02-synopsis.t | 7 +- t/20-vrr.t | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++ t/50-www-efa.t | 226 --------------------------------------------------- t/out/ambiguous | 4 - t/out/invalid_input | 1 - t/out/no_connections | 5 -- 6 files changed, 227 insertions(+), 242 deletions(-) create mode 100644 t/20-vrr.t delete mode 100644 t/50-www-efa.t delete mode 100644 t/out/ambiguous delete mode 100644 t/out/invalid_input delete mode 100644 t/out/no_connections (limited to 't') diff --git a/t/02-synopsis.t b/t/02-synopsis.t index 3b5f0c8..fb2b63f 100644 --- a/t/02-synopsis.t +++ b/t/02-synopsis.t @@ -9,10 +9,5 @@ eval "use Test::Synopsis"; if ($@) { plan skip_all => 'Test::Synopsis required for testing'; } -else { - plan tests => 1; -} -for my $m (qw(lib/WWW/Efa.pm)) { - synopsis_ok($m); -} +all_synopsis_ok(); diff --git a/t/20-vrr.t b/t/20-vrr.t new file mode 100644 index 0000000..86422c1 --- /dev/null +++ b/t/20-vrr.t @@ -0,0 +1,226 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; + +use Test::More tests => 59; + +BEGIN { + use_ok('Net::Travel::DE::VRR'); +} +require_ok('Net::Travel::DE::VRR'); + +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( + 'Net::Travel::DE::VRR' => [%{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", + ); + + 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) = @_; + return; # FIXME error handling + 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", + ); + + # FIXME actual error tests + +} + +is_efa_post('ignored', 'ignored'); + +my $efa; + +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', + 'Invalid day', +); + +is_efa_err( + 'date', '7.', + 'Invalid month', +); + +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], +); diff --git a/t/50-www-efa.t b/t/50-www-efa.t deleted file mode 100644 index 29e4af5..0000000 --- a/t/50-www-efa.t +++ /dev/null @@ -1,226 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use 5.010; - -use Test::More tests => 59; - -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", - ); - - 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) = @_; - return; # FIXME error handling - 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", - ); - - # FIXME actual error tests - -} - -is_efa_post('ignored', 'ignored'); - -my $efa; - -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', - 'Invalid day', -); - -is_efa_err( - 'date', '7.', - 'Invalid month', -); - -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], -); diff --git a/t/out/ambiguous b/t/out/ambiguous deleted file mode 100644 index 787b3fd..0000000 --- a/t/out/ambiguous +++ /dev/null @@ -1,4 +0,0 @@ -WWW::Efa error: ambiguous input for name_origin: - Bredeney - Bredeney Friedhof - Bredeneyer Kreuz diff --git a/t/out/invalid_input b/t/out/invalid_input deleted file mode 100644 index 2d22895..0000000 --- a/t/out/invalid_input +++ /dev/null @@ -1 +0,0 @@ -WWW::Efa error: No data returned by efa.vrr.de diff --git a/t/out/no_connections b/t/out/no_connections deleted file mode 100644 index f081ab7..0000000 --- a/t/out/no_connections +++ /dev/null @@ -1,5 +0,0 @@ -WWW::Efa error from efa.vrr.de: - -Leider konnte für Ihre Anfrage keine Verbindung gefunden werden! Bitte ändern Sie Ihre Eingabe (z.B. Fußwegezeit in den Mobilitätseinstellungen) oder starten Sie eine neue Anfrage! - - -- cgit v1.2.3