Author: dom Date: 2007-06-16 16:41:13 +0100 (Sat, 16 Jun 2007) New Revision: 1079
Added: trunk/t/69_bug_zero_geo.t Modified: trunk/lib/OpenGuides/Template.pm Log: Fix bug representing zero geodata (fixes #215)
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2007-06-16 14:20:24 UTC (rev 1078) +++ trunk/lib/OpenGuides/Template.pm 2007-06-16 15:41:13 UTC (rev 1079) @@ -423,19 +423,19 @@ $os_y =~ s/\s+//g;
# If we were sent x and y, work out lat/long; and vice versa. - if ( $os_x && $os_y ) { + if ( defined $os_x && defined $os_y ) { my $point = Geography::NationalGrid::GB->new( Easting =>$os_x, Northing=>$os_y); $lat = sprintf("%.6f", $point->latitude); $long = sprintf("%.6f", $point->longitude); - } elsif ( $lat && $long ) { + } elsif ( defined $lat && defined $long ) { my $point = Geography::NationalGrid::GB->new(Latitude => $lat, Longitude => $long); $os_x = $point->easting; $os_y = $point->northing; }
- if ( $os_x && $os_y ) { + if ( defined $os_x && defined $os_y ) { %vars = ( %vars, latitude => $lat, @@ -468,18 +468,18 @@ $osie_y =~ s/\s+//g;
# If we were sent x and y, work out lat/long; and vice versa. - if ( $osie_x && $osie_y ) { + if ( defined $osie_x && defined $osie_y ) { my $point = Geography::NationalGrid::IE->new(Easting=>$osie_x, Northing=>$osie_y); $lat = sprintf("%.6f", $point->latitude); $long = sprintf("%.6f", $point->longitude); - } elsif ( $lat && $long ) { + } elsif ( defined $lat && defined $long ) { my $point = Geography::NationalGrid::GB->new(Latitude => $lat, Longitude => $long); $osie_x = $point->easting; $osie_y = $point->northing; } - if ( $osie_x && $osie_y ) { + if ( defined $osie_x && defined $osie_y ) { %vars = ( %vars, latitude => $lat, @@ -505,7 +505,7 @@ my $lat = $q->param("latitude"); my $long = $q->param("longitude");
- if ( $lat && $long ) { + if ( defined $lat && defined $long ) { # Trim whitespace. $lat =~ s/\s+//g; $long =~ s/\s+//g;
Added: trunk/t/69_bug_zero_geo.t =================================================================== --- trunk/t/69_bug_zero_geo.t (rev 0) +++ trunk/t/69_bug_zero_geo.t 2007-06-16 15:41:13 UTC (rev 1079) @@ -0,0 +1,103 @@ +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use Cwd; +use OpenGuides; +use Test::More; +use OpenGuides::Test; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 6; + +Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_url => "http://wiki.example.com/", + script_name => "mywiki.cgi", + site_name => "Wiki::Toolkit Test Site", + template_path => cwd . "/templates", + } +); +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene ( 0 ) }; + +$config->{geo_handler} = 1; + +my $guide = OpenGuides->new( config => $config ); + +my $q = OpenGuides::Test->make_cgi_object( + content => "Blah", + os_x => 0, + os_y => 0 +); + +my $output = $guide->commit_node( + id => "Test Node", + cgi_obj => $q, + return_output => 1 +); + +my %details = $guide->wiki->retrieve_node("Test Node"); + +use Data::Dumper; +#print STDERR Dumper %details; + +is( @{$details{metadata}->{os_x}}[0], 0, "Zero os_x saved" ); +is( @{$details{metadata}->{os_y}}[0], 0, "Zero os_y saved" ); + +$config->{geo_handler} = 2; + +Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + +$guide = OpenGuides->new( config => $config ); + +$q = OpenGuides::Test->make_cgi_object( + content => "Blah", + osie_x => 0, + osie_y => 0 +); + +$output = $guide->commit_node( + id => "Test Node IE", + cgi_obj => $q, + return_output => 1 +); + +%details = $guide->wiki->retrieve_node("Test Node IE"); + +is( @{$details{metadata}->{osie_x}}[0], 0, "Zero osie_x saved" ); +is( @{$details{metadata}->{osie_y}}[0], 0, "Zero osie_y saved" ); + +$config->{geo_handler} = 3; + +Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + +$guide = OpenGuides->new( config => $config ); + +$q = OpenGuides::Test->make_cgi_object( + content => "Blah", + latitude => 0, + longitude => 0 +); + +$output = $guide->commit_node( + id => "Test Node lat/long", + cgi_obj => $q, + return_output => 1 +); + +%details = $guide->wiki->retrieve_node("Test Node lat/long"); + +is( @{$details{metadata}->{latitude}}[0], 0, "Zero latitude saved" ); +is( @{$details{metadata}->{longitude}}[0], 0, "Zero longitude saved" ); +
openguides-commits@lists.openguides.org