aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Page.pm3
-rwxr-xr-xt/Page.t38
2 files changed, 34 insertions, 7 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 9b0860391..2e76488f1 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.pm,v 1.170 2009-09-03 13:36:47 louise Exp $
+# $Id: Page.pm,v 1.171 2009-09-03 13:54:13 louise Exp $
#
package Page;
@@ -125,6 +125,7 @@ sub base_url_with_lang {
my $base = "http://" . $host;
return $base unless $q->{site} eq 'emptyhomes';
my $lang = $mySociety::Locale::lang;
+ $base =~ s{http://(cy|en)\.}{http://};
if ($reverse && $lang eq 'en-gb') {
$base =~ s{http://}{$&cy.};
} elsif ($reverse) {
diff --git a/t/Page.t b/t/Page.t
index 4a79267fc..c7c348965 100755
--- a/t/Page.t
+++ b/t/Page.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: Page.t,v 1.1 2009-08-27 08:42:46 louise Exp $
+# $Id: Page.t,v 1.2 2009-09-03 13:54:13 louise Exp $
#
use strict;
use warnings;
-use Test::More tests => 4;
+use Test::More tests => 9;
use Test::Exception;
use FindBin;
@@ -28,14 +28,19 @@ sub mock_query(){
return $q;
}
+sub set_lang($) {
+ my $lang = shift;
+ mySociety::Locale::negotiate_language($lang);
+ mySociety::Locale::gettext_domain('FixMyStreet');
+ mySociety::Locale::change();
+}
+
sub test_header(){
my $q = mock_query();
my $html;
my %params = (title => 'test title');
- mySociety::Locale::negotiate_language('en-gb,English,en_GB');
- mySociety::Locale::gettext_domain('FixMyStreet');
- mySociety::Locale::change();
-
+ set_lang('en-gb,English,en_GB');
+
# Test that param that isn't explicitly allowed raises error
$params{'test-param'} = 'test';
throws_ok { Page::header($q, %params); } qr/bad parameter/, 'bad parameter caught ok';
@@ -54,5 +59,26 @@ sub test_footer(){
return 1;
}
+sub test_base_url_with_lang {
+ $ENV{HTTP_HOST}='test.com';
+ set_lang('en-gb,English,en_GB');
+ my $q = mock_query();
+ my $url = Page::base_url_with_lang($q);
+ ok($url eq 'http://test.com', 'Basic url rendered ok');
+
+ $q = new MockQuery('emptyhomes');
+ $url = Page::base_url_with_lang($q);
+ ok($url eq 'http://en.test.com', 'Empty homes url with lang returned ok');
+
+ $url = Page::base_url_with_lang($q, 1);
+ ok($url eq 'http://cy.test.com', 'Empty homes url with lang reversed returned ok');
+
+ $q = new MockQuery('emptyhomes');
+ $ENV{HTTP_HOST}='en.test.com';
+ $url = Page::base_url_with_lang($q);
+ ok($url eq 'http://en.test.com', 'No extra lang part for emptyhomes url with lang part');
+}
+
+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');