1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
#!/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.10 2009-09-22 15:56:44 louise Exp $
#
use strict;
use warnings;
use Test::More tests => 35;
use Test::Exception;
use FindBin;
use lib "$FindBin::Bin";
use lib "$FindBin::Bin/../perllib";
use lib "$FindBin::Bin/../../perllib";
use Cobrand;
use MockQuery;
sub test_site_restriction {
my $q = new MockQuery('mysite');
my ($site_restriction, $site_id) = Cobrand::set_site_restriction($q);
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');
$q = new MockQuery('nosite');
($site_restriction, $site_id) = Cobrand::set_site_restriction($q);
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', '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_cobrand_page {
my $q = new MockQuery('mysite');
# should get the result of the page function in the cobrand module if one exists
my ($html, $params) = Cobrand::cobrand_page($q);
like($html, qr/A cobrand produced page/, 'cobrand_page returns output from cobrand module');
# should return 0 if no cobrand module exists
$q = new MockQuery('mynonexistingsite');
($html, $params) = Cobrand::cobrand_page($q);
is($html, 0, 'cobrand_page returns 0 if there is no cobrand module');
return 1;
}
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';
# 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_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');
}
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');
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');
ok(test_header_params() == 1, 'Ran all tests for header_params');
|