aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Cobrand.pm71
-rwxr-xr-xt/Cobrand.t52
2 files changed, 119 insertions, 4 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
index c780e28e8..cb174aa9c 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.17 2009-09-16 17:00:35 louise Exp $
+# $Id: Cobrand.pm,v 1.18 2009-09-22 14:54:01 louise Exp $
package Cobrand;
use strict;
@@ -277,6 +277,75 @@ sub form_elements {
}
+=item extra_problem_data COBRAND Q
+
+Return a string of extra data to be stored with a problem
+
+=cut
+
+sub extra_problem_data {
+
+ my ($cobrand, $q) = @_;
+ my $handle;
+ if ($cobrand){
+ $handle = cobrand_handle($cobrand);
+ }
+ if ( !$cobrand || !$handle || !$handle->can('extra_problem_data')){
+ return '';
+ } else{
+ return $handle->extra_problem_data($q);
+ }
+}
+
+=item extra_update_data COBRAND Q
+
+Return a string of extra data to be stored with a problem
+
+=cut
+
+sub extra_update_data {
+ my ($cobrand, $q) = @_;
+ my $handle;
+ if ($cobrand){
+ $handle = cobrand_handle($cobrand);
+ }
+ if ( !$cobrand || !$handle || !$handle->can('extra_update_data')){
+ return '';
+ } else{
+ return $handle->extra_update_data($q);
+ }
+}
+
+=item extra_params COBRAND Q
+
+Given a query, return a hash of extra params to be included in
+any URLs in links produced on the page returned by that query.
+
+=cut
+sub extra_params {
+ my ($cobrand, $q) = @_;
+ my $handle;
+ if ($cobrand){
+ $handle = cobrand_handle($cobrand);
+ }
+ if ( !$cobrand || !$handle || !$handle->can('extra_params')){
+ return '';
+ } else{
+ return $handle->extra_params($q);
+ }
+
+}
+
+=item url
+
+Given a URL, return a URL with any extra params needed appended to it.
+
+=cut
+sub url {
+ my ($cobrand, $url, $q) = @_;
+ return $url . '?' . extra_params($cobrand, $q);
+}
+
1;
diff --git a/t/Cobrand.t b/t/Cobrand.t
index 79153e690..0dc439e64 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.8 2009-09-16 17:00:35 louise Exp $
+# $Id: Cobrand.t,v 1.9 2009-09-22 14:54:01 louise Exp $
#
use strict;
use warnings;
-use Test::More tests => 23;
+use Test::More tests => 32;
use Test::Exception;
use FindBin;
@@ -80,6 +80,34 @@ sub test_cobrand_page {
}
+sub test_extra_problem_data {
+ my $cobrand = 'mysite';
+ my $q = new MockQuery($cobrand);
+
+ # should get the result of the page function in the cobrand module if one exists
+ my $cobrand_data = Cobrand::extra_problem_data($cobrand, $q);
+ ok($cobrand_data eq 'Cobrand problem data', 'extra_problem_data should return data from cobrand module') or diag("Got $cobrand_data");
+
+ # should return an empty string if no cobrand module exists
+ $q = new MockQuery('nosite');
+ $cobrand_data = Cobrand::extra_problem_data('nosite', $q);
+ ok($cobrand_data eq '', 'extra_problem_data should return an empty string if there is no cobrand module') or diag("Got $cobrand_data");
+}
+
+sub test_extra_update_data {
+ my $cobrand = 'mysite';
+ my $q = new MockQuery($cobrand);
+
+ # should get the result of the page function in the cobrand module if one exists
+ my $cobrand_data = Cobrand::extra_update_data($cobrand, $q);
+ ok($cobrand_data eq 'Cobrand update data', 'extra_update_data should return data from cobrand module') or diag("Got $cobrand_data");
+
+ # should return an empty string if no cobrand module exists
+ $q = new MockQuery('nosite');
+ $cobrand_data = Cobrand::extra_update_data('nosite', $q);
+ ok($cobrand_data eq '', 'extra_update_data should return an empty string if there is no cobrand module') or diag("Got $cobrand_data");
+}
+
sub test_base_url {
my $cobrand = 'mysite';
@@ -99,7 +127,7 @@ sub test_base_url_for_emails {
# should get the results of the base_url_for_emails function in the cobrand module if one exists
my $base_url = Cobrand::base_url_for_emails($cobrand);
- is('http://mysite.foremails.example.com', $base_url, 'base_url_for_emails returns output from cobrand module');
+ is('http://mysite.foremails.example.com', $base_url, 'base_url_for_emails returns output from cobrand module') ;
# should return the result of Cobrand::base_url otherwise
$cobrand = 'nosite';
@@ -108,6 +136,21 @@ sub test_base_url_for_emails {
}
+sub test_extra_params {
+ my $cobrand = 'mysite';
+ my $q = new MockQuery($cobrand);
+
+ # should get the results of the extra_params function in the cobrand module if one exists
+ my $extra_params = Cobrand::extra_params($cobrand, $q);
+ is($extra_params, 'key=value', 'extra_params returns output from cobrand module') ;
+
+ # should return an empty string otherwise
+ $cobrand = 'nosite';
+ $extra_params = Cobrand::extra_params($cobrand, $q);
+ is($extra_params, '', 'extra_params returns an empty string 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');
@@ -115,3 +158,6 @@ 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');
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');