diff options
author | louise <louise> | 2009-08-31 09:48:55 +0000 |
---|---|---|
committer | louise <louise> | 2009-08-31 09:48:55 +0000 |
commit | f62012b5445f911835caa6a6fd3a190f9a6a7232 (patch) | |
tree | b054ec453f717b18dc4b6902ef9af1a7d74cee8d | |
parent | ce1a46122ec3298eaf543b68b3ee6bfb0c1c3b14 (diff) |
Methods for allowing cobrands to handle site restrictions
-rw-r--r-- | perllib/Cobrand.pm | 44 | ||||
-rwxr-xr-x | t/Cobrand.t | 32 | ||||
-rw-r--r-- | t/Cobrands/Mysite/Util.pm | 10 |
3 files changed, 76 insertions, 10 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm index cd336f0e4..26fc6c95e 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.4 2009-08-26 17:24:39 louise Exp $ +# $Id: Cobrand.pm,v 1.5 2009-08-31 09:48:55 louise Exp $ package Cobrand; use strict; @@ -24,12 +24,13 @@ sub get_allowed_cobrands{ return \@allowed_cobrands; } -=item cobrand_page QUERY +=item cobrand_handle Q -Return a string containing the HTML to be rendered for a custom Cobranded page +Given a query that has the name of a site set, return a handle to the Util module for that +site, if one exists, or zero if not. =cut -sub cobrand_page{ +sub cobrand_handle{ my $q = shift; my $cobrand = $q->{site}; my $cobrand_class = ucfirst($cobrand); @@ -37,9 +38,38 @@ sub cobrand_page{ eval "use $class"; my $handle; eval{ $handle = $class->new }; - return 0 if $@; - my ($out, %params) = $handle->page($q); - return ($out, %params); + return 0 if $@; + return $handle; +} + + +=item cobrand_page QUERY + +Return a string containing the HTML to be rendered for a custom Cobranded page + +=cut +sub cobrand_page{ + my $q = shift; + my $handle = cobrand_handle($q); + return 0 if $handle == 0; + return $handle->page($q); +} + +=item set_site_restriction Q + +Return a site restriction clause and a site key if the cobrand uses a subset of the FixMyStreet +data. Q is the query object. Returns an empty string and site key 0 if the cobrand uses all the +data. + +=cut +sub set_site_restriction{ + my $q = shift; + my $site_restriction = ''; + my $site_id = 0; + my $handle = cobrand_handle($q); + return ($site_restriction, $site_id) if $handle == 0; + return $handle->site_restriction($q); } 1; + diff --git a/t/Cobrand.t b/t/Cobrand.t index 95f3ac73b..1e9a0edf0 100755 --- a/t/Cobrand.t +++ b/t/Cobrand.t @@ -6,7 +6,7 @@ # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: louise@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Cobrand.t,v 1.1 2009-08-27 08:42:46 louise Exp $ +# $Id: Cobrand.t,v 1.2 2009-08-31 09:48:56 louise Exp $ # use strict; @@ -22,6 +22,33 @@ use lib "$FindBin::Bin/../../perllib"; use Cobrand; use MockQuery; +sub test_site_restriction{ + # should return result of cobrand module site_restriction function + my $q = new MockQuery('mysite'); + my ($site_restriction, $site_id) = Cobrand::set_site_restriction($q); + like($site_restriction, ' and council = 1 '); + like($site_id, 99); + + # should return '' and zero if no module exists + $q = new MockQuery('nosite'); + ($site_restriction, $site_id) = Cobrand::set_site_restriction($q); + like($site_restriction, ''); + like($site_id, 0); +} + +sub test_cobrand_handle{ + # should get a module handle if Util module exists for cobrand + my $q = new MockQuery('mysite'); + my $handle = Cobrand::cobrand_handle($q); + like($handle->site_name(), 'mysite'); + + # should return zero if no module exists + $q = new MockQuery('nosite'); + $handle = Cobrand::cobrand_handle($q); + like($handle, 0); + +} + sub test_cobrand_page{ my $q = new MockQuery('mysite'); # should get the result of the page function in the cobrand module if one exists @@ -36,5 +63,6 @@ sub test_cobrand_page{ } - +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'); diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm index b37d3cdf3..42b920f91 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.1 2009-08-27 08:42:46 louise Exp $ +# $Id: Util.pm,v 1.2 2009-08-31 09:49:59 louise Exp $ package Cobrands::Mysite::Util; use Page; @@ -20,6 +20,14 @@ sub new{ return bless {}, $class; } +sub site_name{ + return 'mysite'; +} + +sub site_restriction{ + return (' and council = 1 ', 99); +} + sub page{ my %params = (); return ("A cobrand produced page", %params); |