aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-04-22 15:39:53 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-04-24 14:51:48 +0100
commitf70ef9f6a612d3387db24519e163e6b326a9fb64 (patch)
treebfc140c28207813b3b7f14c7c43cd6919e82c93c /t
parentdf80428e2f51f85436988958d0371e67b528ea88 (diff)
Factor out some new report tests into own files.
Diffstat (limited to 't')
-rw-r--r--t/app/controller/report_new.t888
-rw-r--r--t/app/controller/report_new_errors.t745
-rw-r--r--t/app/controller/report_new_unresponsive.t122
3 files changed, 874 insertions, 881 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 236edda62..d2da75f2c 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -7,62 +7,26 @@ package main;
use Test::MockModule;
use FixMyStreet::TestMech;
-use Web::Scraper;
-use Path::Class;
# disable info logs for this test run
FixMyStreet::App->log->disable('info');
END { FixMyStreet::App->log->enable('info'); }
my $mech = FixMyStreet::TestMech->new;
-$mech->get_ok('/report/new');
-
-my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify;
-ok -e $sample_file, "sample file $sample_file exists";
-
-subtest "test that bare requests to /report/new get redirected" => sub {
-
- $mech->get_ok('/report/new');
- is $mech->uri->path, '/', "went to /";
- is_deeply { $mech->uri->query_form }, {}, "query empty";
-
- FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->get_ok('/report/new?pc=SW1A%201AA');
- is $mech->uri->path, '/around', "went to /around";
- is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' },
- "pc correctly transferred";
-
- $mech->get_ok('/report/new?pc_override=SW1A%201AA&latitude=51&longitude=-2');
- is $mech->uri->path, '/around', "went to /around";
- is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' },
- "pc correctly transferred, lat/lon gone";
- };
-};
my %body_ids;
-my @bodies;
for my $body (
{ area_id => 2651, name => 'City of Edinburgh Council' },
{ area_id => 2226, name => 'Gloucestershire County Council' },
{ area_id => 2326, name => 'Cheltenham Borough Council' },
- { area_id => 2504, name => 'Westminster City Council' },
{ area_id => 2482, name => 'Bromley Council' },
{ area_id => 2227, name => 'Hampshire County Council' },
{ area_id => 2333, name => 'Hart Council' },
{ area_id => 2535, name => 'Sandwell Borough Council' },
{ area_id => 1000, name => 'Highways England' },
- { area_id => 2217, name => 'Buckinghamshire Council' },
- { area_id => 2232, name => 'Lincolnshire County Council' },
- { area_id => 2237, name => 'Oxfordshire County Council' },
- { area_id => 2600, name => 'Rutland County Council' },
- { area_id => 2234, name => 'Northamptonshire County Council' },
{ area_id => 2483, name => 'Hounslow Borough Council' },
- { area_id => 2566, name => 'Peterborough City Council' },
) {
my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name});
- push @bodies, $body_obj;
$body_ids{$body->{area_id}} = $body_obj->id;
}
@@ -82,31 +46,26 @@ my $contact3 = $mech->create_contact_ok(
category => 'Trees',
email => 'trees@example.com',
);
-my $contact4 = $mech->create_contact_ok(
+$mech->create_contact_ok(
body_id => $body_ids{2482}, # Bromley
category => 'Trees',
email => 'trees@example.com',
);
-my $contact5 = $mech->create_contact_ok(
+$mech->create_contact_ok(
body_id => $body_ids{2651}, # Edinburgh
category => 'Trees',
email => 'trees@example.com',
);
-my $contact6 = $mech->create_contact_ok(
+$mech->create_contact_ok(
body_id => $body_ids{2333}, # Hart
category => 'Trees',
email => 'trees@example.com',
);
-my $contact7 = $mech->create_contact_ok(
+$mech->create_contact_ok(
body_id => $body_ids{2227}, # Hampshire
category => 'Street lighting',
email => 'highways@example.com',
);
-my $contact8 = $mech->create_contact_ok(
- body_id => $body_ids{2504},
- category => 'Street lighting',
- email => 'highways@example.com'
-);
my $contact9 = $mech->create_contact_ok(
body_id => $body_ids{2226}, # Gloucestershire
category => 'Street lighting',
@@ -117,631 +76,22 @@ my $contact10 = $mech->create_contact_ok(
category => 'Street lighting',
email => 'streetlights-2326@example.com',
);
-my $contact11 = $mech->create_contact_ok(
+$mech->create_contact_ok(
body_id => $body_ids{1000}, # Highways
category => 'Pothole',
email => 'pothole-1000@example.com',
);
-my $contact12 = $mech->create_contact_ok(
- body_id => $body_ids{2217}, # Buckinghamshire
- category => 'Street lighting',
- email => 'streetlights-2217@example.com',
-);
-my $contact13 = $mech->create_contact_ok(
- body_id => $body_ids{2232}, # Lincolnshire
- category => 'Trees',
- email => 'trees-2232@example.com',
-);
-my $contact14 = $mech->create_contact_ok(
- body_id => $body_ids{2237}, # Oxfordshire
- category => 'Trees',
- email => 'trees-2247@example.com',
-);
-my $contact15 = $mech->create_contact_ok(
- body_id => $body_ids{2600}, # Rutland
- category => 'Trees',
- email => 'trees-2600@example.com',
-);
-my $contact16 = $mech->create_contact_ok(
- body_id => $body_ids{2234}, # Northamptonshire
- category => 'Trees',
- email => 'trees-2234@example.com',
-);
-my $contact17 = $mech->create_contact_ok(
+$mech->create_contact_ok(
body_id => $body_ids{2483}, # Hounslow
category => 'Trees',
email => 'trees-2483@example.com',
);
-my $contact18 = $mech->create_contact_ok(
+$mech->create_contact_ok(
body_id => $body_ids{2483}, # Hounslow
category => 'General Enquiry',
email => 'general-enquiry-2483@example.com',
non_public => 1,
);
-my $contact19 = $mech->create_contact_ok(
- body_id => $body_ids{2566}, # Peterborough
- category => 'Trees',
- email => 'trees-2566@example.com',
-);
-
-# test that the various bit of form get filled in and errors correctly
-# generated.
-foreach my $test (
- {
- msg => 'all fields empty',
- pc => 'OX1 3DH',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => '',
- may_show_name => '1',
- username => '',
- phone => '',
- password_sign_in => '',
- password_register => '',
- },
- changes => {},
- errors => [
- 'Please enter a subject',
- 'Please enter some details',
- # No category error, as no categories for Oxon at all, so is skipped
- 'Please enter your email',
- 'Please enter your name',
- ],
- },
- {
- msg => 'all fields empty, bad category',
- pc => 'GL50 2PR',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => '',
- may_show_name => '1',
- username => '',
- phone => '',
- category => 'Something bad',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- category => '-- Pick a category --',
- },
- errors => [
- 'Please enter a subject',
- 'Please enter some details',
- 'Please choose a category',
- 'Please enter your email',
- 'Please enter your name',
- ],
- },
- {
- msg => 'all fields empty except category',
- pc => 'SW1A 1AA',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => '',
- may_show_name => '1',
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {},
- errors => [
- 'Please enter a subject',
- 'Please enter some details',
- 'Please enter your email',
- 'Please enter your name',
- ],
- },
- {
- msg => 'may_show_name is remembered',
- pc => 'SW1A 1AA',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => '',
- may_show_name => undef,
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {},
- errors => [
- 'Please enter a subject',
- 'Please enter some details',
- 'Please enter your email',
- 'Please enter your name',
- ],
- },
- {
- msg => 'may_show_name unchanged if name is present (stays false)',
- pc => 'SW1A 1AA',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Bob Jones',
- may_show_name => undef,
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {},
- errors => [
- 'Please enter a subject',
- 'Please enter some details',
- 'Please enter your email',
- ],
- },
- {
- msg => 'may_show_name unchanged if name is present (stays true)',
- pc => 'SW1A 1AA',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Bob Jones',
- may_show_name => '1',
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {},
- errors => [
- 'Please enter a subject',
- 'Please enter some details',
- 'Please enter your email',
- ],
- },
- {
- msg => 'title and details tidied up',
- pc => 'SW1A 1AA',
- fields => {
- title => "DOG SHIT\r\nON WALLS",
- detail => "on this portakabin -\r\n\r\nmore of a portaloo HEH!!",
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Bob Jones',
- may_show_name => '1',
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- title => 'Dog poo on walls',
- detail =>
- "On this [portable cabin] -\n\nMore of a [portable loo] HEH!!",
- },
- errors => [ 'Please enter your email', ],
- },
- {
- msg => 'name too short',
- pc => 'SW1A 1AA',
- fields => {
- title => 'Test title',
- detail => 'Test detail',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'DUDE',
- may_show_name => '1',
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {},
- errors => [
- 'Please enter your email',
-'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
- ],
- },
- {
- msg => 'name is anonymous',
- pc => 'SW1A 1AA',
- fields => {
- title => 'Test title',
- detail => 'Test detail',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'anonymous',
- may_show_name => '1',
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {},
- errors => [
- 'Please enter your email',
-'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
- ],
- },
- {
- msg => 'email invalid',
- pc => 'SW1A 1AA',
- fields => {
- title => 'Test title',
- detail => 'Test detail',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Joe Smith',
- may_show_name => '1',
- username => 'not an email',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => { username => 'notanemail' },
- errors => [ 'Please enter a valid email', ],
- },
- {
- msg => 'cleanup title and detail',
- pc => 'SW1A 1AA',
- fields => {
- title => " Test title ",
- detail => " first line \n\n second\nline\n\n ",
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => '',
- may_show_name => '1',
- username => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- title => 'Test title',
- detail => "First line\n\nSecond line",
- },
- errors => [
- 'Please enter your email',
- 'Please enter your name',
- ],
- },
- {
- msg => 'clean up name and email',
- pc => 'SW1A 1AA',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => ' Bob Jones ',
- may_show_name => '1',
- username => ' BOB @ExAmplE.COM ',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- name => 'Bob Jones',
- username => 'bob@example.com',
- },
- errors => [ 'Please enter a subject', 'Please enter some details', ],
- },
- {
- msg => 'non-photo upload gives error',
- pc => 'SW1A 1AA',
- fields => {
- title => 'Title',
- detail => 'Detail',
- photo1 => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ],
- photo2 => '',
- photo3 => '',
- name => 'Bob Jones',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- photo1 => '',
- },
- errors => [ "Please upload an image only" ],
- },
- {
- msg => 'bad photo upload gives error',
- pc => 'SW1A 1AA',
- fields => {
- title => 'Title',
- detail => 'Detail',
- photo1 => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ],
- photo2 => '',
- photo3 => '',
- name => 'Bob Jones',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- photo1 => '',
- },
- errors => [ "That image doesn't appear to have uploaded correctly (Please upload an image only ), please try again." ],
- },
- {
- msg => 'photo with octet-stream gets through okay',
- pc => 'SW1A 1AA',
- fields => {
- title => '',
- detail => 'Detail',
- photo1 => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ],
- photo2 => '',
- photo3 => '',
- name => 'Bob Jones',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- photo1 => '',
- },
- errors => [ "Please enter a subject" ],
- },
- {
- msg => 'email in title',
- pc => 'SW1A 1AA',
- fields => {
- title => 'user@example.com',
- detail => 'Test detail',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Joe Smith',
- may_show_name => '1',
- username => 'user@example.com',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => {
- username => 'user@example.com',
- title => 'User@example.com'
- },
- errors => [ 'Please make sure you are not including an email address', ],
- },
- {
- msg => 'Bromley long detail',
- pc => 'BR1 3UH',
- fields => {
- fms_extra_title => 'MR',
- title => '',
- detail => 'X' . 'x' x 1751,
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Bob Example',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '',
- category => 'Trees',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Please enter a subject', 'Reports are limited to 1750 characters in length. Please shorten your report' ],
- },
- {
- msg => 'Oxfordshire long detail',
- pc => 'OX20 1SZ',
- fields => {
- title => '',
- detail => 'X' . 'x' x 1701,
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Bob Example',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '',
- category => 'Trees',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Please enter a subject', 'Reports are limited to 1700 characters in length. Please shorten your report' ],
- },
- {
- msg => 'Lincolnshire long phone',
- pc => 'PE9 2GX',
- fields => {
- title => '',
- detail => 'Detail',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'Bob Example',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '123456789 12345678910',
- category => 'Trees',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Please enter a subject', 'Phone numbers are limited to 20 characters in length.' ],
- },
- {
- msg => 'Buckinghamshire long name',
- pc => 'RG9 6TL',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'This is a very long name that should fail validation',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Please enter a subject', 'Please enter some details', 'Names are limited to 50 characters in length.' ],
- },
- {
- msg => 'Rutland long name',
- pc => 'LE15 0GJ',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'This is a very long name that should fail validation',
- may_show_name => '1',
- username => 'bob@example.com',
- phone => '',
- category => 'Trees',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Please enter a subject', 'Please enter some details', 'Names are limited to 40 characters in length.' ],
- },
- {
- msg => 'Oxfordshire validation',
- pc => 'OX20 1SZ',
- fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'This is a really extraordinarily long name that definitely should fail validation',
- may_show_name => '1',
- username => 'bob.has.a.very.long.email@thisisalonghostname.example.com',
- phone => '01234 5678910 09876 54321 ext 203',
- category => 'Trees',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Please enter a subject', 'Please enter some details', 'Emails are limited to 50 characters in length.', 'Phone numbers are limited to 20 characters in length.', 'Names are limited to 50 characters in length.'],
- },
- {
- msg => 'Northamptonshire validation',
- pc => 'NN1 1NS',
- fields => {
- title => 'This is a very long title that should fail the validation as it is really much too long to pass the validation of 120 characters',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'A User',
- may_show_name => '1',
- username => 'user@example.org',
- phone => '',
- category => 'Trees',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Summaries are limited to 120 characters in length. Please shorten your summary', 'Please enter some details'],
- },
- {
- msg => 'Peterborough validation',
- pc => 'PE1 1HF',
- fields => {
- title => 'This is a very long title that should fail the validation',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => 'A User',
- may_show_name => '1',
- username => 'user@example.org',
- phone => '',
- category => 'Trees',
- password_sign_in => '',
- password_register => '',
- },
- changes => { },
- errors => [ 'Summaries are limited to 50 characters in length. Please shorten your summary', 'Please enter some details'],
- },
- )
-{
- subtest "check form errors where $test->{msg}" => sub {
- $mech->get_ok('/around');
-
- # submit initial pc form
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { fixmystreet => '.' }, 'bromley', 'oxfordshire', 'rutland', 'lincolnshire', 'buckinghamshire', 'northamptonshire', 'peterborough' ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
- "submit location" );
- 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, },
- "follow 'skip this step' link" );
-
- # submit the main form
- $mech->submit_form_ok( { with_fields => $test->{fields} },
- "submit form" );
- };
-
- # check that we got the errors expected
- is_deeply [ sort @{$mech->page_errors} ], [ sort @{$test->{errors}} ], "check errors";
-
- # check that fields have changed as expected
- my $new_values = {
- %{ $test->{fields} }, # values added to form
- %{ $test->{changes} }, # changes we expect
- };
- is_deeply $mech->visible_form_values, $new_values,
- "values correctly changed";
- };
-}
my $first_user;
foreach my $test (
@@ -882,62 +232,6 @@ foreach my $test (
};
}
-# this test to make sure that we don't see spurious error messages about
-# the name being blank when there is a sign in error
-subtest "test password errors for a user who is signing in as they report" => sub {
- $mech->log_out_ok;
- $mech->clear_emails_ok;
-
- # check that the user does not exist
- my $test_email = 'test-2@example.com';
-
- my $user = $mech->create_user_ok($test_email);
-
- # setup the user.
- ok $user->update( {
- name => 'Joe Bloggs',
- phone => '01234 567 890',
- password => 'secret2',
- phone_verified => 1,
- } ), "set user details";
-
- # submit initial pc form
- $mech->get_ok('/around');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
- "submit location" );
-
- # click through to the report page
- $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
- "follow 'skip this step' link" );
-
- $mech->submit_form_ok(
- {
- button => 'submit_sign_in',
- with_fields => {
- title => 'Test Report',
- detail => 'Test report details.',
- photo1 => '',
- username => 'test-2@example.com',
- password_sign_in => 'secret1',
- category => 'Street lighting',
- }
- },
- "submit with wrong password"
- );
- };
-
- # check that we got the errors expected
- is_deeply $mech->page_errors, [
- "There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the \x{2018}No\x{2019} section of the form.",
- ], "check there were errors";
-
- $mech->content_lacks('1234 567', 'phone number not shown');
-};
-
foreach my $test (
{ two_factor => '', desc => '', },
{ two_factor => 'yes', desc => ' with two-factor', },
@@ -1506,29 +800,6 @@ subtest "check map click ajax response" => sub {
# create report by clicking on map with javascript off
# create report with images off
-subtest "check that a lat/lon off coast leads to /around" => sub {
- my $off_coast_latitude = 50.78301;
- my $off_coast_longitude = -0.646929;
-
- FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->get_ok( #
- "/report/new"
- . "?latitude=$off_coast_latitude"
- . "&longitude=$off_coast_longitude"
- );
- };
-
- is $mech->uri->path, '/around', "redirected to '/around'";
-
- is_deeply #
- $mech->page_errors,
- [ 'That location does not appear to be covered by a council; perhaps it is offshore or outside the country. Please try again.' ],
- "Found location error";
-
-};
-
subtest "check we load a partial report correctly" => sub {
my $user = FixMyStreet::DB->resultset('User')->find_or_create(
{
@@ -1930,151 +1201,6 @@ 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.uk/',
- }, sub {
- # Test body-level send method
- my $old_send = $contact1->body->send_method;
- $contact1->body->update( { send_method => 'Refused' } );
- my $body_id = $contact1->body->id;
- my $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=55.952055&longitude=-3.189579');
- like $extra_details->{top_message}, qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id};
- is_deeply $extra_details->{unresponsive}, { $body_id => 1 }, "unresponsive json set";
- $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Street%20lighting&latitude=55.952055&longitude=-3.189579');
- is_deeply $extra_details->{unresponsive}, { $body_id => 1 }, "unresponsive json set";
-
- my $test_email = 'test-2@example.com';
- $mech->log_out_ok;
- $mech->get_ok('/around');
- $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
- $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
- $mech->submit_form_ok(
- {
- with_fields => {
- title => "Test Report at café",
- detail => 'Test report details.',
- photo1 => '',
- name => 'Joe Bloggs',
- username => $test_email,
- may_show_name => '1',
- phone => '07903 123 456',
- category => 'Trees',
- }
- },
- "submit good details"
- );
-
- my $user = FixMyStreet::DB->resultset('User')->find( { email => $test_email } );
- ok $user, "test user does exist";
-
- my $report = $user->problems->first;
- ok $report, "Found the report";
- is $report->bodies_str, undef, "Report not going anywhere";
-
- like $mech->get_text_body_from_email, qr/despite not being sent/i, "correct email sent";
-
- $user->problems->delete;
- $mech->clear_emails_ok;
-
- # Make sure the same behaviour occurs for reports from the mobile app
- $mech->log_out_ok;
- $mech->post_ok( '/report/new/mobile', {
- title => "Test Report at café",
- detail => 'Test report details.',
- photo1 => '',
- name => 'Joe Bloggs',
- email => $test_email,
- may_show_name => '1',
- phone => '07903 123 456',
- category => 'Trees',
- service => 'iOS',
- lat => 55.952055,
- lon => -3.189579,
- pc => '',
- used_map => '1',
- submit_register => '1',
- password_register => '',
- });
- my $res = $mech->response;
- ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json';
-
- $user = FixMyStreet::DB->resultset('User')->find( { email => $test_email } );
- ok $user, "test user does exist";
-
- $report = $user->problems->first;
- ok $report, "Found the report";
- is $report->bodies_str, undef, "Report not going anywhere";
-
- like $mech->get_text_body_from_email, qr/despite not being sent/i, "correct email sent";
-
- $user->problems->delete;
- $mech->clear_emails_ok;
-
- $contact1->body->update( { send_method => $old_send } );
-
- # And test per-category refusing
- my $old_email = $contact3->email;
- $contact3->update( { email => 'REFUSED' } );
- $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=51.896268&longitude=-2.093063');
- like $extra_details->{by_category}{$contact3->category}{category_extra}, qr/Cheltenham.*Trees.*unresponsive.*category=Trees/s;
- $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063');
- is_deeply $extra_details->{unresponsive}, { $contact3->body->id => 1 }, "unresponsive json set";
-
- $mech->get_ok('/around');
- $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, "submit location" );
- $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
- $mech->submit_form_ok(
- {
- with_fields => {
- title => "Test Report at café",
- detail => 'Test report details.',
- photo1 => '',
- name => 'Joe Bloggs',
- username => $test_email,
- may_show_name => '1',
- phone => '07903 123 456',
- category => 'Trees',
- }
- },
- "submit good details"
- );
-
- $report = $user->problems->first;
- ok $report, "Found the report";
- is $report->bodies_str, undef, "Report not going anywhere";
-
- $contact3->update( { email => $old_email } );
- $mech->delete_user($user);
- };
-};
-
-subtest "unresponsive body page works" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- }, sub {
- my $old_send = $contact1->body->send_method;
- my $body_id = $contact1->body->id;
- my $url = "/unresponsive?body=$body_id";
- is $mech->get($url)->code, 404, "page not found";
- $contact1->body->update( { send_method => 'Refused' } );
- $mech->get_ok($url);
- $mech->content_contains('Edinburgh');
- $contact1->body->update( { send_method => $old_send } );
-
- my $old_email = $contact3->email;
- $body_id = $contact3->body->id;
- $url = "/unresponsive?body=$body_id;category=Trees";
- is $mech->get($url)->code, 404, "page not found";
- $contact3->update( { email => 'REFUSED' } );
- $mech->get_ok($url);
- $mech->content_contains('Cheltenham');
- $mech->content_contains('Trees');
- $contact3->update( { email => $old_email } );
- };
-};
-
subtest "extra google analytics code displayed on logged in problem creation" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
diff --git a/t/app/controller/report_new_errors.t b/t/app/controller/report_new_errors.t
new file mode 100644
index 000000000..f45f13c1e
--- /dev/null
+++ b/t/app/controller/report_new_errors.t
@@ -0,0 +1,745 @@
+use FixMyStreet::TestMech;
+use Path::Tiny;
+
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $sample_file = path(__FILE__)->parent->child("sample.jpg");
+ok -e $sample_file, "sample file $sample_file exists";
+
+subtest "test that bare requests to /report/new get redirected" => sub {
+ $mech->get_ok('/report/new');
+ is $mech->uri->path, '/', "went to /";
+ is_deeply { $mech->uri->query_form }, {}, "query empty";
+
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok('/report/new?pc=SW1A%201AA');
+ is $mech->uri->path, '/around', "went to /around";
+ is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' },
+ "pc correctly transferred";
+
+ $mech->get_ok('/report/new?pc_override=SW1A%201AA&latitude=51&longitude=-2');
+ is $mech->uri->path, '/around', "went to /around";
+ is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' },
+ "pc correctly transferred, lat/lon gone";
+ };
+};
+
+my %body_ids;
+for my $body (
+ { area_id => 2226, name => 'Gloucestershire County Council' },
+ { area_id => 2504, name => 'Westminster City Council' },
+ { area_id => 2482, name => 'Bromley Council' },
+ { area_id => 2217, name => 'Buckinghamshire Council' },
+ { area_id => 2232, name => 'Lincolnshire County Council' },
+ { area_id => 2237, name => 'Oxfordshire County Council' },
+ { area_id => 2600, name => 'Rutland County Council' },
+ { area_id => 2234, name => 'Northamptonshire County Council' },
+ { area_id => 2566, name => 'Peterborough City Council' },
+) {
+ my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name});
+ $body_ids{$body->{area_id}} = $body_obj->id;
+}
+
+# Let's make some contacts to send things to!
+$mech->create_contact_ok(
+ body_id => $body_ids{2226}, # Gloucestershire
+ category => 'Potholes',
+ email => 'potholes@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2482}, # Bromley
+ category => 'Trees',
+ email => 'trees@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2504},
+ category => 'Street lighting',
+ email => 'highways@example.com'
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2226}, # Gloucestershire
+ category => 'Street lighting',
+ email => 'streetlights-2226@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2217}, # Buckinghamshire
+ category => 'Street lighting',
+ email => 'streetlights-2217@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2232}, # Lincolnshire
+ category => 'Trees',
+ email => 'trees-2232@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2237}, # Oxfordshire
+ category => 'Trees',
+ email => 'trees-2247@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2600}, # Rutland
+ category => 'Trees',
+ email => 'trees-2600@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2234}, # Northamptonshire
+ category => 'Trees',
+ email => 'trees-2234@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body_ids{2566}, # Peterborough
+ category => 'Trees',
+ email => 'trees-2566@example.com',
+);
+
+# test that the various bit of form get filled in and errors correctly
+# generated.
+foreach my $test (
+ {
+ msg => 'all fields empty',
+ pc => 'OX1 3DH',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => '',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {},
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ # No category error, as no categories for Oxon at all, so is skipped
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'all fields empty, bad category',
+ pc => 'GL50 2PR',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => '',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ category => 'Something bad',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ category => '-- Pick a category --',
+ },
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please choose a category',
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'all fields empty except category',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => '',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {},
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'may_show_name is remembered',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => '',
+ may_show_name => undef,
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {},
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'may_show_name unchanged if name is present (stays false)',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Jones',
+ may_show_name => undef,
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {},
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please enter your email',
+ ],
+ },
+ {
+ msg => 'may_show_name unchanged if name is present (stays true)',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Jones',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {},
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please enter your email',
+ ],
+ },
+ {
+ msg => 'title and details tidied up',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => "DOG SHIT\r\nON WALLS",
+ detail => "on this portakabin -\r\n\r\nmore of a portaloo HEH!!",
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Jones',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ title => 'Dog poo on walls',
+ detail =>
+ "On this [portable cabin] -\n\nMore of a [portable loo] HEH!!",
+ },
+ errors => [ 'Please enter your email', ],
+ },
+ {
+ msg => 'name too short',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Test title',
+ detail => 'Test detail',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'DUDE',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {},
+ errors => [
+ 'Please enter your email',
+'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
+ ],
+ },
+ {
+ msg => 'name is anonymous',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Test title',
+ detail => 'Test detail',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'anonymous',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {},
+ errors => [
+ 'Please enter your email',
+'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
+ ],
+ },
+ {
+ msg => 'email invalid',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Test title',
+ detail => 'Test detail',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Joe Smith',
+ may_show_name => '1',
+ username => 'not an email',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { username => 'notanemail' },
+ errors => [ 'Please enter a valid email', ],
+ },
+ {
+ msg => 'cleanup title and detail',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => " Test title ",
+ detail => " first line \n\n second\nline\n\n ",
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => '',
+ may_show_name => '1',
+ username => '',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ title => 'Test title',
+ detail => "First line\n\nSecond line",
+ },
+ errors => [
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'clean up name and email',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => ' Bob Jones ',
+ may_show_name => '1',
+ username => ' BOB @ExAmplE.COM ',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ name => 'Bob Jones',
+ username => 'bob@example.com',
+ },
+ errors => [ 'Please enter a subject', 'Please enter some details', ],
+ },
+ {
+ msg => 'non-photo upload gives error',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Title',
+ detail => 'Detail',
+ photo1 => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ],
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Jones',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ photo1 => '',
+ },
+ errors => [ "Please upload an image only" ],
+ },
+ {
+ msg => 'bad photo upload gives error',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Title',
+ detail => 'Detail',
+ photo1 => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ],
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Jones',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ photo1 => '',
+ },
+ errors => [ "That image doesn't appear to have uploaded correctly (Please upload an image only ), please try again." ],
+ },
+ {
+ msg => 'photo with octet-stream gets through okay',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => 'Detail',
+ photo1 => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ],
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Jones',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ photo1 => '',
+ },
+ errors => [ "Please enter a subject" ],
+ },
+ {
+ msg => 'email in title',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'user@example.com',
+ detail => 'Test detail',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Joe Smith',
+ may_show_name => '1',
+ username => 'user@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => {
+ username => 'user@example.com',
+ title => 'User@example.com'
+ },
+ errors => [ 'Please make sure you are not including an email address', ],
+ },
+ {
+ msg => 'Bromley long detail',
+ pc => 'BR1 3UH',
+ fields => {
+ fms_extra_title => 'MR',
+ title => '',
+ detail => 'X' . 'x' x 1751,
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Example',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '',
+ category => 'Trees',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Please enter a subject', 'Reports are limited to 1750 characters in length. Please shorten your report' ],
+ },
+ {
+ msg => 'Oxfordshire long detail',
+ pc => 'OX20 1SZ',
+ fields => {
+ title => '',
+ detail => 'X' . 'x' x 1701,
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Example',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '',
+ category => 'Trees',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Please enter a subject', 'Reports are limited to 1700 characters in length. Please shorten your report' ],
+ },
+ {
+ msg => 'Lincolnshire long phone',
+ pc => 'PE9 2GX',
+ fields => {
+ title => '',
+ detail => 'Detail',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'Bob Example',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '123456789 12345678910',
+ category => 'Trees',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Please enter a subject', 'Phone numbers are limited to 20 characters in length.' ],
+ },
+ {
+ msg => 'Buckinghamshire long name',
+ pc => 'RG9 6TL',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'This is a very long name that should fail validation',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Please enter a subject', 'Please enter some details', 'Names are limited to 50 characters in length.' ],
+ },
+ {
+ msg => 'Rutland long name',
+ pc => 'LE15 0GJ',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'This is a very long name that should fail validation',
+ may_show_name => '1',
+ username => 'bob@example.com',
+ phone => '',
+ category => 'Trees',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Please enter a subject', 'Please enter some details', 'Names are limited to 40 characters in length.' ],
+ },
+ {
+ msg => 'Oxfordshire validation',
+ pc => 'OX20 1SZ',
+ fields => {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'This is a really extraordinarily long name that definitely should fail validation',
+ may_show_name => '1',
+ username => 'bob.has.a.very.long.email@thisisalonghostname.example.com',
+ phone => '01234 5678910 09876 54321 ext 203',
+ category => 'Trees',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Please enter a subject', 'Please enter some details', 'Emails are limited to 50 characters in length.', 'Phone numbers are limited to 20 characters in length.', 'Names are limited to 50 characters in length.'],
+ },
+ {
+ msg => 'Northamptonshire validation',
+ pc => 'NN1 1NS',
+ fields => {
+ title => 'This is a very long title that should fail the validation as it is really much too long to pass the validation of 120 characters',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'A User',
+ may_show_name => '1',
+ username => 'user@example.org',
+ phone => '',
+ category => 'Trees',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Summaries are limited to 120 characters in length. Please shorten your summary', 'Please enter some details'],
+ },
+ {
+ msg => 'Peterborough validation',
+ pc => 'PE1 1HF',
+ fields => {
+ title => 'This is a very long title that should fail the validation',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => 'A User',
+ may_show_name => '1',
+ username => 'user@example.org',
+ phone => '',
+ category => 'Trees',
+ password_sign_in => '',
+ password_register => '',
+ },
+ changes => { },
+ errors => [ 'Summaries are limited to 50 characters in length. Please shorten your summary', 'Please enter some details'],
+ },
+ )
+{
+ subtest "check form errors where $test->{msg}" => sub {
+ $mech->get_ok('/around');
+
+ # submit initial pc form
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' }, 'bromley', 'oxfordshire', 'rutland', 'lincolnshire', 'buckinghamshire', 'northamptonshire', 'peterborough' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
+ "submit location" );
+ 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, },
+ "follow 'skip this step' link" );
+
+ # submit the main form
+ $mech->submit_form_ok( { with_fields => $test->{fields} },
+ "submit form" );
+ };
+
+ # check that we got the errors expected
+ is_deeply [ sort @{$mech->page_errors} ], [ sort @{$test->{errors}} ], "check errors";
+
+ # check that fields have changed as expected
+ my $new_values = {
+ %{ $test->{fields} }, # values added to form
+ %{ $test->{changes} }, # changes we expect
+ };
+ is_deeply $mech->visible_form_values, $new_values,
+ "values correctly changed";
+ };
+}
+
+# this test to make sure that we don't see spurious error messages about
+# the name being blank when there is a sign in error
+subtest "test password errors for a user who is signing in as they report" => sub {
+ my $user = $mech->create_user_ok('test-2@example.com',
+ name => 'Joe Bloggs',
+ phone => '01234 567 890',
+ password => 'secret2',
+ phone_verified => 1,
+ );
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok('/around?pc=GL50+2PR');
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ $mech->submit_form_ok(
+ {
+ button => 'submit_sign_in',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ photo1 => '',
+ username => 'test-2@example.com',
+ password_sign_in => 'secret1',
+ category => 'Street lighting',
+ }
+ },
+ "submit with wrong password"
+ );
+ };
+
+ # check that we got the errors expected
+ is_deeply $mech->page_errors, [
+ "There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the \x{2018}No\x{2019} section of the form.",
+ ], "check there were errors";
+
+ $mech->content_lacks('1234 567', 'phone number not shown');
+};
+
+subtest "check that a lat/lon off coast leads to /around" => sub {
+ my $off_coast_latitude = 50.78301;
+ my $off_coast_longitude = -0.646929;
+
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok(
+ "/report/new"
+ . "?latitude=$off_coast_latitude"
+ . "&longitude=$off_coast_longitude"
+ );
+ };
+
+ is $mech->uri->path, '/around', "redirected to '/around'";
+
+ is_deeply
+ $mech->page_errors,
+ [ 'That location does not appear to be covered by a council; perhaps it is offshore or outside the country. Please try again.' ],
+ "Found location error";
+
+};
+
+done_testing;
diff --git a/t/app/controller/report_new_unresponsive.t b/t/app/controller/report_new_unresponsive.t
new file mode 100644
index 000000000..033475c25
--- /dev/null
+++ b/t/app/controller/report_new_unresponsive.t
@@ -0,0 +1,122 @@
+use FixMyStreet::TestMech;
+
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $body_edin = $mech->create_body_ok(2651, 'City of Edinburgh Council', { send_method => 'Refused' });
+my $body_chelt = $mech->create_body_ok(2326, 'Cheltenham Borough Council');
+$mech->create_contact_ok(body_id => $body_edin->id, category => 'Street lighting', email => 'highways@example.com');
+my $contact = $mech->create_contact_ok(body_id => $body_chelt->id, category => 'Trees', email => 'trees@example.org');
+$mech->create_contact_ok(body_id => $body_edin->id, category => 'Trees', email => 'trees@example.com');
+my $user = $mech->create_user_ok('test-2@example.com');
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+ subtest "unresponsive body handling, body-level send method" => sub {
+ my $body_id = $body_edin->id;
+ my $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=55.952055&longitude=-3.189579');
+ like $extra_details->{top_message}, qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id};
+ is_deeply $extra_details->{unresponsive}, { $body_id => 1 }, "unresponsive json set";
+ $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Street%20lighting&latitude=55.952055&longitude=-3.189579');
+ is_deeply $extra_details->{unresponsive}, { $body_id => 1 }, "unresponsive json set";
+
+ make_report('EH1 1BB');
+
+ like $mech->get_text_body_from_email, qr/despite not being sent/i, "correct email sent";
+
+ $user->problems->delete;
+ };
+
+ subtest "unresponsive body handling from mobile app" => sub {
+ $mech->log_out_ok;
+ $mech->post_ok( '/report/new/mobile', {
+ title => "Test Report at café",
+ detail => 'Test report details.',
+ photo1 => '',
+ name => 'Joe Bloggs',
+ email => $user->email,
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => 'Trees',
+ service => 'iOS',
+ lat => 55.952055,
+ lon => -3.189579,
+ pc => '',
+ used_map => '1',
+ submit_register => '1',
+ password_register => '',
+ });
+ my $res = $mech->response;
+ ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json';
+
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+ is $report->bodies_str, undef, "Report not going anywhere";
+
+ like $mech->get_text_body_from_email, qr/despite not being sent/i, "correct email sent";
+
+ $body_edin->update({ send_method => undef });
+ $user->problems->delete;
+ };
+
+ subtest "unresponsive body handling, per-category refusing" => sub {
+ $contact->update({ email => 'REFUSED' });
+ my $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=51.896268&longitude=-2.093063');
+ like $extra_details->{by_category}{Trees}{category_extra}, qr/Cheltenham.*Trees.*unresponsive.*category=Trees/s;
+ $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063');
+ is_deeply $extra_details->{unresponsive}, { $body_chelt->id => 1 }, "unresponsive json set";
+
+ make_report('GL50 2PR');
+
+ $contact->update({ email => 'trees@example.org' });
+ };
+
+ subtest "unresponsive body page works" => sub {
+ my $url = "/unresponsive?body=" . $body_edin->id;
+ is $mech->get($url)->code, 404, "page not found";
+ $body_edin->update({ send_method => 'Refused' });
+ $mech->get_ok($url);
+ $mech->content_contains('Edinburgh');
+ $body_edin->update({ send_method => undef });
+
+ $url = "/unresponsive?body=" . $body_chelt->id . ";category=Trees";
+ is $mech->get($url)->code, 404, "page not found";
+ $contact->update({ email => 'REFUSED' });
+ $mech->get_ok($url);
+ $mech->content_contains('Cheltenham');
+ $mech->content_contains('Trees');
+ };
+};
+
+done_testing;
+
+sub make_report {
+ my $pc = shift;
+ $mech->get_ok('/around');
+ $mech->submit_form_ok( { with_fields => { pc => $pc } }, "submit location" );
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ title => "Test Report at café",
+ detail => 'Test report details.',
+ photo1 => '',
+ name => 'Joe Bloggs',
+ username => $user->email,
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => 'Trees',
+ }
+ },
+ "submit good details"
+ );
+
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+ is $report->bodies_str, undef, "Report not going anywhere";
+}