aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-13 17:52:15 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-13 17:52:15 +0100
commit8dae03ed508f07265727005bbce9570e51c6c33c (patch)
tree317f3abe8c092af4d8f44b4b7da0696f92cbf8db
parentb683026c94f15f6f4b5214820b1446a8ef684658 (diff)
display correct error messages and test for bad problem ids
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm5
-rw-r--r--perllib/FixMyStreet/TestMech.pm1
-rw-r--r--t/app/controller/contact.t46
-rw-r--r--templates/web/default/contact/index.html6
4 files changed, 48 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index 030f69cc2..bb3581144 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -114,6 +114,7 @@ sub determine_contact_type : Private {
elsif ($problem) {
$c->stash->{problem} = $problem;
}
+ $c->stash->{id} = $id;
}
return 1;
@@ -145,6 +146,10 @@ sub validate : Private {
or $c->req->param('update_id')
&& $c->req->param('update_id') !~ /^[1-9]\d*$/;
+ unshift @errors,
+ _('There were problems with your report. Please see below.')
+ if scalar keys %field_errors;
+
if ( @errors or scalar keys %field_errors ) {
$c->stash->{errors} = \@errors;
$c->stash->{field_errors} = \%field_errors;
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index ee59bded6..160b3955a 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -219,6 +219,7 @@ sub page_errors {
my $mech = shift;
my $result = scraper {
process 'p.error', 'errors[]', 'TEXT';
+ process 'ul.error', 'errors[]', 'TEXT';
}
->scrape( $mech->response );
return $result->{errors} || [];
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index c4bf83613..860ada4ce 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -77,7 +77,9 @@ for my $test (
subject => '',
message => '',
},
- errors => [
+ page_errors =>
+ [ 'There were problems with your report. Please see below.', ],
+ field_errors => [
'Please give your name',
'Please give your email',
'Please give a subject',
@@ -91,7 +93,9 @@ for my $test (
subject => '',
message => '',
},
- errors => [
+ page_errors =>
+ [ 'There were problems with your report. Please see below.', ],
+ field_errors => [
'Please give your name',
'Please give a valid email address',
'Please give a subject',
@@ -105,7 +109,9 @@ for my $test (
subject => '',
message => '',
},
- errors => [ 'Please give a subject', 'Please write a message', ]
+ page_errors =>
+ [ 'There were problems with your report. Please see below.', ],
+ field_errors => [ 'Please give a subject', 'Please write a message', ]
},
{
fields => {
@@ -114,7 +120,9 @@ for my $test (
subject => 'A subject',
message => '',
},
- errors => [ 'Please write a message', ]
+ page_errors =>
+ [ 'There were problems with your report. Please see below.', ],
+ field_errors => [ 'Please write a message', ]
},
{
fields => {
@@ -123,7 +131,9 @@ for my $test (
subject => ' ',
message => '',
},
- errors => [ 'Please give a subject', 'Please write a message', ]
+ page_errors =>
+ [ 'There were problems with your report. Please see below.', ],
+ field_errors => [ 'Please give a subject', 'Please write a message', ]
},
{
fields => {
@@ -132,15 +142,33 @@ for my $test (
subject => 'A subject',
message => ' ',
},
- errors => [ 'Please write a message', ]
+ page_errors =>
+ [ 'There were problems with your report. Please see below.', ],
+ field_errors => [ 'Please write a message', ]
+ },
+ {
+ url => '/contact?id=1',
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ id => 'invalid',
+ },
+ page_errors => [ 'Illegal ID' ],
+ field_errors => []
},
-
)
{
subtest 'check submit page error handling' => sub {
- $mech->get_ok('/contact');
+ $mech->get_ok( $test->{url} ? $test->{url} : '/contact' );
$mech->submit_form_ok( { with_fields => $test->{fields} } );
- is_deeply $mech->form_errors, $test->{errors};
+ is_deeply $mech->page_errors, $test->{page_errors};
+ is_deeply $mech->form_errors, $test->{field_errors};
+
+ # we santise this when we submit so need to remove it
+ delete $test->{fields}->{id}
+ if $test->{fields}->{id} and $test->{fields}->{id} eq 'invalid';
is_deeply $mech->visible_form_values, $test->{fields};
};
}
diff --git a/templates/web/default/contact/index.html b/templates/web/default/contact/index.html
index 0937e73cf..e76724d1b 100644
--- a/templates/web/default/contact/index.html
+++ b/templates/web/default/contact/index.html
@@ -32,7 +32,8 @@
</blockquote>
[% END %]
- <input type="hidden" name="id" value="[% update.id %]">
+ <input type="hidden" name="update_id" value="[% update.id %]">
+ <input type="hidden" name="id" value="[% problem.id %]">
[% ELSIF problem %]
<p>
[% loc('You are reporting the following problem report for being abusive, containing personal information, or similar:') %]
@@ -58,6 +59,9 @@
<input type="hidden" name="id" value="[% problem.id %]">
[% END %]
[% ELSE %]
+[% IF id %]
+<input type="hidden" name="id" value="[% id %]">
+[% END %]
<p>
[% loc('Please do <strong>not</strong> report problems through this form; messages go to
the team behind FixMyStreet, not a council. To report a problem,