aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand/loading.t
blob: aa74bbb91d0a3054a00fbbea004041fc8ecc847e (plain)
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
use strict;
use warnings;

use Test::More;
use Sub::Override;

use FixMyStreet;

use_ok 'FixMyStreet::Cobrand';

# check that the allowed cobrands is correctly loaded from config
{
    my $allowed = FixMyStreet::Cobrand->get_allowed_cobrands;
    ok $allowed,     "got the allowed_cobrands";
    isa_ok $allowed, "ARRAY";
    cmp_ok scalar @$allowed, '>', 1, "got more than one";
    is join( '|', @$allowed ), FixMyStreet->config('ALLOWED_COBRANDS'),
      "matches config value";
}

# fake the allowed cobrands for testing
my $override = Sub::Override->new(    #
    'FixMyStreet::Cobrand::get_allowed_cobrands' =>
      sub { return ['emptyhomes'] }
);
is_deeply FixMyStreet::Cobrand->get_allowed_cobrands, ['emptyhomes'],
  'overidden get_allowed_cobrands';

sub run_host_tests {
    my %host_tests = @_;
    for my $host ( sort keys %host_tests ) {
        is FixMyStreet::Cobrand->get_class_for_host($host),
          "FixMyStreet::Cobrand::$host_tests{$host}",
          "does $host -> F::C::$host_tests{$host}";
    }
}

# get the cobrand class by host
run_host_tests(
    'www.fixmystreet.com'    => 'Default',
    'reportemptyhomes.com'   => 'EmptyHomes',
    'barnet.fixmystreet.com' => 'Default',    # not in the allowed_cobrands list
    'some.odd.site.com'      => 'Default',
);

# now enable barnet too and check that it works
$override->replace(                           #
    'FixMyStreet::Cobrand::get_allowed_cobrands' =>
      sub { return [ 'emptyhomes', 'barnet' ] }
);

# get the cobrand class by host
run_host_tests(
    'www.fixmystreet.com'  => 'Default',
    'reportemptyhomes.com' => 'EmptyHomes',
    'barnet.fixmystreet.com' => 'Barnet',  # found now it is in allowed_cobrands
    'some.odd.site.com'      => 'Default',
);

# check that the moniker works as expected both on class and object.
is FixMyStreet::Cobrand::EmptyHomes->moniker, 'emptyhomes',
  'class->moniker works';
is FixMyStreet::Cobrand::EmptyHomes->new->moniker, 'emptyhomes',
  'object->moniker works';

# all done
done_testing();