diff options
Diffstat (limited to 't')
28 files changed, 434 insertions, 398 deletions
diff --git a/t/Mock/Twitter.pm b/t/Mock/Twitter.pm new file mode 100644 index 000000000..930895e28 --- /dev/null +++ b/t/Mock/Twitter.pm @@ -0,0 +1,43 @@ +package t::Mock::Twitter; + +use JSON::MaybeXS; +use Web::Simple; +use MooX::Types::MooseLike::Base qw(:all); + +has json => ( + is => 'lazy', + default => sub { + JSON->new->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /oauth/authenticate + ?*) { + my ($self) = @_; + return [ 200, [ 'Content-Type' => 'text/html' ], [ 'TwitteB login page' ] ]; + }, + + sub (GET + /oauth/access_token + ?*) { + my ($self) = @_; + return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'oauth_token=access_token&oauth_token_secret=secret' ] ]; + }, + + sub (GET + /oauth/request_token + ?*) { + my ($self) = @_; + return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'oauth_token=request-token&oauth_token_secret=secret&oauth_callback_confirmed=true' ] ]; + }, + + sub (GET + /1.1/account/verify_credentials.json + ?*) { + my ($self) = @_; + my $data = { + id => '987654321', + name => 'Fiona Tester', + }; + my $json = $self->json->encode($data); + return [ 200, [ 'Content-Type' => 'text/html' ], [ $json ] ]; + }, +} + +__PACKAGE__->run_if_script; diff --git a/t/app/01app.t b/t/app/01app.t index eb98b6319..df562b829 100644 --- a/t/app/01app.t +++ b/t/app/01app.t @@ -16,12 +16,16 @@ use Encode qw(encode); ok( request('/')->is_success, 'Request should succeed' ); +SKIP: { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'tester' ], }, sub { + skip 'Test will not pass on Mac OS', 1 if $^O eq 'darwin'; + my $page = get('/'); my $num = encode('UTF-8', "12\N{NO-BREAK SPACE}345"); like $page, qr/$num/; }; +} done_testing(); 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 92cbbc00f..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'); @@ -171,6 +171,7 @@ subtest 'check contact creation' => sub { email => 'test@example.com', note => 'test note', non_public => undef, + confirmed => 0, } } ); $mech->content_contains( 'test category' ); diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t index 84fdd4dfe..6929c0ddc 100644 --- a/t/app/controller/auth_social.t +++ b/t/app/controller/auth_social.t @@ -6,6 +6,7 @@ use LWP::Simple; use JSON::MaybeXS; use t::Mock::Facebook; +use t::Mock::Twitter; use t::Mock::MapIt; use FixMyStreet::TestMech; @@ -21,6 +22,7 @@ LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk'); FixMyStreet::override_config { FACEBOOK_APP_ID => 'facebook-app-id', + TWITTER_KEY => 'twitter-key', ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], MAPIT_URL => 'http://mapit.uk/', }, sub { @@ -31,7 +33,10 @@ my $fb_uid = 123456789; for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { for my $page ( 'my', 'report', 'update' ) { subtest "test FB '$fb_state' login for page '$page'" => sub { + # Lots of user changes happening here, make sure we don't confuse + # Catalyst with a cookie session user that no longer exists $mech->log_out_ok; + $mech->cookie_jar({}); if ($fb_state eq 'existing UID') { my $user = $mech->create_user_ok($fb_email); $user->update({ facebook_id => $fb_uid }); @@ -135,6 +140,118 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { } } +my $tw_email = 'twitter@example.org'; +my $tw_uid = 987654321; + +# Twitter has no way of getting the email, so no "okay" state here +for my $tw_state ( 'refused', 'existing UID', 'no email' ) { + for my $page ( 'my', 'report', 'update' ) { + subtest "test Twitter '$tw_state' login for page '$page'" => sub { + # Lots of user changes happening here, make sure we don't confuse + # Catalyst with a cookie session user that no longer exists + $mech->log_out_ok; + $mech->cookie_jar({}); + if ($tw_state eq 'existing UID') { + my $user = $mech->create_user_ok($tw_email); + $user->update({ twitter_id => $tw_uid }); + } else { + $mech->delete_user($tw_email); + } + + # Set up a mock to catch (most, see below) requests to Twitter + my $tw = t::Mock::Twitter->new; + LWP::Protocol::PSGI->register($tw->to_psgi_app, host => 'api.twitter.com'); + + # Due to https://metacpan.org/pod/Test::WWW::Mechanize::Catalyst#External-Redirects-and-allow_external + # the redirect to Twitter's OAuth page can mess up the session + # cookie. So let's pretend we always on api.twitter.com, which + # sorts that out. + $mech->host('api.twitter.com'); + + # Fetch the page with the form via which we wish to log in + my $fields; + if ($page eq 'my') { + $mech->get_ok('/my'); + } elsif ($page eq 'report') { + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'SW1A1AA' } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $fields = { + title => 'Test title', + detail => 'Test detail', + }; + } else { + $mech->get_ok('/report/' . $report->id); + $fields = { + update => 'Test update', + }; + } + $mech->submit_form(with_fields => $fields, button => 'twitter_sign_in'); + + # As well as the cookie issue above, caused by this external + # redirect rewriting the host, the redirect gets handled directly + # by Catalyst, not our mocked handler, so will be a 404. Check + # the redirect happened instead. + is $mech->res->previous->code, 302, 'Twitter button redirected'; + like $mech->res->previous->header('Location'), qr{api\.twitter\.com/oauth/authenticate\?oauth_token=request-token}, 'Twitter redirect to oauth URL'; + + # Okay, now call the callback Facebook would send us to + if ($tw_state eq 'refused') { + $mech->get_ok('/auth/Twitter?denied=token'); + } else { + $mech->get_ok('/auth/Twitter?oauth_token=request-token&oauth_verifier=verifier'); + } + + # Check we're showing the right form, regardless of what came back + if ($page eq 'report') { + $mech->content_contains('/report/new'); + } elsif ($page eq 'update') { + $mech->content_contains('/report/update'); + } + + if ($tw_state eq 'refused') { + $mech->content_contains('Sorry, we could not log you in. Please fill in the form below.'); + $mech->not_logged_in_ok; + } elsif ($tw_state eq 'no email') { + $mech->content_contains('We need your email address, please give it below.'); + # We don't have an email, so check that we can still submit it, + # and the ID carries through the confirmation + if ($page eq 'update') { + $fields->{rznvy} = $tw_email; + } else { + $fields->{email} = $tw_email; + } + $fields->{name} = 'Ffion Tester'; + $mech->submit_form(with_fields => $fields); + $mech->content_contains('Nearly done! Now check your email'); + + my $email = $mech->get_email; + ok $email, "got an email"; + $mech->clear_emails_ok; + my ( $url, $url_token ) = $email->body =~ m{(https?://\S+/[CMP]/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $user = FixMyStreet::App->model( 'DB::User' )->find( { email => $tw_email } ); + if ($page eq 'my') { + is $user, undef, 'No user yet exists'; + } else { + is $user->twitter_id, undef, 'User has no twitter ID'; + } + $mech->get_ok( $url . $url_token ); + $user = FixMyStreet::App->model( 'DB::User' )->find( { email => $tw_email } ); + is $user->twitter_id, $tw_uid, 'User now has correct twitter ID'; + + } elsif ($page ne 'my') { + # /my auth login goes directly there, no message like this + $mech->content_contains('You have successfully signed in; please check and confirm your details are accurate'); + $mech->logged_in_ok; + } else { + is $mech->uri->path, '/my', 'Successfully on /my page'; + } + } + } +} + }; END { diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t index 39380e769..425e3c4df 100644 --- a/t/app/controller/photo.t +++ b/t/app/controller/photo.t @@ -65,10 +65,10 @@ subtest "Check multiple upload worked" => sub { ok $mech->success, 'Made request with multiple photo upload'; $mech->base_is('http://localhost/report/new'); $mech->content_like( - qr[(<img align="right" src="/photo/1cdd4329ceee2234bd4e89cb33b42061a0724687.temp.jpeg" alt="">\s*){3}], + qr[(<img align="right" src="/photo/temp.1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg" alt="">\s*){3}], 'Three uploaded pictures are all shown, safe'); $mech->content_contains( - 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687"', + 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg,1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg,1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg"', 'Returned upload_fileid contains expected hash, 3 times'); my $image_file = path($UPLOAD_DIR, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg'); ok $image_file->exists, 'File uploaded to temp'; diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index 7718d5034..7bc6545db 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -63,8 +63,8 @@ my $email = $mech->get_email; ok $email, "got an email"; like $email->body, qr/fill in our short questionnaire/i, "got questionnaire email"; -like $email->body, qr/Testing =96 Detail/, 'email contains encoded character'; -is $email->header('Content-Type'), 'text/plain; charset="windows-1252"', 'in the right character set'; +like $email->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character'; +is $email->header('Content-Type'), 'text/plain; charset="utf-8"', 'in the right character set'; my ($token) = $email->body =~ m{http://.*?/Q/(\S+)}; ok $token, "extracted questionnaire token '$token'"; @@ -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,18 +438,19 @@ 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; - like $email->body, qr/Testing =96 Detail/, 'email contains encoded character from user'; - like $email->body, qr/sak p=E5 FiksGataMi/, 'email contains encoded character from template'; - is $email->header('Content-Type'), 'text/plain; charset="windows-1252"', 'email is in right encoding'; + like $email->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character from user'; + like $email->body_str, qr/sak p\xe5 FiksGataMi/, 'email contains encoded character from template'; + is $email->header('Content-Type'), 'text/plain; charset="utf-8"', 'email is in right encoding'; }; $mech->delete_user('test@example.com'); 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/report_new.t b/t/app/controller/report_new.t index cf72221b4..eb29d37da 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -420,7 +420,7 @@ foreach my $test ( changes => { photo1 => '', }, - errors => [ "Please upload a JPEG image only" ], + errors => [ "Please upload an image only" ], }, { msg => 'bad photo upload gives error', @@ -443,7 +443,7 @@ foreach my $test ( changes => { photo1 => '', }, - errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ], + errors => [ "That image doesn't appear to have uploaded correctly (Please upload an image only ), please try again." ], }, { msg => 'photo with octet-stream gets through okay', diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index f9f5189e5..7b4bf7854 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -760,7 +760,8 @@ subtest 'check meta correct for comments marked confirmed but not marked open' = user => $user, problem_id => $report->id, text => 'update text', - confirmed => DateTime->now( time_zone => 'local' ), + # Subtract a day to deal with any code/db timezone difference + confirmed => DateTime->now( time_zone => 'local' ) - DateTime::Duration->new( days => 1 ), problem_state => 'confirmed', anonymous => 0, mark_open => 0, diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 02625fcc7..8869adaa7 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -12,6 +12,7 @@ $mech->create_body_ok(2514, 'Birmingham City Council'); my $body_edin_id = $mech->create_body_ok(2651, 'City of Edinburgh Council')->id; my $body_west_id = $mech->create_body_ok(2504, 'Westminster City Council')->id; my $body_fife_id = $mech->create_body_ok(2649, 'Fife Council')->id; +my $body_slash_id = $mech->create_body_ok(10000, 'Electricity/Gas Council')->id; $mech->delete_problems_for_body( $body_west_id ); $mech->delete_problems_for_body( $body_edin_id ); @@ -122,6 +123,10 @@ is scalar @$problems, 5, 'correct number of problems displayed'; FixMyStreet::override_config { MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { + $mech->get_ok('/reports'); + $mech->follow_link_ok({ url_regex => qr{/reports/Electricity_Gas\+Council} }); + is $mech->uri->path, '/reports/Electricity_Gas+Council', 'Path is correct'; + $mech->get_ok('/reports/City+of+Edinburgh?t=new'); }; $problems = $mech->extract_problem_list; @@ -191,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/helpers/send_email.t b/t/app/helpers/send_email.t index f60f7fa5a..e2c8688a8 100644 --- a/t/app/helpers/send_email.t +++ b/t/app/helpers/send_email.t @@ -41,8 +41,7 @@ my $email = Email::MIME->new($email_as_string); my $expected_email_content = path(__FILE__)->parent->child('send_email_sample.txt')->slurp; my $name = FixMyStreet->config('CONTACT_NAME'); -$name = "\"$name\"" if $name =~ / /; -my $sender = $name . ' <' . FixMyStreet->config('DO_NOT_REPLY_EMAIL') . '>'; +my $sender = '"' . $name . '" <' . FixMyStreet->config('DO_NOT_REPLY_EMAIL') . '>'; $expected_email_content =~ s{CONTACT_EMAIL}{$sender}; my $expected_email = Email::MIME->new($expected_email_content); diff --git a/t/app/helpers/send_email_sample.txt b/t/app/helpers/send_email_sample.txt index 1ccce6a23..0f7406172 100644 --- a/t/app/helpers/send_email_sample.txt +++ b/t/app/helpers/send_email_sample.txt @@ -1,5 +1,5 @@ MIME-Version: 1.0 -Subject: test email =?utf-8?Q?=E2=98=BA?= +Subject: =?UTF-8?B?dGVzdCBlbWFpbCDimLo=?= Content-Type: text/plain; charset="utf-8" To: test@recipient.com Content-Transfer-Encoding: quoted-printable @@ -24,5 +24,3 @@ culpa qui officia deserunt mollit anim id est laborum. Yours,=20=20 FixMyStreet.=20= - - diff --git a/t/app/helpers/send_email_sample_mime.txt b/t/app/helpers/send_email_sample_mime.txt index c4ca97bcc..0649d1ceb 100644 --- a/t/app/helpers/send_email_sample_mime.txt +++ b/t/app/helpers/send_email_sample_mime.txt @@ -1,57 +1,49 @@ -MIME-Version: 1.0 -Subject: test email =?utf-8?Q?=E2=98=BA?= -Content-Type: multipart/mixed; boundary="BOUNDARY" -To: test@recipient.com -Content-Transfer-Encoding: 7bit -From: CONTACT_EMAIL - - ---BOUNDARY -MIME-Version: 1.0 -Subject: test email =?utf-8?Q?=E2=98=BA?= -Content-Type: text/plain; charset="utf-8" -To: test@recipient.com -Content-Transfer-Encoding: quoted-printable -From: CONTACT_EMAIL - -Hello, - -This is a test email where foo: bar. - -utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=E7=BC= -=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81 - - indented_text - -long line: Lorem ipsum dolor sit amet, consectetur adipisicing elit, -sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris -nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in -reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla -pariatur. Excepteur sint occaecat cupidatat non proident, sunt in -culpa qui officia deserunt mollit anim id est laborum. - -Yours,=20=20 -FixMyStreet.=20= - - - ---BOUNDARY -MIME-Version: 1.0 -Content-Type: image/gif; name="foo.gif" -Content-Disposition: inline; filename="foo.gif" -Content-Transfer-Encoding: quoted-printable - -GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00= -=02=01L=00;= - ---BOUNDARY -MIME-Version: 1.0 -Content-Type: image/gif; name="bar.gif" -Content-Disposition: inline; filename="bar.gif" -Content-Transfer-Encoding: quoted-printable - -GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00= -=02=01L=00;= - ---BOUNDARY-- +MIME-Version: 1.0
+Subject: =?UTF-8?B?dGVzdCBlbWFpbCDimLo=?=
+Content-Type: multipart/mixed; boundary="BOUNDARY"
+To: test@recipient.com
+Content-Transfer-Encoding: 7bit
+From: CONTACT_EMAIL
+
+
+--BOUNDARY
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Hello,
+
+This is a test email where foo: bar.
+
+utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=E7=BC=
+=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81
+
+ indented_text
+
+long line: Lorem ipsum dolor sit amet, consectetur adipisicing elit,
+sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+culpa qui officia deserunt mollit anim id est laborum.
+
+Yours,=20=20
+FixMyStreet.=20=
+
+--BOUNDARY
+Content-Type: image/gif; name="foo.gif"
+Content-Disposition: inline; filename="foo.gif"
+Content-Transfer-Encoding: quoted-printable
+
+GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
+=02=01L=00;=
+
+--BOUNDARY
+Content-Type: image/gif; name="bar.gif"
+Content-Disposition: inline; filename="bar.gif"
+Content-Transfer-Encoding: quoted-printable
+
+GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
+=02=01L=00;=
+
+--BOUNDARY--
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index 0130f404e..e94ee8ce1 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -287,7 +287,7 @@ foreach my $test ( desc => 'address only', addressLine => '18 North Bridge', locality => undef, - nearest => qr/: 18 North Bridge\n/, + nearest => qr/: 18 North Bridge\r?\n/, }, { desc => 'no fields', diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t index cfb5236a8..577e39eb1 100644 --- a/t/app/model/photoset.t +++ b/t/app/model/photoset.t @@ -58,7 +58,7 @@ subtest 'Photoset with photo inline in DB' => sub { my $report = make_report( $image_path->slurp ); my $photoset = $report->get_photoset(); is $photoset->num_images, 1, 'Found just 1 image'; - is $photoset->data, '1cdd4329ceee2234bd4e89cb33b42061a0724687'; + is $photoset->data, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg'; }; $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); 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/sendreport/angus.t b/t/app/sendreport/angus.t new file mode 100644 index 000000000..a19ee483a --- /dev/null +++ b/t/app/sendreport/angus.t @@ -0,0 +1,61 @@ +use strict; +use warnings; + +use FixMyStreet::DB; + +use Test::More; + +use_ok("FixMyStreet::SendReport::Angus"); + +my $u = FixMyStreet::DB->resultset('User')->new( { email => 'test@example.org', name => 'A User' } ); + +my $p = FixMyStreet::DB->resultset('Problem')->new( { + latitude => 1, + longitude => 1, + title => 'title', + detail => 'detail', + user => $u, + id => 1, + name => 'A User', + cobrand => 'fixmystreet', +} ); + +my $angus = FixMyStreet::SendReport::Angus->new(); + +subtest 'parses authentication token correctly' => sub { + my $authxml = <<EOT; + <AuthenticateResponse> + + <AuthenticateResult> + TVRreUxqRTJPQzR5TlRVdU1qSjhNakF4Tmpvd01Ub3lNam94TlRvME16b3pPUT09VGhvdVNoYWx0Tm90UGFzcw== + </AuthenticateResult> + <success> + True + </success> + <message></message> + + </AuthenticateResponse> +EOT +; + is $angus->get_auth_token($authxml), 'TVRreUxqRTJPQzR5TlRVdU1qSjhNakF4Tmpvd01Ub3lNam94TlRvME16b3pPUT09VGhvdVNoYWx0Tm90UGFzcw==', 'token correct'; +}; + +subtest 'parses report external id correctly' => sub { + my $respxml = <<EOT; +<CreateRequestResponse> + + <CreateRequestResult> + <RequestId>7245</RequestId> + </CreateRequestResult> + + <success>True</success> + <message></message> + +</CreateRequestResponse> +EOT +; + is $angus->get_external_id($respxml), '7245', 'external id correct'; +}; + + +done_testing(); 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/fixamingata.t b/t/cobrand/fixamingata.t index 50b7713d1..0cf7a31fe 100644 --- a/t/cobrand/fixamingata.t +++ b/t/cobrand/fixamingata.t @@ -46,10 +46,10 @@ FixMyStreet::override_config { FixMyStreet::DB->resultset('Problem')->send_reports(); }; my $email = $mech->get_email; -like $email->header('Content-Type'), qr/iso-8859-1/, 'encoding looks okay'; +like $email->header('Content-Type'), qr/utf-8/, 'encoding looks okay'; like $email->header('Subject'), qr/Ny rapport: Test Test/, 'subject looks okay'; like $email->header('To'), qr/other\@example.org/, 'to line looks correct'; -like $email->body, qr/V=E4nligen,/, 'signature looks correct'; +like $email->body_str, qr/V\xe4nligen,/, 'signature looks correct'; $mech->clear_emails_ok; my $user = @@ -91,8 +91,8 @@ FixMyStreet::override_config { $mech->email_count_is(1); $email = $mech->get_email; -like $email->header('Content-Type'), qr/iso-8859-1/, 'encoding looks okay'; -like $email->body, qr/V=E4nligen,/, 'signature looks correct'; +like $email->header('Content-Type'), qr/utf-8/, 'encoding looks okay'; +like $email->body_str, qr/V\xe4nligen,/, 'signature looks correct'; $mech->clear_emails_ok; subtest "Test ajax decimal points" => sub { diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t deleted file mode 100644 index 2f99b8c1e..000000000 --- a/t/cobrand/fixmybarangay.t +++ /dev/null @@ -1,150 +0,0 @@ -use strict; -use warnings; -use Test::More; - -BEGIN { - use FixMyStreet; - FixMyStreet->test_mode(1); -} - -use FixMyStreet::TestMech; -my $mech = FixMyStreet::TestMech->new; - -# Front page test - -ok $mech->host("www.fixmybarangay.com"), "change host to FixMyBarangay"; -FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'fixmybarangay' ], -}, sub { - $mech->get_ok('/'); -}; -$mech->content_like( qr/FixMyBarangay/ ); - -# Set up bodies - -my $luz = $mech->create_body_ok( 1, 'Bgy Luz', id => 1 ); -$luz->update( { send_method => 'Email' } ); - -my $bsn = $mech->create_body_ok( 2, 'Bgy BSN', id => 2 ); -$bsn->update( { send_method => 'Email' } ); - -my $dps = $mech->create_body_ok( 3, 'DPS', id => 3 ); -$dps->update( { send_method => 'Open311', endpoint => 'http://dps.endpoint.example.com', jurisdiction => 'FMB', api_key => 'test' } ); -FixMyStreet::DB->resultset('BodyArea')->find_or_create({ area_id => 1, body_id => $dps->id }); -FixMyStreet::DB->resultset('BodyArea')->find_or_create({ area_id => 2, body_id => $dps->id }); - -# Create contacts for these bodies -# TODO: log in as a Bgy user, and create a report using the front end, -# testing that the drop-down has the right things in it, and so on. - -$mech->create_contact_ok( - body_id => $luz->id, - category => 'Streetlight (BGY)', - email => 'bgy@example.com', -); -$mech->create_contact_ok( - body_id => $dps->id, - category => 'Streetlight (DPS)', - email => 'LIGHT', -); - -# Create a couple of reports - -my @reports = $mech->create_problems_for_body( 1, $luz->id, 'Test', { - cobrand => 'fixmybarangay', - category => 'Streetlight (BGY)', -}); -my $luz_report = $reports[0]; - -@reports = $mech->create_problems_for_body( 1, $dps->id, 'Test', { - cobrand => 'fixmybarangay', - category => 'Streetlight (DPS)', -}); -my $dps_report = $reports[0]; - -$mech->get_ok( '/report/' . $luz_report->id ); -$mech->get_ok( '/report/' . $dps_report->id ); - -# Send the reports - -$mech->email_count_is(0); - -FixMyStreet::override_config { - SEND_REPORTS_ON_STAGING => 1, -}, sub { - FixMyStreet::DB->resultset('Problem')->send_reports('fixmybarangay'); -}; - -# Check BGY one sent by email -my $email = $mech->get_email; -like $email->header('Subject'), qr/Problem Report: Test Test/, 'subject looks okay'; -like $email->header('To'), qr/bgy\@example.com/, 'to line looks correct'; -$mech->clear_emails_ok; - -$luz_report->discard_changes; -$dps_report->discard_changes; -ok $luz_report->whensent, 'Luz report marked as sent'; -ok $dps_report->whensent, 'DPS report marked as sent'; -is $dps_report->send_method_used, 'Open311', 'DPS report sent via Open311'; -is $dps_report->external_id, 248, 'DPS report has right external ID'; - -my $fmb_test_email = 'luz_test_user@example.com'; -my $user = FixMyStreet::DB->resultset('User')->find_or_create( { email => $fmb_test_email, from_body => $luz->id, password => 'fmbsecret' } ); -ok $user, "test user does exist"; - -my $alert = FixMyStreet::DB->resultset('Alert')->find_or_create({ - user => $user, - parameter => '-0.142497580865087', - parameter2 => '51.5016605453401', - alert_type => 'local_problems', - whensubscribed => '2014-01-01 10:00:00', - confirmed => 1, - cobrand => 'fixmybarangay', -}); - -FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'fixmybarangay' ], -}, sub { - FixMyStreet::DB->resultset('AlertType')->email_alerts(); -}; - -$mech->email_count_is(1); -$email = $mech->get_email; -like $email->body, qr/The following FixMyBarangay reports/, 'Start of email looks correct'; -$mech->clear_emails_ok; - -$mech->log_out_ok; -$mech->get_ok( '/report/' . $luz_report->id ); -$mech->content_lacks( "Remove from site" ); -$mech->content_contains( "Report abuse" ); - -$mech->post_ok('/report/delete/' . $luz_report->id); -is $mech->uri->path, '/report/' . $luz_report->id, "should redirect to report page, deletion ignored"; -$luz_report->discard_changes; -is $luz_report->state, 'confirmed', 'should be confirmed'; - -$user = $mech->log_in_ok($fmb_test_email); - -FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'fixmybarangay' ], -}, sub { - $mech->get_ok( '/report/' . $luz_report->id ); -}; -$mech->content_contains( "Remove from site" ); -$mech->content_lacks( "Report abuse" ); - -$mech->form_id('remove-from-site-form'); -$mech->submit_form(); -is $mech->uri->path, '/report/' . $luz_report->id, "should redirect to report page, deletion successful"; -$luz_report->discard_changes; -is $luz_report->state, 'hidden', 'should be hidden'; - -$mech->delete_user($fmb_test_email); - -$mech->delete_body($luz); -$mech->delete_body($bsn); -$mech->delete_body($dps); - -ok $mech->host("www.fixmystreet.com"), "change host back"; - -done_testing(); diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t index 9c20b7ad4..c6f6976d5 100644 --- a/t/cobrand/form_extras.t +++ b/t/cobrand/form_extras.t @@ -13,7 +13,6 @@ sub path_to_web_templates { my $self = shift; return [ FixMyStreet->path_to( 't/cobrand/form_extras/templates' )->stringify, - FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify ]; } 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(); diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 4734dc837..cf66136e5 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -661,7 +661,7 @@ subtest "external report triggers email" => sub { }; $email = $mech->get_email; my $report_id = $report->id; - like $email->header('Subject'), qr/Meldung #$report_id/, 'subject looks okay'; + like Encode::decode('MIME-Header', $email->header('Subject')), qr/Meldung #$report_id/, 'subject looks okay'; like $email->header('To'), qr/test\@example.com/, 'to line looks correct'; like $email->body, qr/$PUBLIC_RESPONSE/, 'public_response was passed on' or die $email->body; $mech->clear_emails_ok; @@ -894,6 +894,11 @@ subtest 'email images to external partners' => sub { my $expected_email_content = path(__FILE__)->parent->child('zurich_attachments.txt')->slurp; my $REPORT_ID = $report->id; + $expected_email_content =~ s{Subject: (.*?)\r?\n}{ + my $subj = Encode::decode('MIME-Header', $1); + $subj =~ s{REPORT_ID}{$REPORT_ID}g; + 'Subject: ' . Email::MIME::Encode::mime_encode($subj, "utf-8") . "\n"; + }eg; $expected_email_content =~ s{REPORT_ID}{$REPORT_ID}g; $expected_email_content =~ s{BOUNDARY}{$boundary}g; my $expected_email = Email::MIME->new($expected_email_content); diff --git a/t/cobrand/zurich_attachments.txt b/t/cobrand/zurich_attachments.txt index 4ccc90205..bdc4333bf 100644 --- a/t/cobrand/zurich_attachments.txt +++ b/t/cobrand/zurich_attachments.txt @@ -1,40 +1,33 @@ -MIME-Version: 1.0 -Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID -Content-Type: multipart/mixed; boundary="BOUNDARY" -To: "External Body" <external_body@example.org> -Content-Transfer-Encoding: 7bit -From: FixMyStreet <division@example.org> - - ---BOUNDARY -MIME-Version: 1.0 -Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID -Content-Type: text/plain; charset="iso-8859-1" -To: "External Body" <external_body@example.org> -Content-Transfer-Encoding: quoted-printable -From: FixMyStreet <division@example.org> - -Gr=FCezi External Body, - -=D6ffentliche URL: http://www.example.org/report/REPORT_ID - -Bei Fragen zu "Z=FCri wie neu" wenden Sie sich bitte an -gis-zentrum@zuerich.ch.= - - - ---BOUNDARY -MIME-Version: 1.0 -Content-Type: image/jpeg; name="REPORT_ID.0.jpeg" -Content-Disposition: inline; filename="REPORT_ID.0.jpeg" -Content-Transfer-Encoding: base64 - -/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEP -ERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4e -Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABTAAEDAREA -AhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAIIB//EAB8QAQAABAcAAAAAAAAAAAAAAAADBAbT -BxcYVVaUpf/EABcBAQEBAQAAAAAAAAAAAAAAAAAFBgT/xAAgEQEAAAQHAQAAAAAAAAAAAAAAAwQV -UgECFlNhodGx/9oADAMBAAIRAxEAPwCywAIozyxS5R58tbbujSW33j6zFRj3fGbKbjAGAgAACs9N -FCbtUfYg2mO1BM25e/V+lQeW3ISo/9k= - ---BOUNDARY-- +MIME-Version: 1.0
+Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID
+Content-Type: multipart/mixed; boundary="BOUNDARY"
+To: "External Body" <external_body@example.org>
+Content-Transfer-Encoding: 7bit
+From: "FixMyStreet" <division@example.org>
+
+
+--BOUNDARY
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Gr=C3=BCezi External Body,
+
+=C3=96ffentliche URL: http://www.example.org/report/REPORT_ID
+
+Bei Fragen zu "Z=C3=BCri wie neu" wenden Sie sich bitte an
+gis-zentrum@zuerich.ch.=
+
+--BOUNDARY
+Content-Type: image/jpeg; name="REPORT_ID.0.jpeg"
+Content-Disposition: inline; filename="REPORT_ID.0.jpeg"
+Content-Transfer-Encoding: base64
+
+/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEP
+ERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4e
+Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABTAAEDAREA
+AhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAIIB//EAB8QAQAABAcAAAAAAAAAAAAAAAADBAbT
+BxcYVVaUpf/EABcBAQEBAQAAAAAAAAAAAAAAAAAFBgT/xAAgEQEAAAQHAQAAAAAAAAAAAAAAAwQV
+UgECFlNhodGx/9oADAMBAAIRAxEAPwCywAIozyxS5R58tbbujSW33j6zFRj3fGbKbjAGAgAACs9N
+FCbtUfYg2mO1BM25e/V+lQeW3ISo/9k=
+
+--BOUNDARY--
@@ -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 ); @@ -56,10 +55,10 @@ my @EN_sorted = qw( A Å Ø Z ); my @NO_sorted = qw( A Z Ø Å ); 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(); @@ -71,14 +70,18 @@ my @default_sorted = qw( A Z Å Ø ); is_deeply( [ keysort { $_ } @random_sorted ], \@default_sorted, "keysort correctly with no locale" ); + skip 'Will not pass on Mac', 1 if $^O eq 'darwin'; + # Note - this obeys the locale is_deeply( [ sort { strcoll( $a, $b ) } @random_sorted ], \@EN_sorted, "sort strcoll correctly with no locale (to 'en_GB')" ); } -{ +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; @@ -93,7 +96,9 @@ my @default_sorted = qw( A Z Å Ø ); \@EN_sorted, "sort strcoll correctly with use locale 'en_GB'" ); } -{ +SKIP: { + skip 'Will not pass on Mac', 2 if $^O eq 'darwin'; + mySociety::Locale::negotiate_language( # 'nb-no,Norwegian,nb_NO', 'nb_NO' ); diff --git a/t/open311.t b/t/open311.t index 6333355e8..42d09b29c 100644 --- a/t/open311.t +++ b/t/open311.t @@ -3,6 +3,8 @@ use utf8; use strict; use warnings; +use File::Temp 'tempdir'; +use Path::Tiny; use Test::More; use Test::Warn; use FixMyStreet::DB; @@ -24,7 +26,7 @@ EOT is $o->_process_error( $err_text ), "400: Service Code cannot be null -- can't proceed with the request.\n", 'error text parsing'; is $o->_process_error( '503 - service unavailable' ), 'unknown error', 'error text parsing of bad error'; -my $o2 = Open311->new( endpoint => 'http://192.168.50.1/open311/', jurisdiction => 'example.org' ); +my $o2 = Open311->new( endpoint => 'http://127.0.0.1/open311/', jurisdiction => 'example.org' ); my $u = FixMyStreet::DB->resultset('User')->new( { email => 'test@example.org', name => 'A User' } ); @@ -258,16 +260,26 @@ subtest 'extended request update post parameters' => sub { }; subtest 'check media url set' => sub { - $comment->photo(1); + my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); + + my $image_path = path('t/app/controller/sample.jpg'); + $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); + + $comment->photo("0123456789012345678901234567890123456789"); $comment->cobrand('fixmystreet'); - my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); + FixMyStreet::override_config { + UPLOAD_DIR => $UPLOAD_DIR, + }, sub { + my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); - is $results->{ res }, 248, 'got update id'; + is $results->{ res }, 248, 'got update id'; - my $c = CGI::Simple->new( $results->{ req }->content ); - my $expected_path = '/c/' . $comment->id . '.full.jpeg'; - like $c->param('media_url'), qr/$expected_path/, 'image url included'; + my $c = CGI::Simple->new( $results->{ req }->content ); + my $expected_path = '/c/' . $comment->id . '.0.full.jpeg'; + like $c->param('media_url'), qr/$expected_path/, 'image url included'; + }; + $comment->photo(undef); }; foreach my $test ( diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 18a5802bb..134d5422e 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -38,7 +38,7 @@ UPDATED_DATETIME }; -my $dt = DateTime->now; +my $dt = DateTime->now(formatter => DateTime::Format::W3CDTF->new); # basic xml -> perl object tests for my $test ( @@ -388,7 +388,7 @@ subtest 'Update with media_url includes image in update' => sub { is $problem->comments->count, 1, 'comment count'; my $c = $problem->comments->first; is $c->external_id, 638344; - is $c->photo, '1cdd4329ceee2234bd4e89cb33b42061a0724687', 'photo exists'; + is $c->photo, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg', 'photo exists'; }; foreach my $test ( @@ -571,7 +571,8 @@ subtest 'check that existing comments are not duplicated' => sub { is $problem->comments->count, 1, 'one comment before fetching updates'; $requests_xml =~ s/UPDATED_DATETIME2/$dt/; - $requests_xml =~ s/UPDATED_DATETIME/@{[ $comment->confirmed ]}/; + my $confirmed = DateTime::Format::W3CDTF->format_datetime($comment->confirmed); + $requests_xml =~ s/UPDATED_DATETIME/$confirmed/; my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } ); @@ -596,12 +597,12 @@ subtest 'check that existing comments are not duplicated' => sub { foreach my $test ( { desc => 'check that closed and then open comment results in correct state', - dt1 => $dt->subtract( hours => 1 ), + dt1 => $dt->clone->subtract( hours => 1 ), dt2 => $dt, }, { desc => 'check that old comments do not change problem status', - dt1 => $dt->subtract( hours => 2 ), + dt1 => $dt->clone->subtract( minutes => 90 ), dt2 => $dt, } ) { @@ -627,7 +628,7 @@ foreach my $test ( { $problem->comments->delete; $problem->state( 'confirmed' ); - $problem->lastupdate( $dt->subtract( hours => 3 ) ); + $problem->lastupdate( $dt->clone->subtract( hours => 3 ) ); $problem->update; $requests_xml =~ s/UPDATED_DATETIME/$test->{dt1}/; @@ -683,7 +684,7 @@ foreach my $test ( { $problem->comments->delete; $problem->state( 'confirmed' ); - $problem->lastupdate( $dt->subtract( hours => 3 ) ); + $problem->lastupdate( $dt->clone->subtract( hours => 3 ) ); $problem->update; my @alerts = map { |