aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rwxr-xr-xt/Cobrand.t2
-rwxr-xr-xt/Page.t34
-rw-r--r--t/utils.t41
3 files changed, 64 insertions, 13 deletions
diff --git a/t/Cobrand.t b/t/Cobrand.t
index f6c2e9c87..1f38ec605 100755
--- a/t/Cobrand.t
+++ b/t/Cobrand.t
@@ -51,7 +51,7 @@ sub test_disambiguate_location {
$q = new MockQuery('nosite');
$s = 'London Road';
$s = Cobrand::disambiguate_location('nosite', $s, $q);
- ok($s eq 'London Road', 'should return location string as passed if no cobrand module exists') or diag("Got $s");
+ ok($s eq 'London Road&gl=uk', 'should return location string as passed if no cobrand module exists') or diag("Got $s");
}
diff --git a/t/Page.t b/t/Page.t
index d4ccc9f3d..a1ae7f3aa 100755
--- a/t/Page.t
+++ b/t/Page.t
@@ -38,17 +38,24 @@ sub set_lang($) {
sub test_geocode_string() {
my %params = ();
- my $q = new MockQuery('nosite', \%params);
-
- # geocode a straightforward string, expect success
- my ($easting, $northing, $error) = FixMyStreet::Geocode::string('Buckingham Palace', $q);
- ok($easting == 529068, 'example easting generated') or diag("Got $easting");
- ok($northing == 179684, 'example northing generated') or diag("Got $northing");
- ok(! defined($error), 'should not generate error for simple example') or diag("Got $error");
- # expect a failure message for Northern Ireland
- ($easting, $northing, $error) = FixMyStreet::Geocode::string('Falls Road, Belfast', $q);
- ok($error eq "We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.", 'error message produced for NI location') or diag("Got $error");
+ my $q = new MockQuery( 'nosite', \%params );
+
+ # geocode a straightforward string, expect success
+ my ( $latitude, $longitude, $error ) =
+ FixMyStreet::Geocode::string( 'Buckingham Palace', $q );
+ is( $latitude, 51.5013639, 'example easting generated' );
+ is( $longitude, -0.1418898, 'example northing generated' );
+ is( $error, undef, 'should not generate error for simple example' );
+ # expect a failure message for Northern Ireland
+ ( $latitude, $longitude, $error ) =
+ FixMyStreet::Geocode::string( 'Falls Road, Belfast', $q );
+ is(
+ $error,
+ "We do not cover Northern Ireland, I'm afraid, as our licence doesn't "
+ . "include any maps for the region.",
+ 'error message produced for NI location'
+ );
}
sub test_header() {
@@ -64,9 +71,12 @@ sub test_header() {
# Test that template passed is rendered
$params{'template'} = 'test';
- $html = Page::template_header('test', $q, '/../t/templates/' . $q->{site} . '/', title=>'My test title', lang=>'en-gb');
+ $html = Page::template_include('test-header', $q,
+ '/../t/templates/' . $q->{site} . '/',
+ title => 'My test title', lang => 'en-gb'
+ );
+
like ($html, qr/My test header template/, 'named template rendered ok');
-
return 1;
}
diff --git a/t/utils.t b/t/utils.t
new file mode 100644
index 000000000..385c482ed
--- /dev/null
+++ b/t/utils.t
@@ -0,0 +1,41 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 9;
+
+use FindBin;
+use lib "$FindBin::Bin/../perllib";
+use lib "$FindBin::Bin/../commonlib/perllib";
+
+use Utils;
+
+my @truncate_tests = (
+ [ '1.1234567890123', '1.123457', "truncate down" ],
+ [ '1.123456', '1.123456', "leave untouched" ],
+ [ '1.12', '1.12', "don't extend" ],
+ [ '1.100000001', '1.1', "knock off trailing zeros" ],
+ [ '1.000000001', '1', "knock off trailing zeros" ],
+ [ '0.0', '0', "knock off trailing zeros" ],
+ [ '+123', '123', "drop plus sign" ],
+ [ '-123', '-123', "keep minus sign" ],
+);
+
+foreach my $test (@truncate_tests) {
+ my ( $in, $out, $msg ) = @$test;
+ is Utils::truncate_coordinate($in), $out, $msg;
+}
+
+my @convert_en_to_latlon_tests = (
+
+ # e n lat lon
+ [ 1234, 4567, 49.808509, -7.544784 ],
+);
+
+foreach my $test (@convert_en_to_latlon_tests) {
+ my ( $e, $n, $lat, $lon ) = @$test;
+ is_deeply #
+ [ Utils::convert_en_to_latlon_truncated( $e, $n ) ], #
+ [ $lat, $lon ], #
+ "convert ($e,$n) to ($lat,$lon)";
+}