aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/01app.t10
-rw-r--r--t/app/02pod.t10
-rw-r--r--t/app/03podcoverage.t14
-rw-r--r--t/app/controller/about.t24
-rw-r--r--t/app/load_general_config.t13
-rw-r--r--t/app/page_not_found.t20
-rw-r--r--t/app/view_Web.t8
-rw-r--r--t/cobrand/loading.t67
-rw-r--r--t/fixmystreet.t37
9 files changed, 203 insertions, 0 deletions
diff --git a/t/app/01app.t b/t/app/01app.t
new file mode 100644
index 000000000..02ffcd217
--- /dev/null
+++ b/t/app/01app.t
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Catalyst::Test 'FixMyStreet::App';
+
+ok( request('/')->is_success, 'Request should succeed' );
+
+done_testing();
diff --git a/t/app/02pod.t b/t/app/02pod.t
new file mode 100644
index 000000000..ababc2eaa
--- /dev/null
+++ b/t/app/02pod.t
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+eval "use Test::Pod 1.14";
+plan skip_all => 'Test::Pod 1.14 required' if $@;
+
+all_pod_files_ok();
diff --git a/t/app/03podcoverage.t b/t/app/03podcoverage.t
new file mode 100644
index 000000000..6ddc5c6b6
--- /dev/null
+++ b/t/app/03podcoverage.t
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
+
+eval "use Pod::Coverage 0.20";
+plan skip_all => 'Pod::Coverage 0.20 required' if $@;
+
+all_pod_coverage_ok();
diff --git a/t/app/controller/about.t b/t/app/controller/about.t
new file mode 100644
index 000000000..adbce8f25
--- /dev/null
+++ b/t/app/controller/about.t
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
+
+ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' );
+
+# check that we can get the page
+$mech->get_ok('/about');
+$mech->content_contains('FixMyStreet.com');
+
+# check that geting the page as EHA produces a different page
+ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes';
+$mech->get_ok('/about');
+$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/app/load_general_config.t b/t/app/load_general_config.t
new file mode 100644
index 000000000..3855c2565
--- /dev/null
+++ b/t/app/load_general_config.t
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use_ok 'FixMyStreet::App';
+
+# GAZE_URL chosen as it is unlikely to change
+is FixMyStreet::App->config->{GAZE_URL}, #
+ 'http://gaze.mysociety.org/gaze', #
+ "check that known config param is loaded";
diff --git a/t/app/page_not_found.t b/t/app/page_not_found.t
new file mode 100644
index 000000000..9c8d7e5a6
--- /dev/null
+++ b/t/app/page_not_found.t
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
+
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+
+# homepage ok
+$mech->get_ok('/');
+
+# get 404 page
+my $path_to_404 = '/bad/path/page_not_found';
+my $res = $mech->get($path_to_404);
+ok !$res->is_success(), "want a bad response";
+is $res->code, 404, "got 404";
+$mech->content_contains($path_to_404);
diff --git a/t/app/view_Web.t b/t/app/view_Web.t
new file mode 100644
index 000000000..0f49b986b
--- /dev/null
+++ b/t/app/view_Web.t
@@ -0,0 +1,8 @@
+use strict;
+use warnings;
+use Test::More;
+use Test::More;
+
+BEGIN { use_ok 'FixMyStreet::App::View::Web' }
+
+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();
diff --git a/t/fixmystreet.t b/t/fixmystreet.t
new file mode 100644
index 000000000..d7f00b047
--- /dev/null
+++ b/t/fixmystreet.t
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+use Path::Class;
+
+use Test::More;
+use Test::Exception;
+
+use_ok 'FixMyStreet';
+
+# check that the path_to works
+my $file_path = file(__FILE__)->absolute->stringify;
+my $path_to_path = FixMyStreet->path_to('t/fixmystreet.t');
+
+isa_ok $path_to_path, 'Path::Class::File';
+ok $path_to_path->is_absolute, "path is absolute";
+is "$path_to_path", $file_path, "got $file_path";
+
+# check that the config gets loaded and is immutable
+my $config = FixMyStreet->config;
+isa_ok $config, 'HASH';
+is $config->{GAZE_URL}, 'http://gaze.mysociety.org/gaze',
+ "got GAZE_URL correctly";
+throws_ok(
+ sub { $config->{GAZE_URL} = 'some other value'; },
+ qr/Modification of a read-only value attempted/,
+ 'attempt to change config caught'
+);
+is $config->{GAZE_URL}, 'http://gaze.mysociety.org/gaze', "GAZE_URL unchanged";
+
+# check that we can get the value by key as well
+is FixMyStreet->config('GAZE_URL'), 'http://gaze.mysociety.org/gaze',
+ "GAZE_URL correct when got by key";
+is FixMyStreet->config('BAD_KEY_DOES_NOT_EXIST'), undef, "config miss is undef";
+
+# all done
+done_testing();
+