diff options
author | Marius Halden <marius.h@lden.org> | 2017-05-28 21:31:42 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2017-05-28 21:31:42 +0200 |
commit | 987124b09a32248414faf4d0d6615d43b29ac6f6 (patch) | |
tree | a549db8af723c981d3b346e855f25d6fd5ff8aa7 /t/app/controller | |
parent | dbf56159e44c1560a413022451bf1a1c4cb22a52 (diff) | |
parent | a085b63ce09f87e83b75cda9b9cd08aadfe75d61 (diff) |
Merge tag 'v2.0.4' into fiksgatami-dev
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/admin.t | 22 | ||||
-rw-r--r-- | t/app/controller/admin_permissions.t | 4 | ||||
-rw-r--r-- | t/app/controller/alert.t | 24 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 22 | ||||
-rw-r--r-- | t/app/controller/around.t | 20 | ||||
-rw-r--r-- | t/app/controller/auth.t | 4 | ||||
-rw-r--r-- | t/app/controller/auth_social.t | 9 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 4 | ||||
-rw-r--r-- | t/app/controller/index.t | 9 | ||||
-rw-r--r-- | t/app/controller/moderate.t | 21 | ||||
-rw-r--r-- | t/app/controller/my_planned.t | 16 | ||||
-rw-r--r-- | t/app/controller/photo.t | 2 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 6 | ||||
-rw-r--r-- | t/app/controller/report_as_other.t | 14 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 57 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 17 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 50 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 170 | ||||
-rw-r--r-- | t/app/controller/report_new_mobile.t | 8 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 9 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 51 | ||||
-rw-r--r-- | t/app/controller/reports.t | 63 | ||||
-rw-r--r-- | t/app/controller/rss.t | 6 |
23 files changed, 344 insertions, 264 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 1ab0cb488..5f8abe5a6 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -148,7 +146,7 @@ subtest 'check summary counts' => sub { # This override is wrapped around ALL the /admin/body tests FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', MAPIT_TYPES => [ 'UTA' ], BASE_URL => 'http://www.example.org', }, sub { @@ -208,7 +206,7 @@ subtest 'check contact creation' => sub { subtest 'check contact editing' => sub { $mech->get_ok('/admin/body/' . $body->id .'/test%20category'); - $mech->submit_form_ok( { with_fields => { + $mech->submit_form_ok( { with_fields => { email => 'test2@example.com', note => 'test2 note', non_public => undef, @@ -220,7 +218,18 @@ subtest 'check contact editing' => sub { $mech->content_contains( 'Private: No' ); $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); - $mech->submit_form_ok( { with_fields => { + $mech->submit_form_ok( { with_fields => { + email => 'test2@example.com, test3@example.com', + note => 'test3 note', + } } ); + + $mech->content_contains( 'test2@example.com,test3@example.com' ); + + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->content_contains( '<td><strong>test2@example.com,test3@example.com' ); + + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->submit_form_ok( { with_fields => { email => 'test2@example.com', note => 'test2 note', non_public => 'on', @@ -580,7 +589,6 @@ foreach my $test ( } FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', ALLOWED_COBRANDS => 'fixmystreet', }, sub { @@ -1190,6 +1198,7 @@ my %default_perms = ( "permissions[report_instruct]" => undef, "permissions[contribute_as_another_user]" => undef, "permissions[contribute_as_body]" => undef, + "permissions[view_body_contribute_details]" => undef, "permissions[user_edit]" => undef, "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, @@ -1203,7 +1212,6 @@ my %default_perms = ( FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', }, sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); for my $test ( { desc => 'edit user name', diff --git a/t/app/controller/admin_permissions.t b/t/app/controller/admin_permissions.t index 4b05660cc..dd256173d 100644 --- a/t/app/controller/admin_permissions.t +++ b/t/app/controller/admin_permissions.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -84,8 +82,6 @@ FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => [ 'oxfordshire' ], }, sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); - my $user2_id = $user2->id; $report->update({ bodies_str => $oxfordshire->id }); diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index c42eba6b8..cb5949b8f 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -17,7 +17,7 @@ $mech->content_contains('html class="no-js" lang="en-gb"'); # check that we can get list page FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', GEOCODER => '', }, sub { $mech->get_ok('/alert/list'); @@ -25,21 +25,21 @@ FixMyStreet::override_config { $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html class="no-js" lang="en-gb"'); - $mech->get_ok('/alert/list?pc=EH99 1SP'); + $mech->get_ok('/alert/list?pc=EH1 1BB'); $mech->title_like(qr/^Local RSS feeds and email alerts/); - $mech->content_contains('Here are the types of local problem alerts for ‘EH99 1SP’'); + $mech->content_contains('Here are the types of local problem alerts for ‘EH1 1BB’'); $mech->content_contains('html class="no-js" lang="en-gb"'); $mech->content_contains('Problems within 10.0km'); - $mech->content_contains('rss/pc/EH991SP/2'); - $mech->content_contains('rss/pc/EH991SP/5'); - $mech->content_contains('rss/pc/EH991SP/10'); - $mech->content_contains('rss/pc/EH991SP/20'); - $mech->content_contains('Problems within City of Edinburgh'); + $mech->content_contains('rss/pc/EH11BB/2'); + $mech->content_contains('rss/pc/EH11BB/5'); + $mech->content_contains('rss/pc/EH11BB/10'); + $mech->content_contains('rss/pc/EH11BB/20'); + $mech->content_contains('Problems within Edinburgh City'); $mech->content_contains('Problems within City Centre ward'); - $mech->content_contains('/rss/reports/City+of+Edinburgh'); - $mech->content_contains('/rss/reports/City+of+Edinburgh/City+Centre'); - $mech->content_contains('council:2651:City_of_Edinburgh'); - $mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); + $mech->content_contains('/rss/reports/Edinburgh'); + $mech->content_contains('/rss/reports/Edinburgh/City+Centre'); + $mech->content_contains('council:2651:Edinburgh'); + $mech->content_contains('ward:2651:20728:Edinburgh:City_Centre'); subtest "Test Nominatim lookup" => sub { LWP::Protocol::PSGI->register(t::Mock::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org'); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 1b85adf7e..ea38f7c25 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -208,7 +208,7 @@ foreach my $test ( FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/alert/list?pc=EH991SP'); }; @@ -312,7 +312,7 @@ subtest "Test two-tier council alerts" => sub { ) { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok( '/alert/list?pc=GL502PR' ); $mech->submit_form_ok( { @@ -351,7 +351,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { $mech->get_ok( '/alert' ); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH11BB' } } ); $mech->submit_form_ok( { @@ -371,7 +371,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { } } - my $dt = DateTime->now()->add( days => 2); + my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2); my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; @@ -436,7 +436,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { ok $update, "created test update - $update_id"; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); }; @@ -447,7 +447,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { for (@emails) { my $body = $mech->get_text_body_from_email($_); $count++ if $body =~ /The following updates have been left on this report:/; - $count++ if $body =~ /The following new FixMyStreet reports have been added in the City of\s+Edinburgh\s+Council area:/; + $count++ if $body =~ /The following new FixMyStreet reports have been added in the Area 2651 area:/; $count++ if $body =~ /The following FixMyStreet reports have been made within the area you\s+specified:/; $count++ if $body =~ /\s+-\s+Testing/; } @@ -486,7 +486,7 @@ subtest "Test signature template is used from cobrand" => sub { my $user2 = $mech->create_user_ok('alerts@example.com', name => 'Alert User' ); - my $dt = DateTime->now()->add( days => 2); + my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2); my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; @@ -542,7 +542,7 @@ subtest "Test signature template is used from cobrand" => sub { $mech->clear_emails_ok; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); @@ -570,7 +570,7 @@ subtest "Test signature template is used from cobrand" => sub { $mech->clear_emails_ok; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); @@ -665,7 +665,7 @@ for my $test ( $mech->clear_emails_ok; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); }; @@ -673,7 +673,7 @@ for my $test ( $report->update( { non_public => 0 } ); FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); }; diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 9e2e7c524..c8aca04aa 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -17,7 +15,7 @@ subtest "check that if no query we get sent back to the homepage" => sub { subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub { FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around?x=3281&y=1113'); }; @@ -73,8 +71,8 @@ foreach my $test ( foreach my $test ( { pc => 'SW1A 1AA', - latitude => '51.5', - longitude => '-2.1', + latitude => '51.501009', + longitude => '-0.141588', }, { pc => 'TQ 388 773', @@ -84,8 +82,6 @@ foreach my $test ( ) { subtest "check lat/lng for '$test->{pc}'" => sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); - $mech->get_ok('/'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], @@ -102,7 +98,7 @@ foreach my $test ( subtest 'check non public reports are not displayed on around page' => sub { my $params = { - postcode => 'EH99 1SP', + postcode => 'EH1 1BB', latitude => 55.9519637512, longitude => -3.17492254484, }; @@ -112,9 +108,9 @@ subtest 'check non public reports are not displayed on around page' => sub { $mech->get_ok('/'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } }, "good location" ); }; $mech->content_contains( 'Around page Test 3 for 2651', @@ -126,9 +122,9 @@ subtest 'check non public reports are not displayed on around page' => sub { $mech->get_ok('/'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } }, "good location" ); }; $mech->content_lacks( 'Around page Test 3 for 2651', diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 22ade6f4b..3a11cfc4a 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -56,6 +56,10 @@ for my $test ( is_deeply $mech->page_errors, [ $error_message ], 'errors match'; } +# Email address parsing should pass from here +my $resolver = Test::MockModule->new('Email::Valid'); +$resolver->mock('address', sub { $_[1] }); + # create a new account $mech->clear_emails_ok; $mech->get_ok('/auth'); diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t index f3eae32a7..09fdf22d3 100644 --- a/t/app/controller/auth_social.t +++ b/t/app/controller/auth_social.t @@ -1,13 +1,13 @@ use strict; use warnings; use Test::More; +use Test::MockModule; use LWP::Protocol::PSGI; use LWP::Simple; use JSON::MaybeXS; use t::Mock::Facebook; use t::Mock::Twitter; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -18,8 +18,6 @@ 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', TWITTER_KEY => 'twitter-key', @@ -30,6 +28,9 @@ FixMyStreet::override_config { my $fb_email = 'facebook@example.org'; my $fb_uid = 123456789; +my $resolver = Test::MockModule->new('Email::Valid'); +$resolver->mock('address', sub { 'facebook@example.org' }); + 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 { @@ -138,6 +139,8 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { } } +$resolver->mock('address', sub { 'twitter@example.org' }); + my $tw_email = 'twitter@example.org'; my $tw_uid = 987654321; diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 5ea5cb9f5..903affdcf 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -25,7 +25,7 @@ my $p_user = $mech->create_user_ok('p_user@example.com'); set_absolute_time('2014-03-01T12:00:00'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->not_logged_in_ok; @@ -48,7 +48,7 @@ FixMyStreet::override_config { with_fields => { email => $test_user, password_sign_in => $test_pass } } ); - $mech->content_contains( 'City of Edinburgh' ); + $mech->content_contains( 'Area 2651' ); FixMyStreet::App->model('DB::Contact')->search( { body_id => $body->id } ) ->delete; diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 6752d4d7e..6b28a03d2 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -12,12 +12,7 @@ subtest "check that the form goes to /around" => sub { $mech->get_ok('/'); is $mech->uri->path, '/', "still on '/'"; - # submit form - FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', - }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); - }; + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); # check that we are at /around is $mech->uri->path, '/around', "Got to /around"; @@ -52,7 +47,7 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { # get the uri and check for 302 FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok($uri); }; diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t index 0ccfcf2c2..10287ab22 100644 --- a/t/app/controller/moderate.t +++ b/t/app/controller/moderate.t @@ -67,7 +67,8 @@ subtest 'Auth' => sub { $mech->get_ok($REPORT_URL); $mech->content_lacks('Moderat'); - $mech->get_ok('/contact?m=1&id=' . $report->id); + $mech->get('/contact?m=1&id=' . $report->id); + is $mech->res->code, 400; $mech->content_lacks('Good bad bad bad'); }; @@ -100,6 +101,7 @@ subtest 'Problem moderation' => sub { problem_detail => 'Good good improved', }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); + $mech->content_like(qr/Moderated by Bromley Council/); $report->discard_changes; is $report->title, 'Good [...] good'; @@ -329,6 +331,23 @@ subtest 'Update 2' => sub { is $update2->text, 'update good good [...] good', }; +subtest 'Now stop being a staff user' => sub { + $user->update({ from_body => undef }); + $mech->get_ok($REPORT_URL); + $mech->content_contains('Moderated by Bromley Council'); +}; + +subtest 'And do it as a superuser' => sub { + $user->update({ is_superuser => 1 }); + $mech->get_ok($REPORT_URL); + $mech->submit_form_ok({ with_fields => { + %problem_prepopulated, + problem_title => 'Good good', + problem_detail => 'Good good improved', + }}); + $mech->content_contains('Moderated by a FixMyStreet administrator'); +}; + $update->delete; $update2->delete; $report->moderation_original_data->delete; diff --git a/t/app/controller/my_planned.t b/t/app/controller/my_planned.t index 7bd1dd2cd..fa463e61e 100644 --- a/t/app/controller/my_planned.t +++ b/t/app/controller/my_planned.t @@ -40,11 +40,23 @@ $mech->content_contains('Test Title'); $mech->get_ok($problem->url); $mech->content_contains('Shortlisted'); -$mech->submit_form_ok({ with_fields => { change => 'remove' } }); +$mech->submit_form_ok({ with_fields => { 'shortlist-remove' => 1 } }); $mech->content_contains('Shortlist'); -$mech->submit_form_ok({ with_fields => { change => 'add' } }); +$mech->submit_form_ok({ with_fields => { 'shortlist-add' => 1 } }); $mech->content_contains('Shortlisted'); +$mech->get_ok('/my/planned?sort=shortlist&ajax=1'); +$mech->content_contains('shortlist-up'); +$mech->content_contains('shortlist-down'); + +$mech->get_ok('/my/planned?sort=created-desc&ajax=1'); +$mech->content_lacks('shortlist-up'); +$mech->content_lacks('shortlist-down'); + +$mech->get_ok('/my/planned?ajax=1'); +$mech->content_contains('shortlist-up'); +$mech->content_contains('shortlist-down'); + done_testing(); END { diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t index 69c2ae866..ad857b5e3 100644 --- a/t/app/controller/photo.t +++ b/t/app/controller/photo.t @@ -30,7 +30,7 @@ subtest "Check multiple upload worked" => sub { # submit initial pc form FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', UPLOAD_DIR => $UPLOAD_DIR, }, sub { diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index b05f74225..f42908a3e 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -87,16 +87,19 @@ foreach my $test ( desc => 'User goes to questionnaire URL with a bad token', token_extra => 'BAD', content => "Sorry, that wasn’t a valid link", + code => 400, }, { desc => 'User goes to questionnaire URL for a now-hidden problem', state => 'hidden', content => "we couldn't locate your problem", + code => 400, }, { desc => 'User goes to questionnaire URL for an already answered questionnaire', answered => \'current_timestamp', content => 'already answered this questionnaire', + code => 400, }, ) { subtest $test->{desc} => sub { @@ -106,7 +109,8 @@ foreach my $test ( $questionnaire->update; (my $token = $token->token); $token .= $test->{token_extra} if $test->{token_extra}; - $mech->get_ok("/Q/$token"); + $mech->get("/Q/$token"); + is $mech->res->code, $test->{code}, "Right status received"; $mech->content_contains( $test->{content} ); # Reset, no matter what test did $report->state( 'confirmed' ); diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index 505a1bf6b..551a59481 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; use FixMyStreet::App; @@ -13,7 +11,7 @@ END { FixMyStreet::App->log->enable('info'); } my $mech = FixMyStreet::TestMech->new; -my $body = $mech->create_body_ok(2245, 'Wiltshire Council'); +my $body = $mech->create_body_ok(2237, 'Oxfordshire County Council'); my $contact1 = $mech->create_contact_ok( body_id => $body->id, category => 'Street lighting', email => 'highways@example.com' ); my $contact2 = $mech->create_contact_ok( body_id => $body->id, category => 'Potholes', email => 'potholes@example.com' ); @@ -38,7 +36,7 @@ subtest "Body user, has permission to add report as council" => sub { detail => 'Test report details.', category => 'Street lighting', ); - is $report->name, 'Wiltshire Council', 'report name is body'; + is $report->name, 'Oxfordshire County Council', 'report name is body'; is $report->user->name, 'Body User', 'user name unchanged'; is $report->user->id, $user->id, 'user matches'; is $report->anonymous, 0, 'report not anonymous'; @@ -59,7 +57,7 @@ subtest "Body user, has permission to add report as another user" => sub { is $report->user->name, 'Another User', 'user name matches'; is $report->user->email, 'another@example.net', 'user email correct'; isnt $report->user->id, $user->id, 'user does not match'; - like $mech->get_text_body_from_email, qr/Your report to Wiltshire Council has been logged/; + like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; push @users, $report->user; }; @@ -78,7 +76,7 @@ subtest "Body user, has permission to add report as another (existing) user" => is $report->user->name, 'Existing User', 'user name remains same'; is $report->user->email, 'existing@example.net', 'user email correct'; isnt $report->user->id, $user->id, 'user does not match'; - like $mech->get_text_body_from_email, qr/Your report to Wiltshire Council has been logged/; + like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; push @users, $report->user; }; @@ -88,7 +86,7 @@ subtest "Body user, has permission to add update as council" => sub { form_as => 'body', update => 'Test Update', ); - is $update->name, 'Wiltshire Council', 'update name is body'; + is $update->name, 'Oxfordshire County Council', 'update name is body'; is $update->user->name, 'Body User', 'user name unchanged'; is $update->user->id, $user->id, 'user matches'; is $update->anonymous, 0, 'update not anonymous'; @@ -134,7 +132,6 @@ END { sub start_report { my $permission = shift; - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); $_->delete for $user->user_body_permissions; $user->user_body_permissions->create({ body => $body, permission_type => $permission }) if $permission; @@ -191,4 +188,3 @@ sub dropdown_shown { my ($shown, $name) = @_; is grep({ $_ eq 'form_as' } keys %{$mech->visible_form_values($name)}), $shown, "Dropdown shown = $shown"; } - diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index fad8b2bbb..b35a4a026 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -210,13 +210,13 @@ foreach my $meta ( $report->update; subtest "test correct problem meta information" => sub { $mech->get_ok("/report/$report_id"); - + is $mech->extract_problem_meta, $meta->{meta}; }; } -for my $test ( +for my $test ( { description => 'new report', date => DateTime->now, @@ -385,7 +385,7 @@ for my $test ( my $body_westminster = $mech->create_body_ok(2504, 'Westminster City Council'); my $body_camden = $mech->create_body_ok(2505, 'Camden Borough Council'); -for my $test ( +for my $test ( { desc => 'no state dropdown if user not from authority', from_body => undef, @@ -530,6 +530,57 @@ subtest "Zurich banners are displayed correctly" => sub { }; }; +my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237); +my $oxfordshireuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $oxfordshire); + +subtest "check user details show when a user has correct permissions" => sub { + $report->update( { + name => 'Oxfordshire County Council', + user_id => $oxfordshireuser->id, + service => '', + anonymous => 'f', + bodies_str => $oxfordshire->id, + confirmed => '2012-01-10 15:17:00' + }); + + ok $oxfordshireuser->user_body_permissions->create({ + body => $oxfordshire, + permission_type => 'view_body_contribute_details', + }); + + $mech->log_in_ok( $oxfordshireuser->email ); + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Oxfordshire County Council (Council User) at 15:17, Tue 10 January 2012', + 'correct problem meta information'; + + ok $oxfordshireuser->user_body_permissions->delete_all, "Remove view_body_contribute_details permissions"; + + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012', + 'correct problem meta information for user without relevant permissions'; + + $mech->log_out_ok; + + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012', + 'correct problem meta information for logged out user'; + +}; + +subtest "check brackets don't appear when username and report name are the same" => sub { + $report->update( { + name => 'Council User' + }); + + $mech->log_in_ok( $oxfordshireuser->email ); + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Council User at 15:17, Tue 10 January 2012', + 'correct problem meta information'; +}; END { $mech->delete_user('test@example.com'); diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index c8cbcf412..b956b61ae 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -1,13 +1,15 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; use FixMyStreet::App; use Web::Scraper; use Path::Class; +use LWP::Protocol::PSGI; +use t::Mock::MapItZurich; + +LWP::Protocol::PSGI->register(t::Mock::MapItZurich->to_psgi_app, host => 'mapit.zurich'); my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/import'); @@ -92,8 +94,6 @@ subtest "Test creating bad partial entries" => sub { }; subtest "Submit a correct entry" => sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); - $mech->get_ok('/import'); $mech->submit_form_ok( # @@ -156,7 +156,6 @@ subtest "Submit a correct entry" => sub { phone => '', may_show_name => '1', category => '-- Pick a category --', - gender => undef, }, "check imported fields are shown"; @@ -193,7 +192,6 @@ subtest "Submit a correct entry" => sub { phone => '', may_show_name => '1', category => '-- Pick a category --', - gender => undef, }, "check imported fields are shown"; @@ -261,7 +259,7 @@ subtest "Submit a correct entry (with location)" => sub { # go to the token url FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok($token_url); }; @@ -281,14 +279,13 @@ subtest "Submit a correct entry (with location)" => sub { phone => '', may_show_name => '1', category => '-- Pick a category --', - gender => undef, }, "check imported fields are shown"; # change the details FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( # { @@ -321,7 +318,7 @@ subtest "Submit a correct entry (with location)" => sub { subtest "Submit a correct entry (with location) to cobrand" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', MAPIT_TYPES => [ 'O08' ], MAPIT_ID_WHITELIST => [], MAP_TYPE => 'Zurich,OSM', diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 4697cc9d1..69e43ad99 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -34,7 +34,7 @@ my $user = $mech->log_in_ok('test@example.com'); $user->update( { from_body => $oxon } ); FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => 'fixmystreet', }, sub { subtest "test inspect page" => sub { @@ -57,30 +57,33 @@ FixMyStreet::override_config { }; subtest "test basic inspect submission" => sub { - $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Planned' } }); + $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Action Scheduled', include_update => undef } }); $report->discard_changes; - is $report->state, 'planned', 'report state changed'; + is $report->state, 'action scheduled', 'report state changed'; is $report->get_extra_metadata('traffic_information'), 'Yes', 'report data changed'; }; subtest "test inspect & instruct submission" => sub { $report->unset_extra_metadata('inspected'); + $report->state('confirmed'); $report->update; - my $reputation = $report->user->get_extra_metadata("reputation") || 0; + $report->inspection_log_entry->delete; + my $reputation = $report->user->get_extra_metadata("reputation"); $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok({ button => 'save', with_fields => { public_update => "This is a public update.", save_inspected => "1" } }); + $mech->submit_form_ok({ button => 'save', with_fields => { public_update => "This is a public update.", include_update => "1", state => 'action scheduled' } }); $report->discard_changes; is $report->comments->first->text, "This is a public update.", 'Update was created'; is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected'; - is $report->user->get_extra_metadata('reputation'), $reputation+1, "User reputation was increased"; + is $report->user->get_extra_metadata('reputation'), $reputation, "User reputation wasn't changed"; }; subtest "test update is required when instructing" => sub { $report->unset_extra_metadata('inspected'); $report->update; + $report->inspection_log_entry->delete; $report->comments->delete_all; $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok({ button => 'save', with_fields => { public_update => undef, save_inspected => "1" } }); + $mech->submit_form_ok({ button => 'save', with_fields => { public_update => undef, include_update => "1" } }); is_deeply $mech->page_errors, [ "Please provide a public update for this report." ], 'errors match'; $report->discard_changes; is $report->comments->count, 0, "Update wasn't created"; @@ -117,7 +120,7 @@ FixMyStreet::override_config { $report->comments->delete_all; $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', duplicate_of => $report2->id, public_update => "This is a duplicate.", save_inspected => "1" } }); + $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', duplicate_of => $report2->id, public_update => "This is a duplicate.", include_update => "1" } }); $report->discard_changes; is $report->state, 'duplicate', 'report marked as duplicate'; @@ -136,7 +139,7 @@ FixMyStreet::override_config { state => 'Duplicate', duplicate_of => $report2->id, public_update => $update_text, - save_inspected => "1", + include_update => "1", }}); $report->discard_changes; @@ -174,22 +177,43 @@ FixMyStreet::override_config { }; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', ALLOWED_COBRANDS => 'oxfordshire', }, sub { subtest "test negative reputation" => sub { - my $reputation = $report->user->get_extra_metadata("reputation"); + my $reputation = $report->user->get_extra_metadata("reputation") || 0; $mech->get_ok("/report/$report_id"); $mech->submit_form( button => 'remove_from_site' ); $report->discard_changes; is $report->user->get_extra_metadata('reputation'), $reputation-1, "User reputation was decreased"; + $report->update({ state => 'confirmed' }); }; + + subtest "test positive reputation" => sub { + $report->unset_extra_metadata('inspected'); + $report->update; + $report->inspection_log_entry->delete if $report->inspection_log_entry; + my $reputation = $report->user->get_extra_metadata("reputation") || 0; + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok({ button => 'save', with_fields => { state => 'action scheduled', include_update => undef } }); + $report->discard_changes; + is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected'; + is $report->user->get_extra_metadata('reputation'), $reputation+1, "User reputation was increased"; + }; + + subtest "Oxfordshire-specific traffic management options are shown" => sub { + $report->update({ state => 'confirmed' }); + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Signs and Cones', state => 'Action Scheduled', include_update => undef } }); + $report->discard_changes; + is $report->state, 'action scheduled', 'report state changed'; + is $report->get_extra_metadata('traffic_information'), 'Signs and Cones', 'report data changed'; + }; + }; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', ALLOWED_COBRANDS => [ 'oxfordshire', 'fixmystreet' ], BASE_URL => 'http://fixmystreet.site', }, sub { @@ -201,7 +225,7 @@ FixMyStreet::override_config { # which should cause it to be resent. We clear the host because # otherwise testing stays on host() above. $mech->clear_host; - $mech->submit_form(button => 'save', with_fields => { category => 'Horses' }); + $mech->submit_form(button => 'save', with_fields => { category => 'Horses', include_update => undef, }); $report->discard_changes; is $report->category, "Horses", "Report in correct category"; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 6b4f40172..71090cd26 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -25,7 +25,7 @@ subtest "test that bare requests to /report/new get redirected" => sub { is_deeply { $mech->uri->query_form }, {}, "query empty"; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/report/new?pc=SW1A%201AA'); }; @@ -476,7 +476,7 @@ foreach my $test ( # submit initial pc form FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); @@ -498,7 +498,6 @@ 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"; @@ -550,7 +549,7 @@ foreach my $test ( $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -666,7 +665,7 @@ subtest "test password errors for a user who is signing in as they report" => su $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -718,7 +717,7 @@ subtest "test report creation for a user who is signing in as they report" => su $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -814,7 +813,7 @@ foreach my $test ( $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, "submit location" ); @@ -836,7 +835,6 @@ foreach my $test ( photo2 => '', photo3 => '', category => '-- Pick a category --', - gender => undef, }, "user's details prefilled" ); @@ -914,7 +912,7 @@ subtest "test report creation for a category that is non public" => sub { $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -976,7 +974,7 @@ $contact2->update; my $extra_details; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon ); }; @@ -985,7 +983,7 @@ ok !$extra_details->{titles_list}, 'Non Bromley does not send back list of title FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.4021&longitude=0.01578'); }; @@ -1005,7 +1003,7 @@ subtest "check that a lat/lon off coast leads to /around" => sub { my $off_coast_longitude = -0.646929; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok( # "/report/new" @@ -1027,7 +1025,7 @@ for my $test ( { desc => 'user title not set if not bromley problem', host => 'www.fixmystreet.com', - postcode => 'EH99 1SP', + postcode => 'EH1 1BB', fms_extra_title => '', extra => [], user_title => undef, @@ -1078,7 +1076,7 @@ for my $test ( subtest $test->{desc} => sub { my $override = { ALLOWED_COBRANDS => [ $test->{host} =~ /bromley/ ? 'bromley' : 'fixmystreet' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }; $mech->host( $test->{host} ); @@ -1195,9 +1193,9 @@ subtest 'user title not reset if no user title in submission' => sub { $mech->get_ok('/'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP', } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, @@ -1260,7 +1258,7 @@ subtest "test Hart" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'hart', 'fixmystreet' ], BASE_URL => 'http://www.fixmystreet.com', - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around'); $mech->content_contains( "Hart Council" ); @@ -1365,133 +1363,18 @@ subtest "test Hart" => sub { } }; -subtest "test SeeSomething" => sub { - $mech->host('seesomething.fixmystreet.com'); - $mech->clear_emails_ok; - $mech->log_out_ok; - - my $cobrand = FixMyStreet::Cobrand::SeeSomething->new(); - - my $body_ss = $mech->create_body_ok(2535, 'Sandwell Borough Council', id => 2535); - my $bus_contact = $mech->create_contact_ok( - body_id => $body_ss->id, - category => 'Bus', - email => 'bus@example.com', - non_public => 1, - ); - - for my $test ( { - desc => 'report with no user details works', - pc => 'WS1 4NH', - fields => { - detail => 'Test report details', - category => 'Bus', - subcategory => 'Smoking', - }, - email => $cobrand->anonymous_account->{email}, - }, - { - desc => 'report with user details works', - pc => 'WS1 4NH', - fields => { - detail => 'Test report details', - category => 'Bus', - subcategory => 'Smoking', - email => 'non_anon_user@example.com', - name => 'Non Anon', - }, - email => 'non_anon_user@example.com', - }, - { - desc => 'report with public category', - pc => 'WS1 4NH', - fields => { - detail => 'Test report details', - category => 'Bus', - subcategory => 'Smoking', - }, - email => $cobrand->anonymous_account->{email}, - public => 1, - } - ) { - subtest $test->{desc} => sub { - $mech->clear_emails_ok; - my $user = - FixMyStreet::App->model('DB::User')->find( { email => $test->{email} } ); - - if ( $user ) { - $user->alerts->delete; - $user->problems->delete; - $user->delete; - } - - if ( $test->{public} ) { - $bus_contact->non_public(0); - $bus_contact->update; - } else { - $bus_contact->non_public(1); - $bus_contact->update; - } - - $mech->get_ok( '/around' ); - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'seesomething' ], - MAPIT_URL => 'http://mapit.mysociety.org/', - }, sub { - $mech->submit_form_ok( - { - with_fields => { - pc => $test->{pc}, - }, - }, - 'submit around form', - ); - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); - - $mech->submit_form_ok( - { - with_fields => $test->{fields}, - }, - 'Submit form details with no user details', - ); - }; - is_deeply $mech->page_errors, [], "check there were no errors"; - - $user = - FixMyStreet::App->model('DB::User')->find( { email => $test->{email} } ); - ok $user, "user found"; - - my $report = $user->problems->first; - ok $report, "Found the report"; - - $mech->email_count_is(0); - - ok $report->confirmed, 'Report is confirmed automatically'; - - is $mech->uri->path, '/report/new', 'stays on report/new page'; - $mech->content_contains( 'Your report has been sent', 'use report created template' ); - - $user->alerts->delete; - $user->problems->delete; - $user->delete; - }; - } - - $bus_contact->delete; -}; - subtest "categories from deleted bodies shouldn't be visible for new reports" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham + $mech->get_ok('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); # Cheltenham ok $mech->content_contains( $contact3->category ); # Delete the body which the contact belongs to. $contact3->body->update( { deleted => 1 } ); - $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham + $mech->get_ok('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); # Cheltenham ok $mech->content_lacks( $contact3->category ); $contact3->body->update( { deleted => 0 } ); @@ -1501,12 +1384,12 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" => subtest "unresponsive body handling works" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { # Test body-level send method my $old_send = $contact1->body->send_method; $contact1->body->update( { send_method => 'Refused' } ); - $mech->get_ok('/report/new/ajax?latitude=55.9&longitude=-3.2'); # Edinburgh + $mech->get_ok('/report/new/ajax?latitude=55.952055&longitude=-3.189579'); # Edinburgh my $body_id = $contact1->body->id; ok $mech->content_like( qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id} ); @@ -1555,8 +1438,8 @@ subtest "unresponsive body handling works" => sub { phone => '07903 123 456', category => 'Trees', service => 'iOS', - lat => 55.9, - lon => -3.2, + lat => 55.952055, + lon => -3.189579, pc => '', used_map => '1', submit_register => '1', @@ -1582,7 +1465,7 @@ subtest "unresponsive body handling works" => sub { # And test per-category refusing my $old_email = $contact3->email; $contact3->update( { email => 'REFUSED' } ); - $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.89&longitude=-2.09'); + $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063'); ok $mech->content_like( qr/Cheltenham.*Trees.*unresponsive.*category=Trees/ ); $mech->get_ok('/around'); @@ -1616,7 +1499,6 @@ subtest "unresponsive body handling works" => sub { subtest "unresponsive body page works" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { my $old_send = $contact1->body->send_method; my $body_id = $contact1->body->id; @@ -1643,7 +1525,7 @@ subtest "extra google analytics code displayed on logged in problem creation" => FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], BASE_URL => 'https://www.fixmystreet.com', - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { # check that the user does not exist my $test_email = 'test-2@example.com'; @@ -1672,7 +1554,7 @@ subtest "extra google analytics code displayed on logged in problem creation" => $mech->submit_form_ok( { with_fields => { - title => "Test Report at café", + title => "Test Report at café", detail => 'Test report details.', photo1 => '', name => 'Joe Bloggs', @@ -1699,7 +1581,7 @@ subtest "extra google analytics code displayed on email confirmation problem cre FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], BASE_URL => 'https://www.fixmystreet.com', - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->log_out_ok; $mech->clear_emails_ok; diff --git a/t/app/controller/report_new_mobile.t b/t/app/controller/report_new_mobile.t index 61cb14a1b..3dfb99b2f 100644 --- a/t/app/controller/report_new_mobile.t +++ b/t/app/controller/report_new_mobile.t @@ -1,5 +1,7 @@ use Test::More; use FixMyStreet::TestMech; +use LWP::Protocol::PSGI; +use t::Mock::MapItZurich; my $mech = FixMyStreet::TestMech->new; @@ -7,10 +9,12 @@ my $mech = FixMyStreet::TestMech->new; FixMyStreet::App->log->disable('info'); END { FixMyStreet::App->log->enable('info'); } +LWP::Protocol::PSGI->register(t::Mock::MapItZurich->to_psgi_app, host => 'mapit.zurich'); + subtest "Check signed up for alert when logged in" => sub { FixMyStreet::override_config { - MAPIT_URL => 'http://global.mapit.mysociety.org', - MAPIT_TYPES => [ 'O06' ], + MAPIT_URL => 'http://mapit.zurich', + MAPIT_TYPES => [ 'O08' ], }, sub { $mech->log_in_ok('user@example.org'); $mech->post_ok( '/report/new/mobile', { diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index db6e07933..e3a464f88 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -12,7 +12,7 @@ END { FixMyStreet::App->log->enable('info'); } my $mech = FixMyStreet::TestMech->new; -my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council'); +my $body = $mech->create_body_ok(2245, 'Wiltshire Council'); $body->update({ endpoint => 'http://example.com/open311', jurisdiction => 'mySociety', @@ -27,7 +27,7 @@ my $contact1 = $mech->create_contact_ok( extra => [ { description => 'Lamppost number', code => 'number', required => 'True' }, { description => 'Lamppost type', code => 'type', required => 'False', values => { value => [ { name => ['Gas'], key => ['old'] }, { name => [ 'Yellow' ], key => [ 'modern' ] } ] } - } + } ], ); my $contact1b = $mech->create_contact_ok( @@ -117,7 +117,7 @@ foreach my $test ( # submit initial pc form FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); @@ -139,7 +139,6 @@ 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"; @@ -159,7 +158,7 @@ foreach my $test ( }; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => $new_values } ); }; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 5a88097fa..de153978b 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -131,6 +131,19 @@ for my $test ( }; } +subtest "updates displayed on report with empty bodies_str" => sub { + my $old_bodies_str = $report->bodies_str; + $report->update({ bodies_str => undef }); + $comment->update({ problem_state => 'fixed' , mark_open => 'false', mark_fixed => 'false' }); + + $mech->get_ok("/report/$report_id"); + + my $meta = $mech->extract_update_metas; + is scalar @$meta, 1, 'update displayed'; + + $report->update({ bodies_str => $old_bodies_str }); +}; + subtest "unconfirmed updates not displayed" => sub { $comment->state( 'unconfirmed' ); $comment->update; @@ -594,7 +607,7 @@ for my $test ( name => $user->name, may_show_name => 1, update => 'Set state to unable to fix', - state => 'unable to fix', + state => 'no further action', }, state => 'unable to fix', }, @@ -653,6 +666,18 @@ for my $test ( state => 'fixed - council', report_bodies => $body->id . ',2505', }, + { + desc => 'from authority user show username for users with correct permissions', + fields => { + name => $user->name, + may_show_name => 1, + update => 'Set state to fixed', + state => 'fixed', + }, + state => 'fixed - council', + report_bodies => $body->id . ',2505', + view_username => 1 + }, ) { subtest $test->{desc} => sub { $report->comments->delete; @@ -662,6 +687,14 @@ for my $test ( } $mech->log_in_ok( $user->email ); + + if ($test->{view_username}) { + ok $user->user_body_permissions->create({ + body => $body, + permission_type => 'view_body_contribute_details' + }), 'Give user view_body_contribute_details permissions'; + } + $user->from_body( $body->id ); $user->update; @@ -690,8 +723,14 @@ for my $test ( } else { like $update_meta->[0], qr/marked as $meta_state$/, 'update meta includes state change'; } - like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name'; - $mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold'); + + if ($test->{view_username}) { + like $update_meta->[0], qr{Westminster City Council \(Test User\)}, 'update meta includes council and user name'; + $user->user_body_permissions->delete_all; + } else { + like $update_meta->[0], qr{Westminster City Council}, 'update meta includes council name'; + $mech->content_contains( '<strong>Westminster City Council</strong>', 'council name in bold'); + } $report->discard_changes; is $report->state, $test->{state}, 'state set'; @@ -1829,7 +1868,8 @@ for my $test ( subtest 'check have to be logged in for creator fixed questionnaire' => sub { $mech->log_out_ok(); - $mech->get_ok( "/questionnaire/submit?problem=$report_id&reported=Yes" ); + $mech->get( "/questionnaire/submit?problem=$report_id&reported=Yes" ); + is $mech->res->code, 400, "got 400"; $mech->content_contains( "I'm afraid we couldn't locate your problem in the database." ) }; @@ -1838,7 +1878,8 @@ subtest 'check cannot answer other user\'s creator fixed questionnaire' => sub { $mech->log_out_ok(); $mech->log_in_ok( $user2->email ); - $mech->get_ok( "/questionnaire/submit?problem=$report_id&reported=Yes" ); + $mech->get( "/questionnaire/submit?problem=$report_id&reported=Yes" ); + is $mech->res->code, 400, "got 400"; $mech->content_contains( "I'm afraid we couldn't locate your problem in the database." ) }; diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 141269cd8..a21d3ad65 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -107,7 +107,7 @@ is $stats->{'Fife Council'}->[4], 3, 'correct number of fixed reports for Fife'; is $stats->{'Fife Council'}->[5], 1, 'correct number of older fixed reports for Fife'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->follow_link_ok( { text_regex => qr/Birmingham/ } ); $mech->get_ok('/reports/Westminster'); @@ -121,7 +121,7 @@ my $problems = $mech->extract_problem_list; is scalar @$problems, 5, 'correct number of problems displayed'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports'); $mech->follow_link_ok({ url_regex => qr{/reports/Electricity_Gas\+Council} }); @@ -133,7 +133,7 @@ $problems = $mech->extract_problem_list; is scalar @$problems, 2, 'correct number of new problems displayed'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports/City+of+Edinburgh?t=older'); }; @@ -169,7 +169,7 @@ for my $test ( ) { subtest $test->{desc} => sub { FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports/Fife+Council?t=' . $test->{type}); }; @@ -183,7 +183,7 @@ my $private = $westminster_problems[2]; ok $private->update( { non_public => 1 } ), 'problem marked non public'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports/Westminster'); }; @@ -213,7 +213,7 @@ subtest "test fiksgatami all reports page" => sub { subtest "test greenwich all reports page" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'greenwich' ], - MAPIT_URL => 'http://mapit.mysociety.org/' + MAPIT_URL => 'http://mapit.uk/' }, sub { my $body = $mech->create_body_ok(2493, 'Royal Borough of Greenwich'); my $deleted_contact = $mech->create_contact_ok( @@ -233,5 +233,54 @@ subtest "test greenwich all reports page" => sub { } }; -done_testing(); +subtest "it lists shortlisted reports" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/' + }, sub { + my $body = FixMyStreet::App->model('DB::Body')->find( $body_edin_id ); + my $user = $mech->log_in_ok( 'test@example.com' ); + $user->update({ from_body => $body }); + $user->user_body_permissions->find_or_create({ + body => $body, + permission_type => 'planned_reports', + }); + + my ($shortlisted_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Shortlisted report'); + my ($unshortlisted_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Unshortlisted report'); + my ($removed_from_shortlist_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Removed from shortlist report'); + + $user->add_to_planned_reports($shortlisted_problem); + $user->add_to_planned_reports($removed_from_shortlist_problem); + $user->remove_from_planned_reports($removed_from_shortlist_problem); + + $mech->get_ok('/reports/City+of+Edinburgh+Council'); + $mech->content_contains('<option value="shortlisted">Shortlisted</option>'); + $mech->content_contains('<option value="unshortlisted">Unshortlisted</option>'); + + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=shortlisted'); + + $mech->content_contains('Shortlisted report'); + $mech->content_lacks('Unshortlisted report'); + $mech->content_lacks('Removed from shortlist report'); + + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=shortlisted,open'); + $mech->content_contains('Shortlisted report'); + $mech->content_lacks('Unshortlisted report'); + $mech->content_lacks('Removed from shortlist report'); + + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=unshortlisted,open'); + + $mech->content_contains('Unshortlisted report'); + $mech->content_contains('Removed from shortlist report'); + $mech->content_lacks('Shortlisted report'); + + $user->admin_user_body_permissions->delete; + + $mech->get_ok('/reports/City+of+Edinburgh+Council'); + $mech->content_lacks('<option value="shortlisted">Shortlisted</option>'); + $mech->content_lacks('<option value="unshortlisted">Unshortlisted</option>'); + }; +}; + +done_testing(); diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t index 4f737dda7..bec504760 100644 --- a/t/app/controller/rss.t +++ b/t/app/controller/rss.t @@ -44,7 +44,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { $mech->host('www.fixmystreet.com'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmystreet' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok("/rss/pc/EH11BB/2"); }; @@ -118,7 +118,7 @@ $report->update(); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmystreet' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok("/rss/pc/EH11BB/2"); }; @@ -186,7 +186,7 @@ subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" = FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'hart' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok("/rss/area/Hart"); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('hart')->new(); |