diff options
author | louise <louise> | 2009-09-22 15:56:44 +0000 |
---|---|---|
committer | louise <louise> | 2009-09-22 15:56:44 +0000 |
commit | 46f8f19ad7fd1bb3c0d36eb0624dadf2c25bb9f2 (patch) | |
tree | 7f9f1b3f6e53d4e3524316b4ad01f179015b0d3c | |
parent | 994efa210dfe0dea7c8fb92e870c05b1407e8b3f (diff) |
Adding the ability to return a hash of header params
-rw-r--r-- | perllib/Cobrand.pm | 21 | ||||
-rwxr-xr-x | t/Cobrand.t | 20 | ||||
-rw-r--r-- | t/Cobrands/Mysite/Util.pm | 8 |
3 files changed, 44 insertions, 5 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm index cb174aa9c..079f9957c 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.18 2009-09-22 14:54:01 louise Exp $ +# $Id: Cobrand.pm,v 1.19 2009-09-22 15:56:44 louise Exp $ package Cobrand; use strict; @@ -346,6 +346,25 @@ sub url { return $url . '?' . extra_params($cobrand, $q); } +=item header_params + +Return any params to be added to responses + +=cut + +sub header_params { + my ($cobrand, $q) = @_; + my $handle; + if ($cobrand){ + $handle = cobrand_handle($cobrand); + } + if ( !$cobrand || !$handle || !$handle->can('header_params')){ + return {}; + } else{ + return $handle->header_params($q); + } +} + 1; diff --git a/t/Cobrand.t b/t/Cobrand.t index 0dc439e64..22ac4cd83 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.9 2009-09-22 14:54:01 louise Exp $ +# $Id: Cobrand.t,v 1.10 2009-09-22 15:56:44 louise Exp $ # use strict; use warnings; -use Test::More tests => 32; +use Test::More tests => 35; use Test::Exception; use FindBin; @@ -63,7 +63,6 @@ sub test_cobrand_handle { $cobrand = 'nosite'; $handle = Cobrand::cobrand_handle($cobrand); ok($handle == 0, 'should return zero if no module exists'); - } sub test_cobrand_page { @@ -151,6 +150,20 @@ sub test_extra_params { } +sub test_header_params { + my $cobrand = 'mysite'; + my $q = new MockQuery($cobrand); + + # should get the results of the header_params function in the cobrand module if one exists + my $header_params = Cobrand::header_params($cobrand, $q); + is_deeply($header_params, {'key' => 'value'}, 'header_params returns output from cobrand module') ; + + # should return an empty string otherwise + $cobrand = 'nosite'; + $header_params = Cobrand::header_params($cobrand, $q); + is_deeply($header_params, {}, 'header_params returns an empty hash ref 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'); @@ -161,3 +174,4 @@ ok(test_base_url_for_emails() == 1, 'Ran all tests for base_url_for_emails'); ok(test_extra_problem_data() == 1, 'Ran all tests for extra_problem_data'); ok(test_extra_update_data() == 1, 'Ran all tests for extra_update_data'); ok(test_extra_params() == 1, 'Ran all tests for extra_params'); +ok(test_header_params() == 1, 'Ran all tests for header_params'); diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm index d3bd3f23a..d90aad6df 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.8 2009-09-22 15:00:40 louise Exp $ +# $Id: Util.pm,v 1.9 2009-09-22 15:56:44 louise Exp $ package Cobrands::Mysite::Util; use Page; @@ -60,4 +60,10 @@ sub extra_update_data { sub extra_params { return 'key=value'; } + +sub header_params { + my %params = ('key' => 'value'); + return \%params; +} + 1; |