aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Cobrand.pm19
-rwxr-xr-xt/Cobrand.t18
-rw-r--r--t/Cobrands/Mysite/Util.pm6
3 files changed, 39 insertions, 4 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
index 079f9957c..0030c2ccf 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.19 2009-09-22 15:56:44 louise Exp $
+# $Id: Cobrand.pm,v 1.20 2009-09-23 11:31:31 louise Exp $
package Cobrand;
use strict;
@@ -365,6 +365,23 @@ sub header_params {
}
}
+=item root_path_pattern COBRAND
+
+=cut
+
+sub root_path_pattern {
+ my ($cobrand) = @_;
+ my $handle;
+ if ($cobrand){
+ $handle = cobrand_handle($cobrand);
+ }
+ if ( !$cobrand || !$handle || !$handle->can('root_path_pattern')){
+ return '//g';
+ } else{
+ return $handle->root_path_pattern();
+ }
+}
+
1;
diff --git a/t/Cobrand.t b/t/Cobrand.t
index 22ac4cd83..28dbeaf6b 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.10 2009-09-22 15:56:44 louise Exp $
+# $Id: Cobrand.t,v 1.11 2009-09-23 11:31:32 louise Exp $
#
use strict;
use warnings;
-use Test::More tests => 35;
+use Test::More tests => 38;
use Test::Exception;
use FindBin;
@@ -164,6 +164,19 @@ sub test_header_params {
is_deeply($header_params, {}, 'header_params returns an empty hash ref if no cobrand module');
}
+sub test_root_path_pattern {
+ my $cobrand = 'mysite';
+ my $root_path_pattern = Cobrand::root_path_pattern($cobrand);
+
+ # should get the results of the root_path_pattern function in the cobrand module if one exists
+ is($root_path_pattern, 'root path pattern', 'root_path_pattern returns output from cobrand module');
+
+ # should return an empty regex string otherwise
+ $cobrand = 'nosite';
+ $root_path_pattern = Cobrand::root_path_pattern($cobrand);
+ is($root_path_pattern, '//g', 'root_path_pattern returns an empty regex 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');
@@ -175,3 +188,4 @@ 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');
+ok(test_root_path_pattern() == 1, 'Ran all tests for root_path_pattern');
diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm
index d90aad6df..9ddd4c01e 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.9 2009-09-22 15:56:44 louise Exp $
+# $Id: Util.pm,v 1.10 2009-09-23 11:31:32 louise Exp $
package Cobrands::Mysite::Util;
use Page;
@@ -66,4 +66,8 @@ sub header_params {
return \%params;
}
+
+sub root_path_pattern {
+ return 'root path pattern';
+}
1;