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
|
#!/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.7 2009-09-15 17:42:43 louise Exp $
#
use strict;
use warnings;
use Test::More tests => 20;
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_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');
}
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');
|