diff options
-rw-r--r-- | perllib/Cobrand.pm | 22 | ||||
-rw-r--r-- | perllib/Cobrands/Emptyhomes/Util.pm | 22 | ||||
-rw-r--r-- | perllib/Page.pm | 16 | ||||
-rwxr-xr-x | t/Cobrand.t | 20 | ||||
-rw-r--r-- | t/Cobrands/Mysite/Util.pm | 10 |
5 files changed, 67 insertions, 23 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm index f9dea2210..d589c9fbe 100644 --- a/perllib/Cobrand.pm +++ b/perllib/Cobrand.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: Cobrand.pm,v 1.10 2009-09-09 10:18:01 louise Exp $ +# $Id: Cobrand.pm,v 1.11 2009-09-09 15:29:26 louise Exp $ package Cobrand; use strict; @@ -78,18 +78,34 @@ sub set_site_restriction{ return $handle->site_restriction($q); } +=item base_url COBRAND + +Return the base url for the cobranded version of the site + +=cut +sub base_url{ + my $cobrand = shift; + my $handle = cobrand_handle($cobrand); + return mySociety::Config::get('BASE_URL') unless $handle; + return $handle->base_url(); +} =item set_lang_and_domain COBRAND LANG Set the language and domain of the site based on the cobrand and host + =cut -sub set_lang_and_domain{ - my ($cobrand, $lang) = @_; +sub set_lang_and_domain($$;$) { + my ($cobrand, $lang, $unicode) = @_; if ($cobrand){ my $handle = cobrand_handle($cobrand); if ($handle){ $handle->set_lang_and_domain($lang); } + }else{ + mySociety::Locale::negotiate_language('en-gb,English,en_GB|nb,Norwegian,nb_NO'); # XXX Testing + mySociety::Locale::gettext_domain('FixMyStreet', $unicode); + mySociety::Locale::change(); } } diff --git a/perllib/Cobrands/Emptyhomes/Util.pm b/perllib/Cobrands/Emptyhomes/Util.pm index 560d85ceb..8dbeca4b4 100644 --- a/perllib/Cobrands/Emptyhomes/Util.pm +++ b/perllib/Cobrands/Emptyhomes/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.3 2009-09-02 08:55:59 louise Exp $ +# $Id: Util.pm,v 1.4 2009-09-09 15:29:27 louise Exp $ package Cobrands::Emptyhomes::Util; use Standard; @@ -31,6 +31,20 @@ sub site_restriction{ =item +Return the base url for this cobranded site + +=cut + +sub base_url { + my $base_url = mySociety::Config::get('BASE_URL'); + if ($base_url !~ /emptyhomes/) { + $base_url =~ s/http:\/\//http:\/\/emptyhomes\./g; + } + return $base_url; +} + +=item + Return the list of custom pages that can be produced by this module =cut @@ -57,16 +71,16 @@ sub page{ } } -=item set_lang_and_domain Q HOST +=item set_lang_and_domain LANG UNICODE Set the language and text domain for the site based on the query and host. =cut sub set_lang_and_domain{ - my ($self, $lang) = @_; + my ($self, $lang, $unicode) = @_; mySociety::Locale::negotiate_language('en-gb,English,en_GB|cy,Cymraeg,cy_GB', $lang); - mySociety::Locale::gettext_domain('FixMyStreet-EmptyHomes'); + mySociety::Locale::gettext_domain('FixMyStreet-EmptyHomes', $unicode); mySociety::Locale::change(); } diff --git a/perllib/Page.pm b/perllib/Page.pm index 712f206dc..df491957b 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.173 2009-09-09 08:27:46 louise Exp $ +# $Id: Page.pm,v 1.174 2009-09-09 15:29:26 louise Exp $ # package Page; @@ -104,16 +104,10 @@ sub microsite { $q->{site} = $cobrand if $host =~ /$cobrand/; } - if ($q->{site} ne 'fixmystreet') { - my $lang; - $lang = 'cy' if $host =~ /cy/; - $lang = 'en-gb' if $host =~ /^en\./; - Cobrand::set_lang_and_domain($q->{site}, $lang); - } else { - mySociety::Locale::negotiate_language('en-gb,English,en_GB|nb,Norwegian,nb_NO'); # XXX Testing - mySociety::Locale::gettext_domain('FixMyStreet'); - mySociety::Locale::change(); - } + my $lang; + $lang = 'cy' if $host =~ /cy/; + $lang = 'en-gb' if $host =~ /^en\./; + Cobrand::set_lang_and_domain(get_cobrand($q), $lang); Problems::set_site_restriction($q); Memcached::set_namespace(mySociety::Config::get('BCI_DB_NAME') . ":"); diff --git a/t/Cobrand.t b/t/Cobrand.t index fab80e3d2..3f2e34fba 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.4 2009-09-02 08:32:23 louise Exp $ +# $Id: Cobrand.t,v 1.5 2009-09-09 15:29:27 louise Exp $ # use strict; use warnings; -use Test::More tests => 11; +use Test::More tests => 14; use Test::Exception; use FindBin; @@ -58,6 +58,22 @@ sub test_cobrand_page{ } +sub test_base_url{ + my $cobrand = 'mysite'; + + # should get the result of the page function in the cobrand module if one exists + my $base_url = Cobrand::base_url($cobrand); + is('mysite.example.com', $base_url, 'base_url returns output from cobrand module'); + + # should return the base url from the config if there is no cobrand module + $cobrand = 'nosite'; + $base_url = Cobrand::base_url($cobrand); + is(mySociety::Config::get('BASE_URL'), $base_url, 'base_url returns config base url if no cobrand module'); + +} + 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'); + diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm index 42b920f91..ebefe6336 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.2 2009-08-31 09:49:59 louise Exp $ +# $Id: Util.pm,v 1.3 2009-09-09 15:29:27 louise Exp $ package Cobrands::Mysite::Util; use Page; @@ -29,8 +29,12 @@ sub site_restriction{ } sub page{ - my %params = (); - return ("A cobrand produced page", %params); + my %params = (); + return ("A cobrand produced page", %params); +} + +sub base_url{ + return 'mysite.example.com'; } 1; |