diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-02-23 22:10:37 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-02-23 22:10:37 +0000 |
commit | 3ef36c3c9b5393c78c0af59b9f4e3f4528472357 (patch) | |
tree | 74e1118ae16bdd0e7cbb9f206248883c59de51e0 /t/cobrand/loading.t | |
parent | b6ef8d10c3ec7164c65d81b75ecf2662952aeb6d (diff) |
More work on the Cobrand and setting for request
test to see welsh about us page
Diffstat (limited to 't/cobrand/loading.t')
-rw-r--r-- | t/cobrand/loading.t | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/t/cobrand/loading.t b/t/cobrand/loading.t new file mode 100644 index 000000000..aa74bbb91 --- /dev/null +++ b/t/cobrand/loading.t @@ -0,0 +1,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(); |