diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-04-20 19:35:31 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-04-20 19:38:32 +0100 |
commit | 66eb844d7eaba7155e362dcec8a7a7db8f3dbf4c (patch) | |
tree | 25debcbb91cae5d33429ae1dc3120e6d7f627b24 /t | |
parent | 97a01fcec2c48e379394e0127888edc2e5bbde91 (diff) |
Update tests for cobrand/template changes.
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/about.t | 18 | ||||
-rw-r--r-- | t/app/controller/admin.t | 10 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 25 | ||||
-rw-r--r-- | t/app/controller/report_interest_count.t | 24 | ||||
-rw-r--r-- | t/app/controller/reports.t | 11 | ||||
-rw-r--r-- | t/app/model/user.t | 2 | ||||
-rw-r--r-- | t/app/uri_for.t | 26 | ||||
-rw-r--r-- | t/cobrand/loading.t | 30 | ||||
-rw-r--r-- | t/i18n.t | 25 |
9 files changed, 60 insertions, 111 deletions
diff --git a/t/app/controller/about.t b/t/app/controller/about.t index 6a082a2ff..cec50abfa 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -1,3 +1,4 @@ +use utf8; use strict; use warnings; @@ -21,19 +22,12 @@ ok !$mech->res->is_success(), "want a bad response"; is $mech->res->code, 404, "got 404"; FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'emptyhomes' ], + ALLOWED_COBRANDS => [ 'fiksgatami' ], }, sub { - # 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_like(qr{About us ::}); - $mech->content_contains('html lang="en-gb"'); - - # check that geting the page as EHA in welsh produces a different page - ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes'; - $mech->get_ok('/about'); - $mech->content_like(qr{Amdanom ni ::}); - $mech->content_contains('html lang="cy"'); + ok $mech->host("www.fiksgatami.no"), 'host to fiksgatami'; + $mech->get_ok('/faq'); + $mech->content_like(qr{Ofte spurte spørsmål ::}); + $mech->content_contains('html class="no-js" lang="nb"'); }; done_testing(); diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 310e0a677..1dcb768dc 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -104,9 +104,9 @@ subtest 'check summary counts' => sub { $mech->content_contains( "$q_count questionnaires sent" ); FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'barnet' ], + ALLOWED_COBRANDS => [ 'oxfordshire' ], }, sub { - ok $mech->host('barnet.fixmystreet.com'); + ok $mech->host('oxfordshire.fixmystreet.com'); $mech->get_ok('/admin'); $mech->title_like(qr/Summary/); @@ -115,11 +115,11 @@ subtest 'check summary counts' => sub { my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/; my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/; - $report->bodies_str(2489); - $report->cobrand('barnet'); + $report->bodies_str(2237); + $report->cobrand('oxfordshire'); $report->update; - $alert->cobrand('barnet'); + $alert->cobrand('oxfordshire'); $alert->update; $mech->get_ok('/admin'); diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index cad86a40d..7bc6545db 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -394,31 +394,23 @@ for my $test ( } FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'emptyhomes', 'fixmystreet' ], + ALLOWED_COBRANDS => [ 'fixmystreet' ], }, sub { - # EHA extra checking - ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; - - # Reset, and all the questionaire sending function - FIXME should it detect site itself somehow? + $report->discard_changes; $report->send_questionnaire( 1 ); $report->update; $questionnaire->delete; - FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { - site => 'emptyhomes' - } ); + FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires(); $email = $mech->get_email; ok $email, "got an email"; $mech->clear_emails_ok; (my $body = $email->body) =~ s/\s+/ /g; - like $body, qr/fill in this short questionnaire/i, "got questionnaire email"; + like $body, qr/fill in our short questionnaire/i, "got questionnaire email"; ($token) = $email->body =~ m{http://.*?/Q/(\S+)}; ok $token, "extracted questionnaire token '$token'"; - $mech->get_ok("/Q/" . $token); - $mech->content_lacks( 'Would you like to receive another questionnaire' ); - # Test already answered the ever reported question, so not shown again $dt = $dt->add( weeks => 4 ); my $questionnaire2 = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( @@ -429,17 +421,11 @@ FixMyStreet::override_config { } ); ok $questionnaire2, 'added another questionnaire'; - ok $mech->host("www.fixmystreet.com"), 'change host to fixmystreet'; $mech->get_ok("/Q/" . $token); $mech->title_like( qr/Questionnaire/ ); $mech->content_contains( 'Has this problem been fixed?' ); $mech->content_lacks( 'ever reported' ); - # EHA extra checking - ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; - $mech->get_ok("/Q/" . $token); - $mech->content_lacks( 'Would you like to receive another questionnaire' ); - $token = FixMyStreet::App->model("DB::Token")->find( { scope => 'questionnaire', token => $token } ); ok $token, 'found token for questionnaire'; $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->find( { id => $token->data } ); @@ -452,11 +438,12 @@ FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fiksgatami' ], }, sub { # I18N Unicode extra testing using FiksGataMi + $report->discard_changes; $report->send_questionnaire( 1 ); $report->cobrand( 'fiksgatami' ); $report->update; $questionnaire->delete; - FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { site => 'fixmystreet' } ); # It's either fixmystreet or emptyhomes + FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires(); $email = $mech->get_email; ok $email, "got an email"; $mech->clear_emails_ok; diff --git a/t/app/controller/report_interest_count.t b/t/app/controller/report_interest_count.t index 506b50edd..4e86789ba 100644 --- a/t/app/controller/report_interest_count.t +++ b/t/app/controller/report_interest_count.t @@ -1,5 +1,16 @@ use strict; use warnings; + +package FixMyStreet::Cobrand::Tester; + +use parent 'FixMyStreet::Cobrand::Default'; + +sub can_support_problems { + return 1; +} + +package main; + use Test::More; use FixMyStreet::TestMech; @@ -52,7 +63,7 @@ my $report_id = $report->id; ok $report, "created test report - $report_id"; FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'fixmybarangay' ], + ALLOWED_COBRANDS => [ 'tester' ], }, sub { my $body = $mech->create_body_ok(2504, 'Westminster City Council'); @@ -76,7 +87,6 @@ FixMyStreet::override_config { }, ) { subtest $test->{desc} => sub { - ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay'; $mech->log_in_ok( $user->email ); $user->from_body( $test->{from_body} ); $user->update; @@ -92,7 +102,7 @@ FixMyStreet::override_config { $mech->content_contains('Add support'); $mech->submit_form_ok( { form_number => 1 } ); - is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page'; + is $mech->uri->path, "/report/$report_id", 'add support redirects to report page'; $mech->content_contains($test->{updated_support}); } else { @@ -102,26 +112,22 @@ FixMyStreet::override_config { } subtest 'check non body user cannot increment support count' => sub { - ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay'; - ok $report->update({ interest_count => 1 }), 'updated interest count'; is $report->interest_count, 1, 'correct interest count'; $mech->get_ok("/report/$report_id"); $mech->content_contains( '1 supporter' ); - # This doesn't send cookie, so is logged out + $mech->log_out_ok( $user->email ); $mech->post_ok("/report/support", { id => $report_id } ); - is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page'; + is $mech->uri->path, "/report/$report_id", 'add support redirects to report page'; $mech->content_contains( '1 supporter' ); }; }; subtest 'check support details not shown if not enabled in cobrand' => sub { - ok $mech->host('www.fixmystreet.com'), 'changed to fixmystreet'; - $report->interest_count(1); ok $report->update, 'updated interest count'; diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 9b446174d..8869adaa7 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -196,17 +196,6 @@ $mech->get_ok('/reports'); $stats = $mech->extract_report_stats; is $stats->{'Westminster City Council'}->[1], 5, 'non public reports included in stats'; -subtest "test emptyhomes all reports page" => sub { - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'emptyhomes' ], - }, sub { - ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; - $mech->get_ok('/reports'); - # EHA lacks one column the others have - $mech->content_lacks('state unknown'); - }; -}; - subtest "test fiksgatami all reports page" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fiksgatami' ], diff --git a/t/app/model/user.t b/t/app/model/user.t index 24e5d2d98..bf73a9d09 100644 --- a/t/app/model/user.t +++ b/t/app/model/user.t @@ -46,7 +46,7 @@ END { sub create_update { my ($problem, %params) = @_; - my $dt = DateTime->now()->add(hours => 1); + my $dt = DateTime->now()->add(days => 1); return FixMyStreet::App->model('DB::Comment')->find_or_create({ problem_id => $problem->id, user_id => $problem->user_id, diff --git a/t/app/uri_for.t b/t/app/uri_for.t index 810aade62..9cbcd3767 100644 --- a/t/app/uri_for.t +++ b/t/app/uri_for.t @@ -17,7 +17,6 @@ use_ok('FixMyStreet::App'); my $fms_c = ctx_request('http://www.fixmystreet.com/'); my $fgm_c = ctx_request('http://www.fiksgatami.no/'); -my $reh_en_c = ctx_request('http://reportemptyhomes.com/'); is( $fms_c->uri_for('/bar/baz') . "", @@ -44,29 +43,4 @@ is( 'FiksGataMi url with lat not zoom' ); -FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'emptyhomes' ], -}, sub { - like( - $reh_en_c->uri_for_email( '/foo' ), - qr{^http://en.}, - 'adds en to retain language' - ); -}; - -# instantiate this here otherwise sets locale to cy and breaks test -# above -my $reh_cy_c; -FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'emptyhomes' ], -}, sub { - $reh_cy_c = ctx_request('http://cy.reportemptyhomes.com/'); - - like( - $reh_cy_c->uri_for_email( '/foo' ), - qr{^http://cy.}, - 'retains language' - ); -}; - done_testing(); diff --git a/t/cobrand/loading.t b/t/cobrand/loading.t index 48a10293e..b4738fb63 100644 --- a/t/cobrand/loading.t +++ b/t/cobrand/loading.t @@ -44,8 +44,8 @@ FixMyStreet::override_config { }, sub { run_host_tests( 'www.fixmystreet.com' => 'FixMyStreet', - 'reportemptyhomes.com' => 'FixMyStreet', - 'barnet.fixmystreet.com' => 'FixMyStreet', + 'fiksgatami.example.org' => 'FixMyStreet', + 'oxfordshire.fixmystreet.com' => 'FixMyStreet', 'some.odd.site.com' => 'FixMyStreet', ); }; @@ -62,49 +62,49 @@ FixMyStreet::override_config { # Couple of cobrands, hostname checking and default fallback FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'emptyhomes', 'fixmystreet' ], + ALLOWED_COBRANDS => [ 'fiksgatami', 'fixmystreet' ], }, sub { run_host_tests( 'www.fixmystreet.com' => 'FixMyStreet', - 'reportemptyhomes.com' => 'EmptyHomes', - 'barnet.fixmystreet.com' => 'FixMyStreet', # not in the allowed_cobrands list + 'fiksgatami.example.org' => 'FiksGataMi', + 'oxfordshire.fixmystreet.com' => 'FixMyStreet', # not in the allowed_cobrands list 'some.odd.site.com' => 'Default', ); }; -# now enable barnet too and check that it works +# now enable oxfordshire too and check that it works FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'emptyhomes', 'barnet', 'fixmystreet' ], + ALLOWED_COBRANDS => [ 'fiksgatami', 'oxfordshire', 'fixmystreet' ], }, sub { run_host_tests( 'www.fixmystreet.com' => 'FixMyStreet', - 'reportemptyhomes.com' => 'EmptyHomes', - 'barnet.fixmystreet.com' => 'Barnet', # found now it is in allowed_cobrands + 'fiksgatami.example.org' => 'FiksGataMi', + 'oxfordshire.fixmystreet.com' => 'Oxfordshire', # found now it is in allowed_cobrands 'some.odd.site.com' => 'Default', ); }; # And a check with some regex matching FixMyStreet::override_config { - ALLOWED_COBRANDS => [ { 'fixmystreet' => 'empty' }, 'barnet', { 'testing' => 'fixmystreet' } ], + ALLOWED_COBRANDS => [ { 'fixmystreet' => 'example' }, 'oxfordshire', { 'testing' => 'fixmystreet' } ], }, sub { run_host_tests( 'www.fixmystreet.com' => 'testing', - 'reportemptyhomes.com' => 'FixMyStreet', - 'barnet.fixmystreet.com' => 'Barnet', + 'fiksgatami.example.org' => 'FixMyStreet', + 'oxfordshire.fixmystreet.com' => 'Oxfordshire', 'some.odd.site.com' => 'Default', ); }; # check that the moniker works as expected both on class and object. -is FixMyStreet::Cobrand::EmptyHomes->moniker, 'emptyhomes', +is FixMyStreet::Cobrand::FiksGataMi->moniker, 'fiksgatami', 'class->moniker works'; -is FixMyStreet::Cobrand::EmptyHomes->new->moniker, 'emptyhomes', +is FixMyStreet::Cobrand::FiksGataMi->new->moniker, 'fiksgatami', 'object->moniker works'; # check is_default works ok FixMyStreet::Cobrand::Default->is_default, '::Default is default'; -ok !FixMyStreet::Cobrand::EmptyHomes->is_default, '::Emptyhomes is not default'; +ok !FixMyStreet::Cobrand::FiksGataMi->is_default, '::FiksGataMi is not default'; # all done done_testing(); @@ -14,11 +14,11 @@ use mySociety::Locale; die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' " . "to generate the *.mo files needed." unless -e FixMyStreet->path_to( - 'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo'); + 'locale/nb_NO.UTF-8/LC_MESSAGES/FixMyStreet.mo'); # Test the language negotiation works my $lang = mySociety::Locale::negotiate_language( - 'en-gb,English,en_GB|cy,Cymraeg,cy_GB|es,Spanish,es_ES', + 'en-gb,English,en_GB|es,Spanish,es_ES', undef, HTTP::Headers->new( Accept_Language => 'es,en-gb;q=0.6,en;q=0.4' @@ -28,27 +28,26 @@ is $lang, 'es', 'Language negotiation works okay'; # Example strings my $english = "Please enter a valid email"; -my $welsh = "Cofnodwch gyfeiriad e-bost dilys"; +my $norwegian = "Legg til en gyldig e-post"; # set english as the language mySociety::Locale::negotiate_language( # - 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB' + 'en-gb,English,en_GB|nb,Norwegian,nb_NO', 'en_GB' ); -mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1 ); +mySociety::Locale::gettext_domain( 'FixMyStreet', 1 ); mySociety::Locale::change(); is _($english), $english, "english to english"; -# set to welsh and check for translation -mySociety::Locale::change('cy'); -is _($english), $welsh, "english to welsh"; +mySociety::Locale::change('nb'); +is _($english), $norwegian, "english to norwegian"; # check that being in a deep directory does not confuse the code chdir FixMyStreet->path_to('t/app/controller') . ''; -mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1, +mySociety::Locale::gettext_domain( 'FixMyStreet', 1, FixMyStreet->path_to('locale')->stringify ); -mySociety::Locale::change('cy'); -is _($english), $welsh, "english to welsh (deep directory)"; +mySociety::Locale::change('nb'); +is _($english), $norwegian, "english to norwegian (deep directory)"; # test that sorting works as expected in the right circumstances... my @random_sorted = qw( Å Z Ø A ); @@ -59,7 +58,7 @@ my @default_sorted = qw( A Z Å Ø ); SKIP: { mySociety::Locale::negotiate_language( # - 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB' + 'en-gb,English,en_GB', 'en_GB' ); mySociety::Locale::change(); @@ -82,7 +81,7 @@ SKIP: { skip 'Will not pass on Mac', 2 if $^O eq 'darwin'; mySociety::Locale::negotiate_language( # - 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB' + 'en-gb,English,en_GB', 'en_GB' ); mySociety::Locale::change(); use locale; |