summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-11-20 12:42:44 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-11-20 12:42:44 +0100
commitd146e44ff3a8b3304e6603a2238c40034c4b91a1 (patch)
tree8e34dd730d76d273e36f782bff218d1e8aec2f42
parenta32aaf5392f222c120e00eb556897d435993c8e2 (diff)
VRR.pm: Check for 'ambiguous input' error condition
-rw-r--r--lib/Travel/Status/DE/VRR.pm44
-rw-r--r--t/21-vrr-ambig.t28
-rw-r--r--t/in/essen_alfredusbad_ambiguous.xml81
3 files changed, 153 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/VRR.pm b/lib/Travel/Status/DE/VRR.pm
index 3fe437f..3efb1e8 100644
--- a/lib/Travel/Status/DE/VRR.pm
+++ b/lib/Travel/Status/DE/VRR.pm
@@ -109,6 +109,8 @@ sub new {
$self->{tree} = XML::LibXML->load_xml( string => $self->{xml}, );
+ $self->check_for_ambiguous();
+
return $self;
}
@@ -147,6 +149,48 @@ sub sprintf_time {
);
}
+sub check_for_ambiguous {
+ my ($self) = @_;
+
+ my $xml = $self->{tree};
+
+ my $xp_place = XML::LibXML::XPathExpression->new('//itdOdv/itdOdvPlace');
+ my $xp_name = XML::LibXML::XPathExpression->new('//itdOdv/itdOdvName');
+
+ my $xp_place_elem = XML::LibXML::XPathExpression->new('./odvPlaceElem');
+ my $xp_name_elem = XML::LibXML::XPathExpression->new('./odvNameElem');
+
+ my $e_place = ( $xml->findnodes($xp_place) )[0];
+ my $e_name = ( $xml->findnodes($xp_name) )[0];
+
+ if ( not( $e_place and $e_name ) ) {
+
+ # this should not happen[tm]
+ cluck('skipping ambiguity check- itdOdvPlace/itdOdvName missing');
+ return;
+ }
+
+ if ( $e_place->getAttribute('state') eq 'list' ) {
+ $self->{errstr} = sprintf(
+ 'Ambiguous place input: %s',
+ join( q{ | },
+ map { $_->textContent }
+ @{ $e_place->findnodes($xp_place_elem) } )
+ );
+ return;
+ }
+ if ( $e_name->getAttribute('state') eq 'list' ) {
+ $self->{errstr} = sprintf(
+ 'Ambiguous name input: %s',
+ join( q{ | },
+ map { $_->textContent } @{ $e_name->findnodes($xp_name_elem) } )
+ );
+ return;
+ }
+
+ return;
+}
+
sub lines {
my ($self) = @_;
my @lines;
diff --git a/t/21-vrr-ambig.t b/t/21-vrr-ambig.t
new file mode 100644
index 0000000..7dd96a4
--- /dev/null
+++ b/t/21-vrr-ambig.t
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.010;
+use utf8;
+
+use File::Slurp qw(slurp);
+use Test::More tests => 7;
+
+BEGIN {
+ use_ok('Travel::Status::DE::VRR');
+}
+require_ok('Travel::Status::DE::VRR');
+
+my $xml = slurp('t/in/essen_alfredusbad_ambiguous.xml');
+
+my $status = Travel::Status::DE::VRR->new_from_xml(xml => $xml);
+
+isa_ok($status, 'Travel::Status::DE::VRR');
+can_ok($status, qw(errstr results));
+
+$status->check_for_ambiguous();
+
+is($status->errstr, 'Ambiguous name input: Alfredusbad | Am Alfredusbad',
+ 'errstr ok');
+
+is_deeply([$status->lines], [], 'no lines');
+is_deeply([$status->results], [], 'no results');
diff --git a/t/in/essen_alfredusbad_ambiguous.xml b/t/in/essen_alfredusbad_ambiguous.xml
new file mode 100644
index 0000000..9b3e589
--- /dev/null
+++ b/t/in/essen_alfredusbad_ambiguous.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<itdRequest version="9.16.27.53" language="de" lengthUnit="METER" sessionID="efa1.vrr.de_36925562" client="libwww-perl/6.03" clientIP="87.147.17.185" serverID="efa1.vrr.de_" virtDir="vrr" now="2011-11-20T12:18:48" nowWD="1">
+ <itdLayoutParams>
+ <itdLayoutParam name="mdvMap2_dm" value="" />
+ <itdLayoutParam name="mapState_dm" value="" />
+ <itdLayoutParam name="mdvMap_dm" value="3406199:401077:NAV3" />
+ <itdLayoutParam name="view" value="" />
+ <itdLayoutParam name="id_dm" value=":dm" />
+ <itdLayoutParam name="transpCompany" value="vrr" />
+ </itdLayoutParams>
+ <itdDepartureMonitorRequest requestID="1">
+ <itdOdv type="stop" usage="dm">
+ <itdOdvPlace state="identified" method="itp">
+ <odvPlaceElem omc="5113000" placeID="18" value="5113000:18" span="0" type="remote" mainPlace="1">Essen</odvPlaceElem>
+ <odvPlaceInput>E</odvPlaceInput>
+ </itdOdvPlace>
+ <itdOdvName state="list" method="itp">
+ <itdMessage type="error" module="BROKER" code="1">name list</itdMessage>
+ <odvNameElem listIndex="0" selected="0" matchQuality="999010" stopID="20009115" value="0:1">Alfredusbad</odvNameElem>
+ <odvNameElem listIndex="1" selected="0" matchQuality="996010" stopID="20009903" value="1:2">Am Alfredusbad</odvNameElem>
+ <odvNameInput>Afredusbad</odvNameInput>
+ </itdOdvName>
+ </itdOdv>
+ <itdDateTime ttpFrom="20110901" ttpTo="20120531">
+ <itdDate weekday="1" year="2011" month="11" day="20" />
+ <itdTime hour="12" minute="20" />
+ </itdDateTime>
+ <itdDateRange>
+ <itdDate day="20" month="11" year="2011" weekday="1" />
+ <itdDate day="21" month="11" year="2011" weekday="2" />
+ <itdDate day="22" month="11" year="2011" weekday="3" />
+ <itdDate day="23" month="11" year="2011" weekday="4" />
+ <itdDate day="24" month="11" year="2011" weekday="5" />
+ <itdDate day="25" month="11" year="2011" weekday="6" />
+ <itdDate day="26" month="11" year="2011" weekday="7" />
+ <itdDate day="27" month="11" year="2011" weekday="1" />
+ <itdDate day="28" month="11" year="2011" weekday="2" />
+ <itdDate day="29" month="11" year="2011" weekday="3" />
+ <itdDate day="30" month="11" year="2011" weekday="4" />
+ <itdDate day="01" month="12" year="2011" weekday="5" />
+ <itdDate day="02" month="12" year="2011" weekday="6" />
+ <itdDate day="03" month="12" year="2011" weekday="7" />
+ <itdDate day="04" month="12" year="2011" weekday="1" />
+ </itdDateRange>
+ <itdTripOptions>
+ <itdPtOptions>
+ <excludedMeans>
+ <meansElem value="0" selected="0">Zug</meansElem>
+ <meansElem value="1" selected="0">S-Bahn</meansElem>
+ <meansElem value="2" selected="0">U-Bahn</meansElem>
+ <meansElem value="3" selected="0">Stadtbahn</meansElem>
+ <meansElem value="4" selected="0">Stra├čen-/Trambahn</meansElem>
+ <meansElem value="5" selected="0">Stadtbus</meansElem>
+ <meansElem value="6" selected="0">Regionalbus</meansElem>
+ <meansElem value="7" selected="0">Schnellbus</meansElem>
+ <meansElem value="8" selected="0">Seil-/Zahnradbahn</meansElem>
+ <meansElem value="9" selected="0">Schiff</meansElem>
+ <meansElem value="10" selected="0">AST/Rufbus</meansElem>
+ <meansElem value="11" selected="0">Sonstige</meansElem>
+ </excludedMeans>
+ </itdPtOptions>
+ <itdItOptions>
+ <itRouter logASCII="false" logSVG="false" />
+ <itPedestrian computeMonomodalTrip="false" computationType="PT_AND_IT" itIncidentData="false" useElevation="false" speedFactor="100" costFactor="0" distanceFactor="50" traveltimeFactor="50" noTunnel="false" noBridge="false" noFerry="false" maxTime="20" maxLength="2147483647" ignoreRestrictions="false" />
+ <itBicycle preferAsphaltTracks="false" preferGreenTracks="false" usePseudoRouting="false" useSignedRoute="false" cycleSpeed="20" prefHikePath="false" elevFac="50" bikeProf="UNKNOWN" computeMonomodalTrip="false" computationType="PT_AND_IT" itIncidentData="false" useElevation="false" speedFactor="100" costFactor="0" distanceFactor="50" traveltimeFactor="50" noTunnel="false" noBridge="false" noFerry="false" maxTime="15" maxLength="2147483647" ignoreRestrictions="false" />
+ <mitCar computeMonomodalTrip="false" computationType="PT_AND_IT" itIncidentData="false" useElevation="false" speedFactor="100" costFactor="0" distanceFactor="10" traveltimeFactor="90" noTunnel="false" noBridge="false" noFerry="false" maxTime="90" maxLength="2147483647" ignoreRestrictions="false" mitProfileData="false" mitIncidentData="false" mitOnlineData="false" noHighway="false" noTollRoad="false" />
+ <departureTransport>
+ <individualTransport meansCode="100" value="8" speed="normal" selected="1" />
+ <individualTransport meansCode="101" value="15" speed="normal" selected="0" />
+ <individualTransport meansCode="102" value="15" speed="normal" selected="0" />
+ <individualTransport meansCode="103" value="10" speed="normal" selected="0" />
+ <individualTransport meansCode="104" value="10" speed="normal" selected="0" />
+ <individualTransport meansCode="105" value="30" speed="normal" selected="0" />
+ <individualTransport meansCode="106" value="15" speed="normal" selected="0" />
+ <individualTransport meansCode="107" value="15" speed="normal" selected="0" />
+ </departureTransport>
+ </itdItOptions>
+ </itdTripOptions>
+ </itdDepartureMonitorRequest>
+</itdRequest>
+