diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Council.pm | 1 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/FakeMapit.pm | 53 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 26 | ||||
-rw-r--r-- | t/app/controller/around.t | 2 | ||||
-rw-r--r-- | t/app/controller/auth.t | 4 | ||||
-rw-r--r-- | t/app/controller/contact.t | 37 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 24 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 12 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 8 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 4 | ||||
-rw-r--r-- | templates/web/fixmystreet/index.html | 4 |
15 files changed, 121 insertions, 68 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index 48248e4fe..771603c22 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -37,6 +37,7 @@ there are no councils then return false. sub load_and_check_councils : Private { my ( $self, $c ) = @_; + my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; diff --git a/perllib/FixMyStreet/App/Controller/FakeMapit.pm b/perllib/FixMyStreet/App/Controller/FakeMapit.pm new file mode 100755 index 000000000..bc46df712 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/FakeMapit.pm @@ -0,0 +1,53 @@ +package FixMyStreet::App::Controller::FakeMapit; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::FakeMapit - Catalyst Controller + +=head1 DESCRIPTION + +A controller to fake mapit when we don't have it. If you set MAPIT_URL to +.../fakemapit/ it should all just work, with a mapit that assumes the whole +world is one area, with ID 161 and name "Default Area". + +=head1 METHODS + +=cut + +my $area = { "name" => "Default Area", "type" => "ZZZ", "id" => 161 }; + +sub output : Private { + my ( $self, $c, $data ) = @_; + my $body = JSON->new->utf8(1)->encode( $data ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body( $body ); +} + +sub point : Local { + my ( $self, $c ) = @_; + $c->detach( 'output', [ { 161 => $area } ] ); +} + +sub area : Local { + my ( $self, $c ) = @_; + $c->detach( 'output', [ $area ] ); +} + +sub areas : Local { + my ( $self, $c ) = @_; + $c->detach( 'output', [ { 161 => $area } ] ); +} + +sub children : Path('area/161/children') : Args(0) { + my ( $self, $c ) = @_; + $c->detach( 'output', [ {} ] ); +} + +__PACKAGE__->meta->make_immutable; + +1; + diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 9a7bb6192..3ef0410a9 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -43,6 +43,7 @@ sub index : Path : Args(0) { $c->stash->{message} = _("Unable to look up areas in MaPit. Please try again later.") . ' ' . sprintf(_('The error was: %s'), $@); $c->stash->{template} = 'errors/generic.html'; + return; } # For each area, add its link and perhaps alter its name if we need to for @@ -70,6 +71,7 @@ sub index : Path : Args(0) { $c->stash->{message} = _("There was a problem showing the All Reports page. Please try again later.") . ' ' . sprintf(_('The error was: %s'), $@); $c->stash->{template} = 'errors/generic.html'; + return; } # Down here so that error pages aren't cached. @@ -126,7 +128,7 @@ sub ward : Path : Args(2) { # List of wards unless ($c->stash->{ward}) { - my $children = mySociety::MaPit::call('area/children', $c->stash->{council}->{id}, + my $children = mySociety::MaPit::call('area/children', [ $c->stash->{council}->{id} ], type => $mySociety::VotingArea::council_child_types, ); foreach (values %$children) { diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 5e8c9cb53..4ff0b922b 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -641,8 +641,8 @@ The MaPit types this site handles =cut -sub area_types { return qw(DIS LBO MTD UTA CTY COI); } -sub area_min_generation { 10 } +sub area_types { qw(ZZZ) } +sub area_min_generation { '' } =head2 contact_name, contact_email diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index d32e876bb..d838ec84b 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -1,6 +1,9 @@ package FixMyStreet::Cobrand::FixMyStreet; use base 'FixMyStreet::Cobrand::Default'; +sub area_types { return qw(DIS LBO MTD UTA CTY COI); } +sub area_min_generation { 10 } + # FixMyStreet should return all cobrands sub restriction { return {}; diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 6d324c68a..82cf3f343 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -7,6 +7,9 @@ use warnings; use Carp; use URI::Escape; +sub area_types { return qw(DIS LBO MTD UTA CTY COI); } +sub area_min_generation { 10 } + sub is_council { 1; } diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index dc42c1aba..2a49cc2f8 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -211,26 +211,6 @@ sub get_email { return $emails[0]; } -=head2 form_errors - - my $arrayref = $mech->form_errors; - -Find all the form errors on the current page and return them in page order as an -arrayref of TEXTs. If none found return empty arrayref. - -=cut - -sub form_errors { - my $mech = shift; - my $result = scraper { - process 'div.form-error', 'errors[]', 'TEXT'; - process 'p.form-error', 'errors[]', 'TEXT'; - process 'p.error', 'errors[]', 'TEXT'; - } - ->scrape( $mech->response ); - return $result->{errors} || []; -} - =head2 page_errors my $arrayref = $mech->page_errors; @@ -243,8 +223,7 @@ arrayref of TEXTs. If none found return empty arrayref. sub page_errors { my $mech = shift; my $result = scraper { - process 'p.error', 'errors[]', 'TEXT'; - process 'ul.error li', 'errors[]', 'TEXT'; + process 'div.form-error, p.form-error, p.error, ul.error li', 'errors[]', 'TEXT'; } ->scrape( $mech->response ); return $result->{errors} || []; @@ -327,6 +306,7 @@ sub extract_problem_meta { my $result = scraper { process 'div#side p em', 'meta', 'TEXT'; + process '.problem-header p em', 'meta', 'TEXT'; } ->scrape( $mech->response ); @@ -348,6 +328,7 @@ sub extract_problem_title { my $result = scraper { process 'div#side h1', 'title', 'TEXT'; + process '.problem-header h1', 'title', 'TEXT'; } ->scrape( $mech->response ); @@ -388,6 +369,7 @@ sub extract_update_metas { my $result = scraper { process 'div#updates div.problem-update p em', 'meta[]', 'TEXT'; + process '.update-text .meta-2', 'meta[]', 'TEXT'; } ->scrape( $mech->response ); diff --git a/t/app/controller/around.t b/t/app/controller/around.t index ca1694b49..db03e00f4 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -72,7 +72,7 @@ foreach my $test ( $mech->get_ok('/'); $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "good location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; is_deeply $mech->extract_location, $test, "got expected location for pc '$test->{pc}'"; }; diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index efc5e60e6..5c6a4ef09 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -33,7 +33,7 @@ for my $test ( my ( $email, $error_message ) = @$test; pass "--- testing bad email '$email' gives error '$error_message'"; $mech->get_ok('/auth'); - is_deeply $mech->form_errors, [], 'no errors initially'; + is_deeply $mech->page_errors, [], 'no errors initially'; $mech->submit_form_ok( { form_name => 'general_auth', @@ -43,7 +43,7 @@ for my $test ( "try to create an account with email '$email'" ); is $mech->uri->path, '/auth', "still on auth page"; - is_deeply $mech->form_errors, [ $error_message ], 'no errors initially'; + is_deeply $mech->page_errors, [ $error_message ], 'no errors initially'; } # create a new account diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 970241d12..11e0d30cf 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -131,8 +131,7 @@ for my $test ( message => '', }, page_errors => - [ 'There were problems with your report. Please see below.', ], - field_errors => [ + [ 'There were problems with your report. Please see below.', 'Please enter your name', 'Please enter your email', 'Please enter a subject', @@ -147,8 +146,7 @@ for my $test ( message => '', }, page_errors => - [ 'There were problems with your report. Please see below.', ], - field_errors => [ + [ 'There were problems with your report. Please see below.', 'Please enter your name', 'Please enter a valid email address', 'Please enter a subject', @@ -162,9 +160,10 @@ for my $test ( subject => '', message => '', }, - page_errors => - [ 'There were problems with your report. Please see below.', ], - field_errors => [ 'Please enter a subject', 'Please write a message', ] + page_errors => [ + 'There were problems with your report. Please see below.', + 'Please enter a subject', 'Please write a message', + ] }, { fields => { @@ -173,9 +172,10 @@ for my $test ( subject => 'A subject', message => '', }, - page_errors => - [ 'There were problems with your report. Please see below.', ], - field_errors => [ 'Please write a message', ] + page_errors => [ + 'There were problems with your report. Please see below.', + 'Please write a message', + ] }, { fields => { @@ -184,9 +184,11 @@ for my $test ( subject => ' ', message => '', }, - page_errors => - [ 'There were problems with your report. Please see below.', ], - field_errors => [ 'Please enter a subject', 'Please write a message', ] + page_errors => [ + 'There were problems with your report. Please see below.', + 'Please enter a subject', + 'Please write a message', + ] }, { fields => { @@ -195,9 +197,10 @@ for my $test ( subject => 'A subject', message => ' ', }, - page_errors => - [ 'There were problems with your report. Please see below.', ], - field_errors => [ 'Please write a message', ] + page_errors => [ + 'There were problems with your report. Please see below.', + 'Please write a message', + ] }, { url => '/contact?id=' . $problem_main->id, @@ -209,7 +212,6 @@ for my $test ( id => 'invalid', }, page_errors => [ 'Illegal ID' ], - field_errors => [] }, ) { @@ -217,7 +219,6 @@ for my $test ( $mech->get_ok( $test->{url} ? $test->{url} : '/contact' ); $mech->submit_form_ok( { with_fields => $test->{fields} } ); is_deeply $mech->page_errors, $test->{page_errors}, 'page errors'; - is_deeply $mech->form_errors, $test->{field_errors}, 'field_errors'; # we santise this when we submit so need to remove it delete $test->{fields}->{id} diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 548580fe1..6c2733e36 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -209,7 +209,7 @@ for my $test ( ), state => 'confirmed', banner_id => 'unknown', - banner_text => 'This problem is old and of unknown status.', + banner_text => 'unknown', fixed => 0 }, { @@ -224,7 +224,7 @@ for my $test ( ), state => 'fixed', banner_id => 'fixed', - banner_text => 'This problem has been fixed.', + banner_text => 'fixed', fixed => 1 }, { @@ -232,7 +232,7 @@ for my $test ( date => DateTime->now, state => 'fixed', banner_id => 'fixed', - banner_text => 'This problem has been fixed.', + banner_text => 'fixed', fixed => 1 }, { @@ -240,7 +240,7 @@ for my $test ( date => DateTime->now, state => 'fixed - user', banner_id => 'fixed', - banner_text => 'This problem has been fixed.', + banner_text => 'fixed', fixed => 1 }, { @@ -248,7 +248,7 @@ for my $test ( date => DateTime->now, state => 'fixed - council', banner_id => 'fixed', - banner_text => 'This problem has been fixed.', + banner_text => 'fixed', fixed => 1 }, { @@ -256,7 +256,7 @@ for my $test ( date => DateTime->now, state => 'closed', banner_id => 'closed', - banner_text => 'This problem has been closed.', + banner_text => 'closed', fixed => 0 }, { @@ -264,7 +264,7 @@ for my $test ( date => DateTime->now, state => 'investigating', banner_id => 'progress', - banner_text => 'This problem is in progress.', + banner_text => 'progress', fixed => 0 }, { @@ -272,7 +272,7 @@ for my $test ( date => DateTime->now, state => 'planned', banner_id => 'progress', - banner_text => 'This problem is in progress.', + banner_text => 'progress', fixed => 0 }, { @@ -280,7 +280,7 @@ for my $test ( date => DateTime->now, state => 'in progress', banner_id => 'progress', - banner_text => 'This problem is in progress.', + banner_text => 'progress', fixed => 0 }, ) { @@ -299,7 +299,11 @@ for my $test ( } is $banner->{id}, $test->{banner_id}, 'banner id'; - is $banner->{text}, $test->{banner_text}, 'banner text'; + if ($test->{banner_text}) { + ok $banner->{text} =~ /$test->{banner_text}/i, 'banner text'; + } else { + is $banner->{text}, $test->{banner_text}, 'banner text'; + } my $update_form = $mech->form_name( 'updateForm' ); if ( $test->{fixed} ) { diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 2875af537..909588766 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -374,7 +374,7 @@ foreach my $test ( # submit initial pc form $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; # click through to the report page $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, @@ -385,7 +385,7 @@ foreach my $test ( "submit form" ); # check that we got the errors expected - is_deeply $mech->form_errors, $test->{errors}, "check errors"; + is_deeply $mech->page_errors, $test->{errors}, "check errors"; # check that fields have changed as expected my $new_values = { @@ -466,7 +466,7 @@ foreach my $test ( ); # check that we got the errors expected - is_deeply $mech->form_errors, [], "check there were no errors"; + is_deeply $mech->page_errors, [], "check there were no errors"; # check that the user has been created/ not changed my $user = @@ -576,7 +576,7 @@ subtest "test password errors for a user who is signing in as they report" => su ); # check that we got the errors expected - is_deeply $mech->form_errors, [ + is_deeply $mech->page_errors, [ "There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the \x{2018}sign in by email\x{2019} section of the form.", ], "check there were errors"; }; @@ -623,7 +623,7 @@ subtest "test report creation for a user who is signing in as they report" => su ); # check that we got the errors expected - is_deeply $mech->form_errors, [ + is_deeply $mech->page_errors, [ 'You have successfully signed in; please check and confirm your details are accurate:', ], "check there were errors"; @@ -801,7 +801,7 @@ subtest "check that a lat/lon off coast leads to /around" => sub { is $mech->uri->path, '/around', "redirected to '/around'"; is_deeply # - $mech->form_errors, + $mech->page_errors, [ 'That spot does not appear to be covered by a council. If you have' . ' tried to report an issue past the shoreline, for example, please' . ' specify the closest point on land.' ], # diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index dc3583e6b..863571ad0 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -113,10 +113,10 @@ foreach my $test ( # submit initial pc form $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; # click through to the report page - $mech->follow_link_ok( { text => 'skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # submit the main form @@ -124,7 +124,7 @@ foreach my $test ( "submit form" ); # check that we got the errors expected - is_deeply $mech->form_errors, $test->{errors}, "check errors"; + is_deeply $mech->page_errors, $test->{errors}, "check errors"; # check that fields have changed as expected my $new_values = { @@ -136,7 +136,7 @@ foreach my $test ( if ( $test->{fields}->{category} eq 'Street lighting' ) { my $result = scraper { - process 'div#category_meta div select#form_type option', 'option[]' => '@value'; + process 'select#form_type option', 'option[]' => '@value'; } ->scrape( $mech->response ); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 0337a881b..cf6af16cb 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -271,7 +271,7 @@ for my $test ( $mech->submit_form_ok( { with_fields => $test->{fields} }, 'submit update' ); - is_deeply $mech->form_errors, $test->{field_errors}, 'field errors'; + is_deeply $mech->page_errors, $test->{field_errors}, 'field errors'; my $values = { %{ $test->{fields} }, @@ -640,7 +640,7 @@ for my $test ( 'submit update' ); - is_deeply $mech->form_errors, $test->{field_errors}, 'check there were errors'; + is_deeply $mech->page_errors, $test->{field_errors}, 'check there were errors'; SKIP: { skip( "Incorrect password", 5 ) unless $test->{form_values}{password_sign_in} eq $pw; diff --git a/templates/web/fixmystreet/index.html b/templates/web/fixmystreet/index.html index 476c426b0..b7b2cbe77 100644 --- a/templates/web/fixmystreet/index.html +++ b/templates/web/fixmystreet/index.html @@ -45,6 +45,10 @@ Modernizr.load({ [% INCLUDE 'header.html', title = '', bodyclass = 'frontpage fullwidthpage' %] +[% IF error %] + <p class="form-error">[% error %]</p> +[% END %] + [% IF c.cobrand.moniker == 'bromley' %] <p>This is primarily for reporting physical problems that can be fixed like graffiti, cleansing issues or road defects. To report other |