source: trunk/t/28_wgs84_coords.t @ 878

Last change on this file since 878 was 872, checked in by nick, 15 years ago

Do the wgs84 convertion for the google maps page. Add tests for this too. References #89

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7plan tests => 6;
8
9# Clear out the database from any previous runs.
10unlink "t/node.db";
11# And give us a new one
12Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
13
14# Now we can start testing
15my $config = OpenGuides::Test->make_basic_config;
16$config->force_wgs84 (1);
17
18my $guide = OpenGuides->new( config => $config );
19
20my ($longitude, $latitude) = (10, 12);
21
22my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
23                                                    longitude => $longitude,
24                                                    latitude => $latitude,
25                                                    config => $config);
26
27is( $wgs_long, $longitude,
28    "get_wgs84_coords returns the original longitude when force_wgs84 is on");
29is( $wgs_lat, $latitude,
30    "get_wgs84_coords returns the original latitude when force_wgs84 is on");
31
32
33# Now claim to be in the UK
34eval{ require Geo::HelmertTransform; };
35my $have_helmert = $@ ? 0 : 1;
36SKIP : {
37    skip "Geo::HelmertTransform not installed - can't do transforms", 4
38        unless $have_helmert;
39
40    $config->force_wgs84(0);
41    $config->geo_handler(1);
42
43    # Set our location to be somewhere known
44       ($longitude,$latitude)  = (-1.258200,51.754349);
45    my ($wgs84_lon,$wgs84_lat) = (-1.259687,51.754813);
46
47    ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
48                                                     longitude => $longitude,
49                                                     latitude => $latitude,
50                                                     config => $config);
51
52    # Round to 5 dp
53    my $fivedp = 1 * 1000 * 100;
54    $wgs_long = int($wgs_long * $fivedp)/$fivedp;
55    $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
56    $wgs84_lon = int($wgs84_lon * $fivedp)/$fivedp;
57    $wgs84_lat = int($wgs84_lat * $fivedp)/$fivedp;
58
59    is( $wgs_long, $wgs84_lon,
60        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
61    is( $wgs_lat, $wgs84_lat,
62        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
63
64    # Call it again, check we get the same result
65    ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
66                                                     longitude => $longitude,
67                                                     latitude => $latitude,
68                                                     config => $config);
69    $wgs_long = int($wgs_long * $fivedp)/$fivedp;
70    $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
71    is( $wgs_long, $wgs84_lon,
72        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
73    is( $wgs_lat, $wgs84_lat,
74        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
75}
Note: See TracBrowser for help on using the repository browser.