aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/about.t10
-rw-r--r--t/cobrand/loading.t67
2 files changed, 75 insertions, 2 deletions
diff --git a/t/app/controller/about.t b/t/app/controller/about.t
index 2ac628367..adbce8f25 100644
--- a/t/app/controller/about.t
+++ b/t/app/controller/about.t
@@ -11,8 +11,14 @@ $mech->get_ok('/about');
$mech->content_contains('FixMyStreet.com');
# check that geting the page as EHA produces a different page
-ok $mech->host("www.reportemptyhomes.co.uk"), 'change host to reportemptyhomes';
+ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes';
$mech->get_ok('/about');
-$mech->content_lacks('FixMyStreet.com');
+$mech->content_contains('The Empty Homes Agency');
+
+# check that geting the page as EHA in welsh produces a different page
+ok $mech->host("cy.reportemptyhomes.co.uk"),
+ 'change host to cy.reportemptyhomes';
+$mech->get_ok('/about');
+$mech->content_contains('Yr Asiantaeth Tai Gwag');
done_testing();
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();