aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Cobrand.pm246
-rw-r--r--perllib/CrossSell.pm16
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm7
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm7
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/FiksGataMi.pm2
-rw-r--r--perllib/FixMyStreet/Geocode.pm1
-rw-r--r--perllib/FixMyStreet/Map.pm1
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original.pm1
-rw-r--r--perllib/Problems.pm4
-rw-r--r--perllib/Standard.pm40
-rwxr-xr-xt/Cobrand.t273
-rw-r--r--t/Cobrands/Mysite/Util.pm104
14 files changed, 14 insertions, 692 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
deleted file mode 100644
index 7d4382583..000000000
--- a/perllib/Cobrand.pm
+++ /dev/null
@@ -1,246 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Cobrand.pm:
-# Cobranding for FixMyStreet.
-#
-#
-# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
-# Email: louise@mysociety.org. WWW: http://www.mysociety.org
-#
-# $Id: Cobrand.pm,v 1.58 2010-01-06 12:33:25 louise Exp $
-
-package Cobrand;
-use strict;
-use Carp;
-
-=item get_allowed_cobrands
-
-Return an array reference of allowed cobrand subdomains
-
-=cut
-sub get_allowed_cobrands {
- my $allowed_cobrand_string = mySociety::Config::get('ALLOWED_COBRANDS');
- my @allowed_cobrands = split(/\|/, $allowed_cobrand_string);
- return \@allowed_cobrands;
-}
-
-# Cobrand calling functions
-my %fns = (
- # Return a site restriction clause and a site key if the cobrand uses a subset of the FixMyStreet
- # data. Parameter is any extra data the cobrand needs. Returns an empty string and site key 0
- # if the cobrand uses all the data.
- 'site_restriction' => { default => '["", 0]' },
- # Return a contact restriction clause if the cobrand uses a subset of the FixMyStreet contact data.
- 'contact_restriction' => { default => "''" },
- # Return the base url to use in links in emails for the cobranded version of the site, parameter is extra data.
- 'base_url_for_emails' => { default => 'base_url($cobrand)' },
- # Base URL for the admin interface.
- 'admin_base_url' => { default => '0' },
- # URL for writetothem; parameter is COBRAND_DATA.
- 'writetothem_url' => { default => '0' },
- # Return the base url for the cobranded version of the site
- 'base_url' => { default => "mySociety::Config::get('BASE_URL')" },
- # Return the text that prompts the user to enter their postcode/place name. Parameter is QUERY
- 'enter_postcode_text' => { default => '""' },
- # Set the language and domain of the site based on the cobrand and host
- 'set_lang_and_domain' => { default => '\&default_set_lang_and_domain' },
- # Return HTML for a list of alert options for the cobrand, given QUERY and OPTIONS.
- 'alert_list_options' => { default => '0' },
- # Return N recent photos. If EASTING, NORTHING and DISTANCE are supplied, the photos must be attached to problems
- # within DISTANCE of the point defined by EASTING and NORTHING.
- 'recent_photos' => { default => '\&Problems::recent_photos' },
- # Return recent problems on the site.
- 'recent' => { default => '\&Problems::recent' },
- # Given a QUERY, return a block of html for showing front stats for the site
- 'front_stats' => { default => '\&Problems::front_stats' },
- # Given a STRING ($_[1]) representing a location and a QUERY, return a string that
- # includes any disambiguating information available
- 'disambiguate_location' => { default => '"$_[1]&gl=uk"' },
- # Parameter is EPOCHTIME
- 'prettify_epoch' => { default => '0' },
- # Parameters are FORM_NAME, QUERY. Return HTML for any extra needed elements for FORM_NAME
- 'form_elements' => { default => "''" },
- # Parameter is UPDATE_DATA, a reference to a hash of non-cobranded update data. Return cobrand extra data for the update
- 'cobrand_data_for_generic_update' => { default => "''" },
- # Parameter is PROBLEM_DATA, a reference to a hash of non-cobranded problem data. Return cobrand extra data for the problem
- 'cobrand_data_for_generic_problem' => { default => "''" },
- # Parameter is QUERY. Return a string of extra data to be stored with a problem
- 'extra_problem_data' => { default => "''" },
- # Parameter is QUERY. Return a string of extra data to be stored with an update
- 'extra_update_data' => { default => "''" },
- # Parameter is QUERY. Return a string of extra data to be stored with an alert
- 'extra_alert_data' => { default => "''" },
- # Given a QUERY, extract any extra data required by the cobrand
- 'extra_data' => { default => "''" },
- # Returns any extra text to be displayed with a PROBLEM.
- 'extra_problem_meta_text' => { default => "''" },
- # Returns any extra text to be displayed with an UPDATE.
- 'extra_update_meta_text' => { default => "''" },
- # Given a URL ($_[1]), QUERY, EXTRA_DATA, return a URL with any extra params needed appended to it.
- 'url' => { default => '$_[1]' },
- # Return any params to be added to responses
- 'header_params' => { default => '{}' },
- # Parameter is QUERY. Return some js to set the root path from which AJAX
- # queries should be made.
- 'root_path_js' => { default => "'var root_path = \"\";'" },
- # Return the title to be used in page heads.
- 'site_title' => { default => "''" },
- # Return the maximum number of items to be given in the list of reports on the map
- 'on_map_list_limit' => { default => 'undef' },
- # Return a boolean indicating whether the cobrand allows photo uploads
- 'allow_photo_upload' => { default => '1' },
- # Return a boolean indicating whether the cobrand allows the display of crosssell adverts
- 'allow_crosssell_adverts' => { default => '1' },
- # Return a boolean indicating whether the cobrand allows photo display
- 'allow_photo_display' => { default => '1' },
- # Return a boolean indication whether users should see links next to updates allowing them
- # to report them as offensive.
- 'allow_update_reporting' => { default => '0' },
- # Parameters are LOCATION, QUERY. Return a boolean indicating whether the
- # string LOCATION passes the cobrands checks.
- 'geocoded_string_check' => { default => '1' },
- # Paramters are COUNCILS, QUERY, CONTEXT. Return a boolean indicating whether
- # COUNCILS pass any extra checks. CONTEXT is where we are on the site.
- 'council_check' => { default => "[1, '']" },
- # Return an XSL to be used in rendering feeds
- 'feed_xsl' => { default => "'/xsl.xsl'" },
- # Return a boolean indicating whether the cobrand displays a report of all councils
- 'all_councils_report' => { default => '1' },
- # Return a boolean indicating whether people should be asked whether this
- # is the first time they've reported a problem.
- 'ask_ever_reported' => { default => '1' },
- # List of names of pages to display on the admin interface
- 'admin_pages' => { default => '0' },
- # Show the problem creation graph in the admin interface
- 'admin_show_creation_graph' => { default => '1' },
- # The MaPit types this site handles
- 'area_types' => { default => '[qw(DIS LBO MTD UTA CTY COI)]' },
- 'area_min_generation' => { default => '10' },
- # Some cobrands that use a Tilma map have a smaller mid-point to make pin centred
- 'tilma_mid_point' => { default => '""' },
-);
-
-foreach (keys %fns) {
- die "Default must be specified for $_" unless $fns{$_}{default} ne '';
- eval <<EOF;
-sub $_ {
- my (\$cobrand, \@args) = \@_;
- return call(\$cobrand, '$_', $fns{$_}{default}, \@args);
-}
-EOF
-}
-
-# This is the main Cobrand calling function that sees if the Cobrand handles
-# the function and responds appropriately.
-sub call {
- my ($cobrand, $fn, $default, @args) = @_;
- return call_default($default, @args) unless $cobrand;
- my $handle = cobrand_handle($cobrand);
- return call_default($default, @args) unless $handle && $handle->can($fn);
- return $handle->$fn(@args);
-}
-
-# If we're not in a Cobrand, or the Cobrand module doesn't offer a function,
-# this function works out how to return the default response
-sub call_default {
- my ($default, @args) = @_;
- return $default unless ref $default;
- return @$default if ref $default eq 'ARRAY'; # Arrays passed back as values
- return $default if ref $default eq 'HASH'; # Hashes passed back as reference
- return $default->(@args) if ref $default eq 'CODE'; # Functions are called.
- die "Default of $default treatment unknown";
-}
-
-=item cobrand_handle Q
-
-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_handle {
- my $cobrand = shift;
-
- our %handles;
-
- # Once we have a handle defined, return it.
- return $handles{$cobrand} if defined $handles{$cobrand};
-
- my $cobrand_class = ucfirst($cobrand);
- my $class = "Cobrands::" . $cobrand_class . "::Util";
- eval "use $class";
-
- eval{ $handles{$cobrand} = $class->new };
- $handles{$cobrand} = 0 if $@;
- return $handles{$cobrand};
-}
-
-# Cobrand functions to fetch config variables
-%fns = (
- # Return the contact name for the cobranded version of the site
- # (to be used in emails).
- 'contact_name' => 'CONTACT_NAME',
- # Return the contact email for the cobranded version of the site
- 'contact_email' => 'CONTACT_EMAIL',
-);
-
-foreach (keys %fns) {
- eval <<EOF;
-sub $_ {
- my \$cobrand = shift;
- return get_cobrand_conf(\$cobrand, '$fns{$_}');
-}
-EOF
-}
-
-=item get_cobrand_conf COBRAND KEY
-
-Get the value for KEY from the config file for COBRAND
-
-=cut
-sub get_cobrand_conf {
- my ($cobrand, $key) = @_;
- my $value;
- if ($cobrand){
- (my $dir = __FILE__) =~ s{/[^/]*?$}{};
- if (-e "$dir/../conf/cobrands/$cobrand/general"){
- mySociety::Config::set_file("$dir/../conf/cobrands/$cobrand/general");
- $cobrand = uc($cobrand);
- $value = mySociety::Config::get($key . "_" . $cobrand, undef);
- mySociety::Config::set_file("$dir/../conf/general");
- }
- }
- if (!defined($value)){
- $value = mySociety::Config::get($key);
- }
- return $value;
-}
-
-=item email_host COBRAND
-
-Return the virtual host that sends email for this cobrand
-
-=cut
-
-sub email_host {
- my ($cobrand) = @_;
- my $email_vhost = mySociety::Config::get('EMAIL_VHOST');
- if ($cobrand) {
- $email_vhost = mySociety::Config::get('EMAIL_VHOST_'. uc($cobrand), $email_vhost);
- }
- if ($email_vhost && 'http://' . $email_vhost eq mySociety::Config::get('BASE_URL')) {
- return 1;
- } else {
- return 0;
- }
-}
-
-# Default things to do for the set_lang_and_domain call
-sub default_set_lang_and_domain {
- my ($lang, $unicode) = @_;
- mySociety::Locale::negotiate_language('en-gb,English,en_GB|nb,Norwegian,nb_NO', $lang); # XXX Testing
- mySociety::Locale::gettext_domain('FixMyStreet', $unicode);
- mySociety::Locale::change();
-}
-
-1;
-
diff --git a/perllib/CrossSell.pm b/perllib/CrossSell.pm
index e40f2166f..44f971462 100644
--- a/perllib/CrossSell.pm
+++ b/perllib/CrossSell.pm
@@ -197,14 +197,14 @@ EOF
# Choose appropriate advert and display it.
# $this_site is to stop a site advertising itself.
sub display_advert ($$;$%) {
- my ($q, $email, $name, %data) = @_;
+ my ($c, $email, $name, %data) = @_;
- return '' unless $q->{site} eq 'fixmystreet';
+ return '' unless $c->cobrand->is_default;
if (defined $data{council} && $data{council} eq '2326') {
my ($out, $ad) = display_hfyc_cheltenham_advert($email, $name);
if ($out) {
- $q->{scratch} = "advert=$ad";
+ $c->stash->{scratch} = "advert=$ad";
return $out;
}
}
@@ -212,17 +212,17 @@ sub display_advert ($$;$%) {
#if ($data{lat}) {
# my $out = display_gny_groups($data{lon}, $data{lat});
# if ($out) {
- # $q->{scratch} = 'advert=gnygroups';
+ # $c->stash->{scratch} = 'advert=gnygroups';
# return '<div style="margin: 0 5em; border-top: dotted 1px #666666;">'
# . $out . '</div>';
# }
#}
- #$q->{scratch} = 'advert=demclub0';
+ #$c->stash->{scratch} = 'advert=demclub0';
#return display_democracyclub();
#unless (defined $data{done_tms} && $data{done_tms}==1) {
- $q->{scratch} = 'advert=news';
+ $c->stash->{scratch} = 'advert=news';
my $auth_signature = '';
unless (defined $data{emailunvalidated} && $data{emailunvalidated}==1) {
$auth_signature = mySociety::AuthToken::sign_with_shared_secret($email, mySociety::Config::get('AUTH_SHARED_SECRET'));
@@ -250,7 +250,7 @@ sub display_advert ($$;$%) {
my $out = &$func($email, $name, $advert_text);
use strict 'refs';
if ($out) {
- $q->{scratch} = "advert=$advert_id";
+ $c->stash->{scratch} = "advert=$advert_id";
return $out;
}
@@ -260,7 +260,7 @@ sub display_advert ($$;$%) {
}
}
- $q->{scratch} = 'advert=pb';
+ $c->stash->{scratch} = 'advert=pb';
return <<EOF;
<div id="advert_thin" style="text-align:center">
<h2 style="font-size: 150%">
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 579ee9b41..b76447233 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -73,7 +73,7 @@ sub index : Path : Args(0) {
$c->stash->{alerts} = \%alert_counts;
- my $contacts = $c->model('DB::Contact')->summary_count;
+ my $contacts = $c->model('DB::Contact')->summary_count( $c->cobrand->contact_restriction );
my %contact_counts =
map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index c14b7e9b1..5c52d0257 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -118,13 +118,6 @@ sub report_import : Path('/import') {
# anything else we return is plain text
$c->res->content_type('text/plain; charset=utf-8');
- # use strict;
- # use Standard;
- # use mySociety::AuthToken;
- # use mySociety::Config;
- # use mySociety::EvEl;
- # use mySociety::Locale;
-
my %input =
map { $_ => $c->req->param($_) || '' } (
'service', 'subject', 'detail', 'name', 'email', 'phone',
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index 5b20e286b..358e280c3 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -84,12 +84,7 @@ sub display_crosssell_advert {
my ( $self, $c, $email, $name, %data ) = @_;
return unless $c->cobrand->allow_crosssell_adverts();
-
- # fake up the old style $q
- my $q = { site => $c->cobrand->moniker, };
- $q->{site} = 'fixmystreet' if $q->{site} eq 'default';
-
- return CrossSell::display_advert( $q, $email, $name, %data );
+ return CrossSell::display_advert( $c, $email, $name, %data );
}
=head2 Utils::prettify_epoch
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index e02b208dc..b002dd7f2 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -87,7 +87,7 @@ FixMyStreet contact data.
=cut
sub contact_restriction {
- '';
+ {};
}
=head2 base_url_for_emails
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
index 4dd2ef49a..eb7ea89a5 100644
--- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
+++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
@@ -16,7 +16,7 @@ sub set_lang_and_domain {
}
sub enter_postcode_text {
- my ( $self, $q ) = @_;
+ my ( $self ) = @_;
return _('Enter a nearby postcode, or street name and area');
}
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index 50a7ba339..a520a2daa 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -17,7 +17,6 @@ use LWP::Simple;
use Digest::MD5 qw(md5_hex);
use URI::Escape;
-use Cobrand;
use Utils;
use mySociety::Config;
use mySociety::Locale;
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index fc3f318c2..6b41c8d0d 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -20,7 +20,6 @@ use Module::Pluggable
my @ALL_MAP_CLASSES = allowed_maps();
use Problems;
-use Cobrand;
use mySociety::Config;
use mySociety::Gaze;
use mySociety::Locale;
diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm
index 75177f3af..486a7c739 100644
--- a/perllib/FixMyStreet/Map/Tilma/Original.pm
+++ b/perllib/FixMyStreet/Map/Tilma/Original.pm
@@ -11,7 +11,6 @@ package FixMyStreet::Map::Tilma::Original;
use strict;
use LWP::Simple;
-use Cobrand;
use mySociety::GeoUtil;
use mySociety::Locale;
use mySociety::Web qw(ent NewURL);
diff --git a/perllib/Problems.pm b/perllib/Problems.pm
index c1430b540..c31fdd507 100644
--- a/perllib/Problems.pm
+++ b/perllib/Problems.pm
@@ -447,8 +447,8 @@ the cobrand if a cobrand is specified.
=cut
sub contact_counts {
- my ($cobrand) = @_;
- my $contact_restriction = Cobrand::contact_restriction($cobrand);
+ my ( $c ) = @_;
+ my $contact_restriction = $c->cobrand->contact_restriction;
my $contacts = dbh()->selectcol_arrayref("select confirmed, count(*) as c from contacts $contact_restriction group by confirmed", { Columns => [1,2] });
return $contacts;
}
diff --git a/perllib/Standard.pm b/perllib/Standard.pm
deleted file mode 100644
index 0a6f27490..000000000
--- a/perllib/Standard.pm
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/perl
-#
-# Standard.pm:
-# Common headers for Perl files. Mostly in the main namespace on purpose
-# (Filter::Macro sadly didn't work, CPAN bug #20494)
-#
-# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
-# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: Standard.pm,v 1.3 2009-09-15 13:57:01 louise Exp $
-
-use strict;
-use warnings;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../commonlib/perllib";
-
-package Standard;
-
-sub import {
- my $package = shift;
- my $db = shift;
- unless ($db && $db eq '-db') {
- use mySociety::Config;
- use mySociety::DBHandle qw(dbh);
- (my $file = __FILE__) =~ s{/[^/]*?$}{};
- mySociety::Config::set_file("$file/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
- *main::dbh = \&dbh;
- }
-}
diff --git a/t/Cobrand.t b/t/Cobrand.t
deleted file mode 100755
index 047fcc71c..000000000
--- a/t/Cobrand.t
+++ /dev/null
@@ -1,273 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Cobrand.t:
-# Tests for the cobranding functions
-#
-# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
-# Email: louise@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: Cobrand.t,v 1.25 2009-12-16 12:43:12 matthew Exp $
-#
-
-use strict;
-use warnings;
-use Test::More tests => 56;
-use Test::Exception;
-use Error qw(:try);
-
-use FindBin;
-use lib "$FindBin::Bin";
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../commonlib/perllib";
-
-use Cobrand;
-use Problems;
-use mySociety::MockQuery;
-use mySociety::Config;
-
-BEGIN {
- (my $dir = __FILE__) =~ s{/[^/]*?$}{};
- mySociety::Config::set_file("$dir/../conf/general");
-}
-
-sub test_site_restriction {
- my ($site_restriction, $site_id) = Cobrand::site_restriction('mysite', 'test');
- like($site_restriction, qr/ and council = 1 /, 'should return result of cobrand module site_restriction function');
- ok($site_id == 99, 'should return result of cobrand module site_restriction function');
-
- ($site_restriction, $site_id) = Cobrand::site_restriction('nosite', 'test');
- ok($site_restriction eq '', 'should return "" and zero if no module exists' );
- ok($site_id == 0, 'should return "" and zero if no module exists');
-}
-
-sub test_form_elements {
- my $q = new MockQuery('mysite');
- my $element_html = Cobrand::form_elements('mysite', 'postcodeForm', $q);
- ok($element_html eq 'Extra html', 'should return result of cobrand module element_html function') or diag("Got $element_html");
-
- $element_html = Cobrand::form_elements('nosite', 'postcodeForm', $q);
- ok($element_html eq '', 'should return an empty string if no cobrand module exists') or diag("Got $element_html");
-}
-
-sub test_disambiguate_location {
- my $q = new MockQuery('mysite');
- my $s = 'London Road';
- $s = Cobrand::disambiguate_location('mysite', $s, $q);
- ok($s eq 'Specific Location', 'should return result of cobrand module disambiguate_location function') or diag("Got $s");;
-
- $q = new MockQuery('nosite');
- $s = 'London Road';
- $s = Cobrand::disambiguate_location('nosite', $s, $q);
- ok($s eq 'London Road&gl=uk', 'should return location string as passed if no cobrand module exists') or diag("Got $s");
-
-}
-
-sub test_cobrand_handle {
- my $cobrand = 'mysite';
- my $handle = Cobrand::cobrand_handle($cobrand);
- like($handle->site_name(), qr/mysite/, 'should get a module handle if Util module exists for cobrand');
- $cobrand = 'nosite';
- $handle = Cobrand::cobrand_handle($cobrand);
- ok($handle == 0, 'should return zero if no module exists');
-}
-
-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_extra_alert_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_alert_data($cobrand, $q);
- ok($cobrand_data eq 'Cobrand alert data', 'extra_alert_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_alert_data('nosite', $q);
- ok($cobrand_data eq '', 'extra_alert_data should return an empty string if there is no cobrand module') or diag("Got $cobrand_data");
-}
-
-sub test_base_url {
- my $cobrand = 'mysite';
-
- # should get the result of the page function in the cobrand module if one exists
- my $base_url = Cobrand::base_url($cobrand);
- is('http://mysite.example.com', $base_url, 'base_url returns output from cobrand module');
-
- # should return the base url from the config if there is no cobrand module
- $cobrand = 'nosite';
- $base_url = Cobrand::base_url($cobrand);
- is(mySociety::Config::get('BASE_URL'), $base_url, 'base_url returns config base url if no cobrand module');
-
-}
-
-sub test_base_url_for_emails {
- my $cobrand = 'mysite';
-
- # 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') ;
-
- # should return the result of Cobrand::base_url otherwise
- $cobrand = 'nosite';
- $base_url = Cobrand::base_url_for_emails($cobrand);
- is(mySociety::Config::get('BASE_URL'), $base_url, 'base_url_for_emails returns config base url if no cobrand module');
-
-}
-
-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');
-}
-
-sub test_root_path_js {
- my $cobrand = 'mysite';
- my $root_path_js = Cobrand::root_path_js($cobrand);
-
- # should get the results of the root_path_js function in the cobrand module if one exists
- is($root_path_js, 'root path js', 'root_path_js returns output from cobrand module');
-
- # should return a js string setting the root path to an empty string otherwise
- $cobrand = 'nosite';
- $root_path_js = Cobrand::root_path_js($cobrand);
- is($root_path_js, 'var root_path = "";', 'root_path_pattern returns a string setting the root path to an empty string if no cobrand module');
-}
-
-sub test_site_title {
- my $cobrand = 'mysite';
- my $site_title = Cobrand::site_title($cobrand);
-
- # should get the results of the site_title function in the cobrand module if one exists
- is($site_title, 'Mysite Title', 'site_title returns output from cobrand module');
-
- # should return an empty string otherwise
- $cobrand = 'nosite';
- $site_title = Cobrand::site_title($cobrand);
- is($site_title, '', 'site_title returns an empty string if no site title');
-}
-
-sub test_on_map_list_limit {
- my $cobrand = 'mysite';
- my $limit = Cobrand::on_map_list_limit($cobrand);
-
- 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');
-
-}
-
-sub test_url {
- my $cobrand = 'mysite';
- my $q = new MockQuery('mysite');
- my $url = Cobrand::url($cobrand, '/xyz', $q);
- is($url, '/transformed_url', 'url returns output from cobrand module');
-
- $cobrand = 'nosite';
- $url = Cobrand::url($cobrand, '/xyz', $q);
- is($url, '/xyz', 'url returns passed url if there is no url function defined by the cobrand');
-}
-
-sub test_allow_photo_upload {
- my $cobrand = 'mysite';
- my $photo_upload = Cobrand::allow_photo_upload($cobrand);
- is($photo_upload, 0, 'allow_photo_upload returns output from cobrand module');
-
- $cobrand = 'nosite';
- $photo_upload = Cobrand::allow_photo_upload($cobrand);
- is($photo_upload, 1, 'allow_photo_upload returns 1 if there is no allow_photo_upload function defined by the cobrand');
-}
-
-sub test_allow_photo_display {
- my $cobrand = 'mysite';
- my $photo_display = Cobrand::allow_photo_display($cobrand);
- is($photo_display, 0, 'allow_photo_display returns output from cobrand module');
-
- $cobrand = 'nosite';
- $photo_display = Cobrand::allow_photo_display($cobrand);
- is($photo_display, 1, 'allow_photo_display returns 1 if there is no allow_photo_display function defined by the cobrand');
-}
-
-sub test_council_check {
- my $cobrand = 'mysite';
- my $councils = {};
- my $query = new MockQuery('mysite');
- my ($check_result, $error) = Cobrand::council_check($cobrand, $councils, $query);
- is($check_result, 0, 'council_check returns output from cobrand module');
-
- $cobrand = 'nosite';
- ($check_result, $error) = Cobrand::council_check($cobrand, $councils, $query);
- is($check_result, 1, 'council_check returns 1 if there is no council_check function defined by the cobrand');
-}
-
-sub test_recent {
- my $cobrand = 'mysite';
- my $check_result = Cobrand::recent($cobrand);
- is_deeply($check_result, [ { id => 1, title => 'Title 1' }, { id => 2, title => 'Title 2' } ], 'recent returns output from cobrand module');
-
- # Can't test default here as calls database. So test it throws a db not configured error :)
- my $error;
- $cobrand = 'nosite';
- try {
- $check_result = Cobrand::recent($cobrand);
- } catch Error with {
- $error = shift;
- };
- ok($error =~ /^configure not yet called in new_dbh/, 'Default throws a database error');
-}
-
-ok(test_cobrand_handle() == 1, 'Ran all tests for the cobrand_handle function');
-ok(test_site_restriction() == 1, 'Ran all tests for the site_restriction function');
-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_alert_data() == 1, 'Ran all tests for extra_alert_data');
-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');
-ok(test_allow_photo_upload() == 1, 'Ran all tests for allow_photo_upload');
-ok(test_allow_photo_display() == 1, 'Ran all tests for allow_photo_display');
-ok(test_council_check() == 1, 'Ran all tests for council_check');
-ok(test_recent() == 1, 'Ran all tests for recent');
diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm
deleted file mode 100644
index b733cb5b7..000000000
--- a/t/Cobrands/Mysite/Util.pm
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Util.pm:
-# Test Cobranding for FixMyStreet.
-#
-#
-# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
-# Email: louise@mysociety.org. WWW: http://www.mysociety.org
-#
-# $Id: Util.pm,v 1.20 2009-12-16 12:43:13 matthew Exp $
-
-package Cobrands::Mysite::Util;
-use strict;
-use Carp;
-use mySociety::Web qw(ent);
-
-sub new {
- my $class = shift;
- 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);
-}
-
-sub base_url {
- return 'http://mysite.example.com';
-}
-
-sub base_url_for_emails {
- return 'http://mysite.foremails.example.com';
-}
-
-sub disambiguate_location {
- return 'Specific Location';
-}
-
-sub form_elements {
- return "Extra html";
-}
-
-sub extra_problem_data {
- return "Cobrand problem data";
-}
-
-sub extra_update_data {
- return "Cobrand update data";
-}
-
-sub extra_alert_data {
- return "Cobrand alert data";
-}
-
-sub header_params {
- my %params = ('key' => 'value');
- return \%params;
-}
-
-
-sub root_path_js {
- return 'root path js';
-}
-
-sub site_title {
- return 'Mysite Title';
-}
-
-sub on_map_list_limit {
- return 30;
-}
-
-sub url {
- return '/transformed_url';
-}
-
-sub allow_photo_upload {
- return 0;
-}
-
-sub allow_photo_display {
- return 0;
-}
-
-sub council_check {
- return 0;
-}
-
-sub recent {
- return [
- { id => 1, title => 'Title 1' },
- { id => 2, title => 'Title 2' }
- ];
-}
-
-1;