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