diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/about.t | 13 | ||||
-rw-r--r-- | t/app/controller/admin.t | 19 | ||||
-rw-r--r-- | t/app/controller/alert.t | 4 | ||||
-rw-r--r-- | t/app/controller/around.t | 4 | ||||
-rw-r--r-- | t/app/controller/auth_social.t | 143 | ||||
-rw-r--r-- | t/app/controller/my.t | 7 | ||||
-rw-r--r-- | t/app/controller/page_not_found.t | 2 | ||||
-rw-r--r-- | t/app/controller/photo.t | 3 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 2 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 19 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 96 | ||||
-rw-r--r-- | t/app/controller/report_new_mobile.t | 38 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 5 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 131 | ||||
-rw-r--r-- | t/app/controller/rss.t | 2 |
15 files changed, 394 insertions, 94 deletions
diff --git a/t/app/controller/about.t b/t/app/controller/about.t index fb0744d6a..6a082a2ff 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -7,10 +7,19 @@ 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_like(qr{About us ::\s+FixMyStreet}); +$mech->get_ok('/faq'); +$mech->content_like(qr{Frequently Asked Questions ::\s+FixMyStreet}); $mech->content_contains('html class="no-js" lang="en-gb"'); +$mech->get_ok('/privacy'); +is $mech->res->code, 200, "got 200 for final destination"; +is $mech->res->previous->code, 302, "got 302 for redirect"; +is $mech->uri->path, '/about/privacy'; + +$mech->get('/about/page-that-does-not-exist'); +ok !$mech->res->is_success(), "want a bad response"; +is $mech->res->code, 404, "got 404"; + FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'emptyhomes' ], }, sub { diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index e2dd5df19..92cbbc00f 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -6,18 +6,11 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -my $secret = FixMyStreet::App->model('DB::Secret')->search(); - -# don't explode if there's nothing in the secret table -if ( $secret == 0 ) { - diag "You need to put an entry in the secret table for the admin tests to run"; - plan skip_all => 'No entry in secret table'; -} - my $user = FixMyStreet::App->model('DB::User') - ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); + ->find_or_create( { email => 'test@example.com' } ); ok $user, "created test user"; +$user->update({ name => 'Test User' }); my $user2 = FixMyStreet::App->model('DB::User') @@ -70,8 +63,8 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( { - alert_type => 'new_updates', - parameter => $report->id, + alert_type => 'area_problems', + parameter => 2482, confirmed => 1, user => $user, }, @@ -1240,9 +1233,7 @@ subtest "Check admin_base_url" => sub { my $rs = FixMyStreet::App->model('DB::Problem'); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($report->cobrand)->new(); - is (FixMyStreet::App->model('DB::Problem')->get_admin_url( - $cobrand, - $report), + is ($report->admin_url($cobrand), (sprintf 'https://secure.mysociety.org/admin/bci/report_edit/%d', $report_id), 'get_admin_url OK'); }; diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 5bf2af428..c7dc9ed09 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -6,7 +6,7 @@ use LWP::Protocol::PSGI; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -use t::Nominatim; +use t::Mock::Nominatim; # check that we can get the page $mech->get_ok('/alert'); @@ -42,7 +42,7 @@ FixMyStreet::override_config { $mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); subtest "Test Nominatim lookup" => sub { - LWP::Protocol::PSGI->register(t::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org'); + LWP::Protocol::PSGI->register(t::Mock::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org'); $mech->get_ok('/alert/list?pc=High Street'); $mech->content_contains('We found more than one match for that location'); }; diff --git a/t/app/controller/around.t b/t/app/controller/around.t index a70116525..89ca5246e 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -3,7 +3,7 @@ use warnings; use Test::More; use LWP::Protocol::PSGI; -use t::MapIt; +use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -84,7 +84,7 @@ foreach my $test ( ) { subtest "check lat/lng for '$test->{pc}'" => sub { - LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.uk'); + LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); $mech->get_ok('/'); FixMyStreet::override_config { diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t new file mode 100644 index 000000000..84fdd4dfe --- /dev/null +++ b/t/app/controller/auth_social.t @@ -0,0 +1,143 @@ +use strict; +use warnings; +use Test::More; +use LWP::Protocol::PSGI; +use LWP::Simple; +use JSON::MaybeXS; + +use t::Mock::Facebook; +use t::Mock::MapIt; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +my ($report) = $mech->create_problems_for_body(1, '2345', 'Test'); + +LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk'); + +FixMyStreet::override_config { + FACEBOOK_APP_ID => 'facebook-app-id', + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', +}, sub { + +my $fb_email = 'facebook@example.org'; +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 { + $mech->log_out_ok; + if ($fb_state eq 'existing UID') { + my $user = $mech->create_user_ok($fb_email); + $user->update({ facebook_id => $fb_uid }); + } else { + $mech->delete_user($fb_email); + } + + # Set up a mock to catch (most, see below) requests to Facebook + my $fb = t::Mock::Facebook->new; + $fb->returns_email(0) if $fb_state eq 'no email' || $fb_state eq 'existing UID'; + LWP::Protocol::PSGI->register($fb->to_psgi_app, host => 'www.facebook.com'); + LWP::Protocol::PSGI->register($fb->to_psgi_app, host => 'graph.facebook.com'); + + # Due to https://metacpan.org/pod/Test::WWW::Mechanize::Catalyst#External-Redirects-and-allow_external + # the redirect to Facebook's OAuth page can mess up the session + # cookie. So let's pretend we always on www.facebook.com, which + # sorts that out. + $mech->host('www.facebook.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 => 'facebook_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, 'FB button redirected'; + like $mech->res->previous->header('Location'), qr{facebook\.com.*dialog/oauth.*facebook-app-id}, 'FB redirect to oauth URL'; + + # Okay, now call the callback Facebook would send us to + if ($fb_state eq 'refused') { + $mech->get_ok('/auth/Facebook?error_code=ERROR'); + } else { + $mech->get_ok('/auth/Facebook?code=response-code'); + } + + # 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 ($fb_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 ($fb_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} = $fb_email; + } else { + $fields->{email} = $fb_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 => $fb_email } ); + if ($page eq 'my') { + is $user, undef, 'No user yet exists'; + } else { + is $user->facebook_id, undef, 'User has no facebook ID'; + } + $mech->get_ok( $url . $url_token ); + $user = FixMyStreet::App->model( 'DB::User' )->find( { email => $fb_email } ); + is $user->facebook_id, $fb_uid, 'User now has correct facebook 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 { + $mech->delete_problems_for_body('2345'); + done_testing(); +} diff --git a/t/app/controller/my.t b/t/app/controller/my.t index b723e537e..d24a66c8e 100644 --- a/t/app/controller/my.t +++ b/t/app/controller/my.t @@ -9,12 +9,17 @@ my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/my'); is $mech->uri->path, '/auth', "got sent to the sign in page"; +$mech->create_problems_for_body(1, 1234, 'Test Title'); + # sign in my $user = $mech->log_in_ok( 'test@example.com' ); $mech->get_ok('/my'); is $mech->uri->path, '/my', "stayed on '/my/' page"; +# Report listed +$mech->content_contains('Test Title'); + # cleanup $mech->delete_user( $user ); - +$mech->delete_problems_for_body(1234); done_testing(); diff --git a/t/app/controller/page_not_found.t b/t/app/controller/page_not_found.t index 05e983109..3c2bc3c3d 100644 --- a/t/app/controller/page_not_found.t +++ b/t/app/controller/page_not_found.t @@ -1,5 +1,3 @@ -#!/usr/bin/perl - use strict; use warnings; diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t index 6e61ebb32..39380e769 100644 --- a/t/app/controller/photo.t +++ b/t/app/controller/photo.t @@ -64,6 +64,9 @@ 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}], + 'Three uploaded pictures are all shown, safe'); $mech->content_contains( 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687"', 'Returned upload_fileid contains expected hash, 3 times'); diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index 2a89454d5..7718d5034 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -87,7 +87,7 @@ foreach my $test ( { desc => 'User goes to questionnaire URL with a bad token', token_extra => 'BAD', - content => "we couldn't validate that token", + content => "Sorry, that wasn’t a valid link", }, { desc => 'User goes to questionnaire URL for a now-hidden problem', diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 4d0f6e5d1..26acf7790 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -3,7 +3,7 @@ use warnings; use Test::More; use LWP::Protocol::PSGI; -use t::MapIt; +use t::Mock::MapIt; use FixMyStreet::TestMech; use FixMyStreet::App; use Web::Scraper; @@ -92,7 +92,7 @@ subtest "Test creating bad partial entries" => sub { }; subtest "Submit a correct entry" => sub { - LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.uk'); + LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); $mech->get_ok('/import'); @@ -153,10 +153,13 @@ subtest "Submit a correct entry" => sub { name => 'Test User', title => 'Test report', detail => 'This is a test report', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', phone => '', may_show_name => '1', category => '-- Pick a category --', + gender => undef, }, "check imported fields are shown"; @@ -187,10 +190,13 @@ subtest "Submit a correct entry" => sub { name => 'Test User', title => 'Test report', detail => 'This is a test report', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', phone => '', may_show_name => '1', category => '-- Pick a category --', + gender => undef, }, "check imported fields are shown"; @@ -275,10 +281,13 @@ subtest "Submit a correct entry (with location)" => sub { name => 'Test User ll', title => 'Test report ll', detail => 'This is a test report ll', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', phone => '', may_show_name => '1', category => '-- Pick a category --', + gender => undef, }, "check imported fields are shown"; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 3c05adfbd..cf72221b4 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -103,7 +103,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -127,7 +129,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -154,7 +158,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -178,7 +184,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => undef, email => '', @@ -202,7 +210,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => undef, email => '', @@ -225,7 +235,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => '', @@ -248,7 +260,9 @@ foreach my $test ( fields => { title => "DOG SHIT\r\nON WALLS", detail => "on this portakabin -\r\n\r\nmore of a portaloo HEH!!", - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => '', @@ -271,7 +285,9 @@ foreach my $test ( fields => { title => 'Test title', detail => 'Test detail', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'DUDE', may_show_name => '1', email => '', @@ -293,7 +309,9 @@ foreach my $test ( fields => { title => 'Test title', detail => 'Test detail', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'anonymous', may_show_name => '1', email => '', @@ -315,7 +333,9 @@ foreach my $test ( fields => { title => 'Test title', detail => 'Test detail', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Joe Smith', may_show_name => '1', email => 'not an email', @@ -334,7 +354,9 @@ foreach my $test ( fields => { title => " Test title ", detail => " first line \n\n second\nline\n\n ", - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -359,7 +381,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => ' Bob Jones ', may_show_name => '1', email => ' BOB @ExAmplE.COM ', @@ -381,7 +405,9 @@ foreach my $test ( fields => { title => 'Title', detail => 'Detail', - photo => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ], + photo1 => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ], + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => 'bob@example.com', @@ -392,7 +418,7 @@ foreach my $test ( remember_me => undef, }, changes => { - photo => '', + photo1 => '', }, errors => [ "Please upload a JPEG image only" ], }, @@ -402,7 +428,9 @@ foreach my $test ( fields => { title => 'Title', detail => 'Detail', - photo => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ], + photo1 => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ], + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => 'bob@example.com', @@ -413,7 +441,7 @@ foreach my $test ( remember_me => undef, }, changes => { - photo => '', + photo1 => '', }, errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ], }, @@ -423,7 +451,9 @@ foreach my $test ( fields => { title => '', detail => 'Detail', - photo => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ], + photo1 => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ], + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => 'bob@example.com', @@ -434,7 +464,7 @@ foreach my $test ( remember_me => undef, }, changes => { - photo => '', + photo1 => '', }, errors => [ "Please enter a subject" ], }, @@ -468,6 +498,7 @@ foreach my $test ( my $new_values = { %{ $test->{fields} }, # values added to form %{ $test->{changes} }, # changes we expect + gender => undef, }; is_deeply $mech->visible_form_values, $new_values, "values correctly changed"; @@ -534,7 +565,7 @@ foreach my $test ( with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', email => 'test-1@example.com', @@ -652,7 +683,7 @@ subtest "test password errors for a user who is signing in as they report" => su with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', email => 'test-2@example.com', password_sign_in => 'secret1', category => 'Street lighting', @@ -704,7 +735,7 @@ subtest "test report creation for a user who is signing in as they report" => su with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', email => 'test-2@example.com', password_sign_in => 'secret2', category => 'Street lighting', @@ -803,8 +834,11 @@ foreach my $test ( may_show_name => '1', name => 'Test User', phone => '01234 567 890', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', category => '-- Pick a category --', + gender => undef, }, "user's details prefilled" ); @@ -814,7 +848,7 @@ foreach my $test ( with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', phone => '07903 123 456', @@ -898,7 +932,7 @@ subtest "test report creation for a category that is non public" => sub { with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', email => 'test-2@example.com', name => 'Joe Bloggs', category => 'Street lighting', @@ -1087,7 +1121,7 @@ for my $test ( my $submission_fields = { title => "Test Report", detail => 'Test report details.', - photo => '', + photo1 => '', email => 'firstlast@example.com', may_show_name => '1', phone => '07903 123 456', @@ -1156,7 +1190,7 @@ subtest 'user title not reset if no user title in submission' => sub { my $submission_fields = { title => "Test Report", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Has Title', may_show_name => '1', phone => '07903 123 456', @@ -1250,7 +1284,7 @@ subtest "test Hart" => sub { with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', category => $test->{category}, @@ -1484,7 +1518,7 @@ subtest "unresponsive body handling works" => sub { with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', email => $test_email, may_show_name => '1', @@ -1523,7 +1557,7 @@ subtest "unresponsive body handling works" => sub { with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', email => $test_email, may_show_name => '1', @@ -1604,7 +1638,7 @@ subtest "extra google analytics code displayed on logged in problem creation" => with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', phone => '07903 123 456', @@ -1646,7 +1680,7 @@ subtest "extra google analytics code displayed on email confirmation problem cre my $submission_fields = { title => "Test Report", detail => 'Test report details.', - photo => '', + photo1 => '', email => 'firstlast@example.com', name => 'Test User', may_show_name => '1', diff --git a/t/app/controller/report_new_mobile.t b/t/app/controller/report_new_mobile.t new file mode 100644 index 000000000..61cb14a1b --- /dev/null +++ b/t/app/controller/report_new_mobile.t @@ -0,0 +1,38 @@ +use Test::More; +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +subtest "Check signed up for alert when logged in" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://global.mapit.mysociety.org', + MAPIT_TYPES => [ 'O06' ], + }, sub { + $mech->log_in_ok('user@example.org'); + $mech->post_ok( '/report/new/mobile', { + service => 'iPhone', + title => 'Title', + detail => 'Problem detail', + lat => 47.381817, + lon => 8.529156, + email => 'user@example.org', + pc => '', + name => 'Name', + }); + my $res = $mech->response; + ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json'; + + my $user = FixMyStreet::DB->resultset('User')->search({ email => 'user@example.org' })->first; + my $a = FixMyStreet::DB->resultset('Alert')->search({ user_id => $user->id })->first; + isnt $a, undef, 'User is signed up for alert'; + }; +}; + +END { + $mech->delete_user('user@example.org'); + done_testing(); +} diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index d3ca93f0e..22b37fd55 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -45,7 +45,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -129,6 +131,7 @@ foreach my $test ( my $new_values = { %{ $test->{fields} }, # values added to form %{ $test->{changes} }, # changes we expect + gender => undef, }; is_deeply $mech->visible_form_values, $new_values, "values correctly changed"; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 6c6b4ca19..f9f5189e5 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -199,7 +199,9 @@ for my $test ( rznvy => '', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -216,7 +218,9 @@ for my $test ( rznvy => 'test', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -233,7 +237,9 @@ for my $test ( rznvy => 'test @ example. com', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -252,7 +258,9 @@ for my $test ( rznvy => 'test@EXAMPLE.COM', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -292,7 +300,9 @@ for my $test ( rznvy => '', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, remember_me => undef, @@ -316,7 +326,9 @@ for my $test ( rznvy => '', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, remember_me => undef, @@ -417,7 +429,9 @@ for my $test ( rznvy => '', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, remember_me => undef, @@ -502,7 +516,9 @@ subtest 'check non authority user cannot change set state' => sub { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'this is a forbidden update', state => 'fixed - council', }, @@ -530,7 +546,9 @@ for my $state ( qw/unconfirmed hidden partial/ ) { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'this is a forbidden update', state => $state, }, @@ -553,7 +571,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to investigating', state => 'investigating', }, @@ -565,7 +585,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to in progress', state => 'in progress', }, @@ -577,7 +599,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to fixed', state => 'fixed', }, @@ -589,7 +613,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to action scheduled', state => 'action scheduled', }, @@ -601,7 +627,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to unable to fix', state => 'unable to fix', }, @@ -613,7 +641,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to internal referral', state => 'internal referral', }, @@ -626,7 +656,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to not responsible', state => 'not responsible', }, @@ -639,7 +671,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to duplicate', state => 'duplicate', }, @@ -652,7 +686,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to internal referral', state => 'internal referral', }, @@ -665,7 +701,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to fixed', state => 'fixed', }, @@ -783,7 +821,9 @@ subtest "check comment with no status change has not status in meta" => sub { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Comment that does not change state', }, }, @@ -813,7 +853,9 @@ subtest "check comment with no status change has not status in meta" => sub { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Comment that sets state to investigating', state => 'investigating', }, @@ -1049,6 +1091,9 @@ subtest 'submit an update for a registered user, creating update by email' => su $mech->delete_user( $user ); }; +my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; +ok -e $sample_file, "sample file $sample_file exists"; + for my $test ( { desc => 'submit update for registered user', @@ -1056,7 +1101,9 @@ for my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1066,6 +1113,7 @@ for my $test ( update => 'update from a registered user', add_alert => undef, fixed => undef, + photo1 => [ [ $sample_file, undef, Content_Type => 'image/jpeg' ], 1 ], }, changed => { update => 'Update from a registered user' @@ -1081,7 +1129,9 @@ for my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1107,7 +1157,9 @@ for my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1132,7 +1184,9 @@ for my $test ( name => 'Commenter', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1157,7 +1211,9 @@ for my $test ( name => 'Commenter', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', }, email => 'commenter@example.com', @@ -1210,6 +1266,11 @@ for my $test ( $mech->content_contains("/report/" . $report_id); $mech->get_ok("/report/" . $report_id); + my $update = $report->comments->first; + ok $update, 'found update'; + + $mech->content_contains("/photo/c/" . $update->id . ".0.jpeg") if $test->{fields}->{photo1}; + if ( !defined( $test->{endstate_banner} ) ) { is $mech->extract_problem_banner->{text}, undef, 'endstate banner'; } else { @@ -1223,8 +1284,6 @@ for my $test ( %{ $test->{changed} }, }; - my $update = $report->comments->first; - ok $update, 'found update'; is $update->text, $results->{update}, 'update text'; is $update->user->email, $test->{email}, 'update user'; is $update->state, 'confirmed', 'update confirmed'; @@ -1245,7 +1304,9 @@ foreach my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1271,7 +1332,9 @@ foreach my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1298,7 +1361,9 @@ foreach my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1771,7 +1836,9 @@ for my $test ( my %standard_fields = ( name => $report->user->name, update => 'update text', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', may_show_name => 1, add_alert => 1, ); diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t index db653c094..3e820cff3 100644 --- a/t/app/controller/rss.t +++ b/t/app/controller/rss.t @@ -181,7 +181,7 @@ my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_c subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" => sub { $mech->host('hart.fixmystreet.com'); - my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id; + my $expected1 = FixMyStreet->config('BASE_URL') . '/report/' . $report_to_county_council->id; my $expected2; FixMyStreet::override_config { |