diff options
-rw-r--r-- | perllib/Cobrand.pm | 13 | ||||
-rwxr-xr-x | t/Cobrand.t | 27 | ||||
-rw-r--r-- | t/Cobrands/Mysite/Util.pm | 6 |
3 files changed, 35 insertions, 11 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm index 32bf35377..3cd0fd03a 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.25 2009-10-07 08:18:42 louise Exp $ +# $Id: Cobrand.pm,v 1.26 2009-10-13 09:24:09 louise Exp $ package Cobrand; use strict; @@ -367,7 +367,16 @@ 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); + my $handle; + if ($cobrand){ + $handle = cobrand_handle($cobrand); + } + if ( !$cobrand || !$handle || !$handle->can('url')){ + return $url; + } else{ + return $handle->url($url); + } + return $url; } =item header_params diff --git a/t/Cobrand.t b/t/Cobrand.t index 21c601987..b0921213d 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.15 2009-10-07 08:18:42 louise Exp $ +# $Id: Cobrand.t,v 1.16 2009-10-13 09:24:09 louise Exp $ # use strict; use warnings; -use Test::More tests => 47; +use Test::More tests => 50; use Test::Exception; use FindBin; @@ -206,15 +206,25 @@ sub test_site_title { } sub test_on_map_list_limit { - my $cobrand = 'mysite'; - my $limit = Cobrand::on_map_list_limit($cobrand); + my $cobrand = 'mysite'; + my $limit = Cobrand::on_map_list_limit($cobrand); - is($limit, 30, 'on_map_list_limit returns output from cobrand module'); + is($limit, 30, 'on_map_list_limit returns output from cobrand module'); + + $cobrand = 'nosite'; + $limit = Cobrand::on_map_list_limit($cobrand); + is($limit, undef, 'on_map_list_limit returns undef if there is no limit defined by the cobrand'); - $cobrand = 'nosite'; - $limit = Cobrand::on_map_list_limit($cobrand); - is($limit, undef, 'on_map_list_limit returns undef if there is no limit defined by the cobrand'); +} +sub test_url { + my $cobrand = 'mysite'; + my $url = Cobrand::url($cobrand, '/xyz'); + is($url, '/transformed_url', 'url returns output from cobrand module'); + + $cobrand = 'nosite'; + $url = Cobrand::url($cobrand, '/xyz'); + is($url, '/xyz', 'url returns passed url if there is no url function defined by the cobrand'); } ok(test_cobrand_handle() == 1, 'Ran all tests for the cobrand_handle function'); @@ -232,3 +242,4 @@ ok(test_header_params() == 1, 'Ran all tests for header_params'); ok(test_root_path_js() == 1, 'Ran all tests for root_js'); ok(test_site_title() == 1, 'Ran all tests for site_title'); ok(test_on_map_list_limit() == 1, 'Ran all tests for on_map_list_limit'); +ok(test_url() == 1, 'Ran all tests for url'); diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm index e39e378d8..2ee49ad13 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.14 2009-10-07 08:18:42 louise Exp $ +# $Id: Util.pm,v 1.15 2009-10-13 09:24:37 louise Exp $ package Cobrands::Mysite::Util; use Page; @@ -82,4 +82,8 @@ sub site_title { sub on_map_list_limit { return 30; } + +sub url { + return '/transformed_url'; +} 1; |