diff options
Diffstat (limited to 't')
-rwxr-xr-x | t/Cobrand.t | 38 | ||||
-rw-r--r-- | t/Cobrands/Mysite/Util.pm | 8 | ||||
-rwxr-xr-x | t/Page.t | 21 |
3 files changed, 57 insertions, 10 deletions
diff --git a/t/Cobrand.t b/t/Cobrand.t index 13e9ef6b4..fe6d46f51 100755 --- a/t/Cobrand.t +++ b/t/Cobrand.t @@ -6,12 +6,12 @@ # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: louise@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Cobrand.t,v 1.6 2009-09-10 08:54:33 louise Exp $ +# $Id: Cobrand.t,v 1.7 2009-09-15 17:42:43 louise Exp $ # use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 20; use Test::Exception; use FindBin; @@ -22,7 +22,7 @@ use lib "$FindBin::Bin/../../perllib"; use Cobrand; use MockQuery; -sub test_site_restriction{ +sub test_site_restriction { my $q = new MockQuery('mysite'); my ($site_restriction, $site_id) = Cobrand::set_site_restriction($q); like($site_restriction, qr/ and council = 1 /, 'should return result of cobrand module site_restriction function'); @@ -34,7 +34,30 @@ sub test_site_restriction{ ok($site_id == 0, 'should return "" and zero if no module exists'); } -sub test_cobrand_handle{ +sub test_form_elements { + my $q = new MockQuery('mysite'); + my $element_html = Cobrand::form_elements('mysite', 'postcodeForm', $q); + ok($element_html eq 'Extra html', 'should return result of cobrand module element_html function') or diag("Got $element_html"); + + $element_html = Cobrand::form_elements('nosite', 'postcodeForm', $q); + ok($element_html eq '', 'should return an empty string if no cobrand module exists') or diag("Got $element_html"); +} + +sub test_disambiguate_location { + my $q = new MockQuery('mysite'); + my $s = 'London Road'; + $s = Cobrand::disambiguate_location('mysite', $s, $q); + ok($s eq 'Specific Location', 'should return result of cobrand module disambiguate_location function') or diag("Got $s");; + + $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"); + +} + + +sub test_cobrand_handle { my $cobrand = 'mysite'; my $handle = Cobrand::cobrand_handle($cobrand); like($handle->site_name(), qr/mysite/, 'should get a module handle if Util module exists for cobrand'); @@ -44,7 +67,7 @@ sub test_cobrand_handle{ } -sub test_cobrand_page{ +sub test_cobrand_page { my $q = new MockQuery('mysite'); # should get the result of the page function in the cobrand module if one exists my ($html, $params) = Cobrand::cobrand_page($q); @@ -58,7 +81,7 @@ sub test_cobrand_page{ } -sub test_base_url{ +sub test_base_url { my $cobrand = 'mysite'; # should get the result of the page function in the cobrand module if one exists @@ -76,4 +99,5 @@ ok(test_cobrand_handle() == 1, 'Ran all tests for the cobrand_handle function'); ok(test_cobrand_page() == 1, 'Ran all tests for the cobrand_page function'); ok(test_site_restriction() == 1, 'Ran all tests for the site_restriction function'); ok(test_base_url() == 1, 'Ran all tests for the base url'); - +ok(test_disambiguate_location() == 1, 'Ran all tests for disambiguate location'); +ok(test_form_elements() == 1, 'Ran all tests for form_elements'); diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm index 59adb845d..6e7098b43 100644 --- a/t/Cobrands/Mysite/Util.pm +++ b/t/Cobrands/Mysite/Util.pm @@ -7,7 +7,7 @@ # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: louise@mysociety.org. WWW: http://www.mysociety.org # -# $Id: Util.pm,v 1.5 2009-09-14 16:09:40 louise Exp $ +# $Id: Util.pm,v 1.6 2009-09-15 17:42:43 louise Exp $ package Cobrands::Mysite::Util; use Page; @@ -37,5 +37,11 @@ sub base_url { return 'http://mysite.example.com'; } +sub disambiguate_location { + return 'Specific Location'; +} +sub form_elements { + return "Extra html"; +} 1; @@ -6,7 +6,7 @@ # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: louise@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Page.t,v 1.3 2009-09-10 08:54:33 louise Exp $ +# $Id: Page.t,v 1.4 2009-09-15 17:42:43 louise Exp $ # use strict; @@ -35,7 +35,23 @@ sub set_lang($) { mySociety::Locale::change(); } -sub test_header(){ +sub test_geocode_string() { + my %params = (); + my $q = new MockQuery('mysite', \%params); + + # geocode a straightforward string, expect success + my ($x, $y, $easting, $northing, $error) = Page::geocode_string('Buckingham Palace', $q); + ok($x == 3279, 'example x coordinate generated'); + ok($y == 1113, 'example y coordinate generated'); + ok($easting == 529044, 'example easting generated'); + ok($northing == 179619, 'example northing generated'); + + # expect a failure message for Northern Ireland + ($x, $y, $easting, $northing, $error) = Page::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'); +} + +sub test_header() { my $q = mock_query(); my $html; my %params = (title => 'test title'); @@ -77,3 +93,4 @@ sub test_base_url_with_lang { ok(test_base_url_with_lang() == 1, 'Ran all tests for base_url_with_lang'); ok(test_footer() == 1, 'Ran all tests for the footer function'); ok(test_header() == 1, 'Ran all tests for the header function'); +ok(test_geocode_string() == 1, 'Ran all tests for the geocode_string function'); |