aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller')
-rw-r--r--t/app/controller/admin/bodies.t39
-rw-r--r--t/app/controller/admin/report_edit.t125
-rw-r--r--t/app/controller/admin/stats.t26
-rw-r--r--t/app/controller/admin/templates.t51
-rw-r--r--t/app/controller/alert_new.t5
-rw-r--r--t/app/controller/around.t10
-rw-r--r--t/app/controller/contact.t66
-rw-r--r--t/app/controller/develop.t33
-rw-r--r--t/app/controller/fakemapit.t13
-rw-r--r--t/app/controller/open311.t13
-rw-r--r--t/app/controller/photo.t36
-rw-r--r--t/app/controller/questionnaire.t21
-rw-r--r--t/app/controller/report_as_other.t31
-rw-r--r--t/app/controller/report_display.t106
-rw-r--r--t/app/controller/report_inspect.t59
-rw-r--r--t/app/controller/report_new.t162
-rw-r--r--t/app/controller/report_new_open311.t138
-rw-r--r--t/app/controller/report_updates.t55
-rw-r--r--t/app/controller/reports.t3
19 files changed, 852 insertions, 140 deletions
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index 9bdf8fb9a..a485d286d 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -150,6 +150,45 @@ subtest 'check open311 configuring' => sub {
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';
+ ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
+
+ $mech->form_number(3);
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ api_key => 'new api key',
+ endpoint => 'http://example.org/open311',
+ jurisdiction => 'open311',
+ send_comments => 0,
+ send_method => 'Open311',
+ fetch_all_problems => 1,
+ }
+ }
+ );
+
+ $mech->content_contains('Values updated');
+
+ $conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
+ ok $conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems set';
+
+ $mech->form_number(3);
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ api_key => 'new api key',
+ endpoint => 'http://example.org/open311',
+ jurisdiction => 'open311',
+ send_comments => 0,
+ send_method => 'Open311',
+ fetch_all_problems => 0,
+ }
+ }
+ );
+
+ $mech->content_contains('Values updated');
+
+ $conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
+ ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
};
subtest 'check text output' => sub {
diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t
index a8a0bd143..5e3e6c315 100644
--- a/t/app/controller/admin/report_edit.t
+++ b/t/app/controller/admin/report_edit.t
@@ -79,6 +79,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => { title => 'Edited Report', },
log_entries => [qw/edit/],
@@ -95,6 +96,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => { detail => 'Edited Detail', },
log_entries => [qw/edit edit/],
@@ -111,6 +113,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => { name => 'Edited User', },
log_entries => [qw/edit edit edit/],
@@ -128,6 +131,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => {
flagged => 'on',
@@ -147,6 +151,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
changes => { username => $user2->email, },
log_entries => [qw/edit edit edit edit edit/],
@@ -164,6 +169,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'unconfirmed' },
@@ -181,6 +187,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'confirmed' },
@@ -198,6 +205,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'fixed' },
@@ -216,6 +224,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'hidden' },
@@ -235,6 +244,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => {
@@ -257,6 +267,7 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
changes => {},
log_entries => [
@@ -275,6 +286,7 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
changes => {
non_public => 'on',
@@ -285,6 +297,24 @@ foreach my $test (
resend => 0,
},
{
+ description => 'close to updates',
+ fields => {
+ title => 'Edited Report',
+ detail => 'Edited Detail',
+ state => 'confirmed',
+ name => 'Edited User',
+ username => $user2->email,
+ anonymous => 1,
+ flagged => 'on',
+ non_public => 'on',
+ closed_updates => undef,
+ },
+ changes => { closed_updates => 'on' },
+ log_entries => [
+ qw/edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
+ ],
+ },
+ {
description => 'change state to investigating as body superuser',
fields => {
title => 'Edited Report',
@@ -295,12 +325,13 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => 'on',
+ closed_updates => undef,
},
expect_comment => 1,
user_body => $oxfordshire,
changes => { state => 'investigating' },
log_entries => [
- qw/edit state_change edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
+ qw/edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
],
resend => 0,
},
@@ -315,13 +346,14 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => 'on',
+ closed_updates => undef,
},
expect_comment => 1,
expected_text => '*Category changed from ‘Other’ to ‘Potholes’*',
user_body => $oxfordshire,
changes => { state => 'in progress', category => 'Potholes' },
log_entries => [
- qw/edit state_change edit state_change edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
+ qw/edit state_change edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
],
resend => 0,
},
@@ -364,9 +396,22 @@ foreach my $test (
$mech->content_lacks( 'type="submit" name="resend"', 'no resend button' );
}
+ if ($report->state eq 'fixed') {
+ $mech->content_contains('pin-green');
+ }
+
$test->{changes}->{flagged} = 1 if $test->{changes}->{flagged};
$test->{changes}->{non_public} = 1 if $test->{changes}->{non_public};
+ if ($test->{changes}->{closed_updates}) {
+ is $report->get_extra_metadata('closed_updates'), 1, "closed_updates updated";
+ $mech->get_ok("/report/$report_id");
+ $mech->content_lacks('Provide an update');
+ $report->unset_extra_metadata('closed_updates');
+ $report->update;
+ delete $test->{changes}->{closed_updates};
+ }
+
is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'username' } keys %{ $test->{changes} };
if ( $test->{user} ) {
@@ -447,6 +492,7 @@ subtest 'change email to new user' => sub {
anonymous => 1,
flagged => 'on',
non_public => 'on',
+ closed_updates => undef,
external_id => '13',
external_body => '',
external_team => '',
@@ -553,4 +599,79 @@ subtest "Test setting a report from unconfirmed to something else doesn't cause
$mech->get_ok("/report/$report_id");
};
+subtest "Test display of report extra data" => sub {
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Extra data: No');
+ $report->set_extra_metadata('extra_field', 'this is extra data');
+ $report->update;
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('extra_field</strong>: this is extra data');
+};
+
+my $report2 = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'SW1A 1AA',
+ bodies_str => '2504',
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => 'Report to Duplicate Edit',
+ detail => 'Detail for Duplicate Report to Edit',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ external_id => '13',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => '',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ whensent => $dt->ymd . ' ' . $dt->hms,
+ }
+);
+
+subtest "Test display of report duplicates extra data" => sub {
+ $report->update( { extra => undef } );
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Extra data: No');
+
+ $report2->set_duplicate_of($report_id);
+ $report2->update;
+
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Duplicates</strong>: ' . $report2->id);
+};
+
+subtest "Test display of fields extra data" => sub {
+ $report->unset_extra_metadata( 'duplicates' );
+ $report->update;
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Extra data: No');
+
+ $report->push_extra_fields( {
+ name => 'report_url',
+ value => 'http://example.com',
+ });
+ $report->update;
+
+ $report->discard_changes;
+
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('report_url</strong>: http://example.com');
+
+ $report->set_extra_fields( {
+ description => 'Report URL',
+ name => 'report_url',
+ value => 'http://example.com',
+ });
+ $report->update;
+
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Report URL (report_url)</strong>: http://example.com');
+};
+
done_testing();
diff --git a/t/app/controller/admin/stats.t b/t/app/controller/admin/stats.t
index dae51d31f..ce6f8466c 100644
--- a/t/app/controller/admin/stats.t
+++ b/t/app/controller/admin/stats.t
@@ -9,4 +9,30 @@ subtest "smoke view some stats pages" => sub {
$mech->get_ok('/admin/stats/questionnaire');
};
+subtest "test refused stats page works" => sub {
+ my $body1 = $mech->create_body_ok(2651, 'Edinburgh Council');
+ my $body2 = $mech->create_body_ok(2237, 'Oxfordshire Council', { send_method => 'Refused' });
+ my $body3 = $mech->create_body_ok(2243, 'Warwickshire Council', { can_be_devolved => 1 });
+ $mech->create_contact_ok(body_id => $body1->id, category => 'Street lighting', email => 'REFUSED');
+ $mech->create_contact_ok(body_id => $body1->id, category => 'Potholes', email => 'potholes@example.org');
+ $mech->create_contact_ok(body_id => $body2->id, category => 'Potholes', email => 'potholes@example.org');
+ $mech->create_contact_ok(body_id => $body3->id, category => 'Street lighting', email => 'lights@example.org');
+ $mech->create_contact_ok(body_id => $body3->id, category => 'Potholes', email => 'potholes@example.org', send_method => 'Refused');
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ }, sub {
+ $mech->get_ok('/admin/stats/refused');
+ };
+ $mech->content =~ /class="content"(.*)class="nav-wrapper/s;
+ my @lines = split /<li>/, $1;
+ is @lines, 7;
+ like $lines[1], qr/Edinburgh/;
+ like $lines[2], qr/Street lighting/;
+ like $lines[3], qr/Oxfordshire/;
+ like $lines[4], qr/ALL/;
+ like $lines[5], qr/Warwickshire/;
+ like $lines[6], qr/Potholes/;
+};
+
done_testing();
diff --git a/t/app/controller/admin/templates.t b/t/app/controller/admin/templates.t
index 179a1afcb..0d4430cad 100644
--- a/t/app/controller/admin/templates.t
+++ b/t/app/controller/admin/templates.t
@@ -180,4 +180,55 @@ subtest "all-category auto-response templates that duplicate a single category c
is $oxfordshire->response_templates->count, 1, "Duplicate response template wasn't added";
};
+subtest "auto-response templates that duplicate external_status_code can't be added" => sub {
+ $mech->delete_response_template($_) for $oxfordshire->response_templates;
+ my $template = $oxfordshire->response_templates->create({
+ title => "Report fixed - potholes",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 1,
+ external_status_code => '100',
+ });
+ $template->contact_response_templates->find_or_create({
+ contact_id => $oxfordshirecontact->id,
+ });
+ is $oxfordshire->response_templates->count, 1, "Initial response template was created";
+
+
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" );
+
+ my $fields = {
+ title => "Report marked fixed - all cats",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 'on',
+ external_status_code => '100',
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/templates/' . $oxfordshire->id . '/new', 'not redirected';
+ $mech->content_contains( 'Please correct the errors below' );
+ $mech->content_contains( 'There is already an auto-response template for this category/state.' );
+
+ is $oxfordshire->response_templates->count, 1, "Duplicate response template wasn't added";
+};
+
+subtest "templates that set state and external_status_code can't be added" => sub {
+ $mech->delete_response_template($_) for $oxfordshire->response_templates;
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" );
+
+ my $fields = {
+ title => "Report marked fixed - all cats",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 'on',
+ state => 'fixed - council',
+ external_status_code => '100',
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/templates/' . $oxfordshire->id . '/new', 'not redirected';
+ $mech->content_contains( 'Please correct the errors below' );
+ $mech->content_contains( 'State and external status code cannot be used simultaneously.' );
+
+ is $oxfordshire->response_templates->count, 0, "Invalid response template wasn't added";
+};
+
done_testing();
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 4e8fd1b29..27371e4a9 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -451,9 +451,8 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
is $count, 5, 'Three emails, with five matching lines in them';
my $email = $emails[0];
- my $body = $mech->get_text_body_from_email($email);
- like $body, qr/Other User/, 'Update name given';
- unlike $body, qr/Anonymous User/, 'Update name not given';
+ is +(my $c = () = $email->as_string =~ /Other User/g), 2, 'Update name given, twice';
+ unlike $email->as_string, qr/Anonymous User/, 'Update name not given';
# The update alert was to the problem reporter, so has a special update URL
$mech->log_out_ok;
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index 618998513..8eaba6450 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -137,7 +137,7 @@ subtest 'check non public reports are not displayed on around page' => sub {
};
-subtest 'check category and status filtering works on /around' => sub {
+subtest 'check category, status and extra filtering works on /around' => sub {
my $body = $mech->create_body_ok(2237, "Oxfordshire");
my $categories = [ 'Pothole', 'Vegetation', 'Flytipping' ];
@@ -157,6 +157,7 @@ subtest 'check category and status filtering works on /around' => sub {
%$params,
category => $category,
state => $state,
+ external_body => "$category-$state",
);
$mech->create_problems_for_body( 1, $body->id, 'Around page', \%report_params );
}
@@ -185,6 +186,13 @@ subtest 'check category and status filtering works on /around' => sub {
$json = $mech->get_ok_json( '/around?ajax=1&status=fixed&filter_category=Vegetation&bbox=' . $bbox );
$pins = $json->{pins};
is scalar @$pins, 1, 'correct number of fixed Vegetation reports';
+
+ my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Default');
+ $cobrand->mock('display_location_extra_params', sub { { external_body => "Pothole-fixed" } });
+
+ $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
+ $pins = $json->{pins};
+ is scalar @$pins, 1, 'correct number of external_body reports';
};
subtest 'check skip_around skips around page' => sub {
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index c1039d15b..4f255f058 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -37,6 +37,17 @@ for my $test (
detail => 'More detail on the different problem',
postcode => 'EH99 1SP',
confirmed => '2011-05-03 13:24:28.145168',
+ anonymous => 0,
+ hidden => 1,
+ meta => 'Reported anonymously at 13:24, Tue 3 May 2011',
+ },
+ {
+ name => 'A User',
+ email => 'problem_report_test@example.com',
+ title => 'A different problem',
+ detail => 'More detail on the different problem',
+ postcode => 'EH99 1SP',
+ confirmed => '2011-05-03 13:24:28.145168',
anonymous => 1,
meta => 'Reported anonymously at 13:24, Tue 3 May 2011',
update => {
@@ -45,6 +56,38 @@ for my $test (
text => 'This is an update',
},
},
+ {
+ name => 'A User',
+ email => 'problem_report_test@example.com',
+ title => 'A different problem',
+ detail => 'More detail on the different problem',
+ postcode => 'EH99 1SP',
+ confirmed => '2011-05-03 13:24:28.145168',
+ anonymous => 1,
+ meta => 'Reported anonymously at 13:24, Tue 3 May 2011',
+ update => {
+ other_problem => 1,
+ name => 'Different User',
+ email => 'commenter@example.com',
+ text => 'This is an update',
+ },
+ },
+ {
+ name => 'A User',
+ email => 'problem_report_test@example.com',
+ title => 'A different problem',
+ detail => 'More detail on the different problem',
+ postcode => 'EH99 1SP',
+ confirmed => '2011-05-03 13:24:28.145168',
+ anonymous => 1,
+ meta => 'Reported anonymously at 13:24, Tue 3 May 2011',
+ update => {
+ hidden => 1,
+ name => 'Different User',
+ email => 'commenter@example.com',
+ text => 'This is an update',
+ },
+ },
)
{
subtest 'check reporting a problem displays correctly' => sub {
@@ -58,7 +101,7 @@ for my $test (
confirmed => $test->{confirmed},
name => $test->{name},
anonymous => $test->{anonymous},
- state => 'confirmed',
+ state => $test->{hidden} ? 'hidden' : 'confirmed',
user => $user,
latitude => 0,
longitude => 0,
@@ -76,9 +119,9 @@ for my $test (
$update = FixMyStreet::App->model('DB::Comment')->create(
{
- problem_id => $problem->id,
+ problem_id => $update_info->{other_problem} ? $problem_main->id : $problem->id,
user => $update_user,
- state => 'confirmed',
+ state => $update_info->{hidden} ? 'hidden' : 'confirmed',
text => $update_info->{text},
confirmed => \'current_timestamp',
mark_fixed => 'f',
@@ -90,9 +133,20 @@ for my $test (
ok $problem, 'succesfully create a problem';
if ( $update ) {
- $mech->get_ok( '/contact?id=' . $problem->id . '&update_id=' . $update->id );
- $mech->content_contains('reporting the following update');
- $mech->content_contains( $test->{update}->{text} );
+ if ( $test->{update}->{hidden} ) {
+ $mech->get( '/contact?id=' . $problem->id . '&update_id=' . $update->id );
+ is $mech->res->code, 404, 'cannot report a hidden update';
+ } elsif ( $test->{update}->{other_problem} ) {
+ $mech->get( '/contact?id=' . $problem->id . '&update_id=' . $update->id );
+ is $mech->res->code, 404, 'cannot view an update for another problem';
+ } else {
+ $mech->get_ok( '/contact?id=' . $problem->id . '&update_id=' . $update->id );
+ $mech->content_contains('reporting the following update');
+ $mech->content_contains( $test->{update}->{text} );
+ }
+ } elsif ( $test->{hidden} ) {
+ $mech->get( '/contact?id=' . $problem->id );
+ is $mech->res->code, 410, 'cannot report a hidden problem';
} else {
$mech->get_ok( '/contact?id=' . $problem->id );
$mech->content_contains('reporting the following problem');
diff --git a/t/app/controller/develop.t b/t/app/controller/develop.t
new file mode 100644
index 000000000..92aa86721
--- /dev/null
+++ b/t/app/controller/develop.t
@@ -0,0 +1,33 @@
+use FixMyStreet::TestMech;
+
+ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
+
+my ($problem) = $mech->create_problems_for_body(1, 2504, 'title');
+my $update = $mech->create_comment_for_problem($problem, $problem->user, 'Name', 'Text', 'f', 'confirmed', 'confirmed');
+
+subtest 'not visible on live site' => sub {
+ FixMyStreet::override_config {
+ STAGING_SITE => 0
+ }, sub {
+ $mech->get('/_dev/email/');
+ is $mech->res->code, 404;
+ $mech->get('/_dev/email/login');
+ is $mech->res->code, 404;
+ };
+};
+
+subtest 'dev email index page' => sub {
+ $mech->get_ok('/_dev/email/');
+ $mech->content_contains('login">login</a></li>');
+ $mech->content_contains('questionnaire?problem=' . $problem->id . '">questionnaire</a></li>');
+ $mech->content_contains('update-confirm?update=' . $update->id . '">update-confirm</a></li>');
+};
+
+subtest 'individual email previews' => sub {
+ $mech->get_ok('/_dev/email/alert-problem-area');
+ $mech->get_ok('/_dev/email/alert-update?problem=' . $problem->id);
+ $mech->get_ok('/_dev/email/questionnaire?problem=' . $problem->id);
+ $mech->get_ok('/_dev/email/update-confirm?update=' . $update->id);
+};
+
+done_testing();
diff --git a/t/app/controller/fakemapit.t b/t/app/controller/fakemapit.t
new file mode 100644
index 000000000..c89aac600
--- /dev/null
+++ b/t/app/controller/fakemapit.t
@@ -0,0 +1,13 @@
+use JSON::MaybeXS;
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+ $mech->get_ok('/mapit/areas/Birmingham');
+ is_deeply decode_json($mech->content), {2514 => {parent_area => undef, id => 2514, name => "Birmingham City Council", type => "MTD"}};
+};
+
+done_testing;
diff --git a/t/app/controller/open311.t b/t/app/controller/open311.t
index 29cd38129..9f4f594fe 100644
--- a/t/app/controller/open311.t
+++ b/t/app/controller/open311.t
@@ -1,3 +1,4 @@
+use JSON::MaybeXS;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -5,4 +6,16 @@ my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/open311.cgi/v2/requests.rss?jurisdiction_id=fiksgatami.no&status=open&agency_responsible=1854');
like $mech->uri, qr[/open311/v2/requests\.rss\?.{65}]; # Don't know order parameters will be in now
+$mech->create_problems_for_body(2, 2237, 'Around page');
+$mech->get_ok('/open311/v2/requests.xml?jurisdiction_id=foo&status=open&agency_responsible=2237');
+$mech->content_contains('<description>Around page Test 2 for 2237: Around page Test 2 for 2237 Detail</description>');
+$mech->content_contains('<interface_used>Web interface</interface_used>');
+$mech->content_contains('<status>open</status>');
+
+$mech->get_ok('/open311/v2/requests.json?jurisdiction_id=foo&status=open&agency_responsible=2237');
+my $json = decode_json($mech->content);
+my $problems = $json->{requests}[0]{request};
+is @$problems, 2;
+like $problems->[0]{description}, qr/Around page Test/;
+
done_testing();
diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t
index dbbc697d7..e9183836b 100644
--- a/t/app/controller/photo.t
+++ b/t/app/controller/photo.t
@@ -66,7 +66,43 @@ subtest "Check multiple upload worked" => sub {
'Returned upload_fileid contains expected hash, 3 times');
my $image_file = path($UPLOAD_DIR, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg');
ok $image_file->exists, 'File uploaded to temp';
+
+ $mech->submit_form_ok({ with_fields => { name => 'Bob Jones' } });
+ ok $mech->success, 'Made request with multiple photo upload';
};
};
+subtest "Check photo uploading URL works" => sub {
+ my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
+
+ # submit initial pc form
+ FixMyStreet::override_config {
+ UPLOAD_DIR => $UPLOAD_DIR,
+ }, sub {
+ $mech->post( '/photo/upload',
+ Content_Type => 'form-data',
+ Content => {
+ photo1 => [ $sample_file, undef, Content_Type => 'application/octet-stream' ],
+ },
+ );
+ ok $mech->success, 'Made request with multiple photo upload';
+ is $mech->content, '{"id":"74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg"}';
+ my $image_file = path($UPLOAD_DIR, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg');
+ ok $image_file->exists, 'File uploaded to temp';
+ };
+};
+
+subtest "Check photo URL endpoints work" => sub {
+ my $p = FixMyStreet::DB->resultset("Problem")->first;
+
+ $mech->get_ok('/photo/temp.74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg');
+ my $image_file = FixMyStreet->path_to('web/photo/temp.74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg');
+ ok -e $image_file, 'File uploaded to temp';
+ $mech->get_ok('/photo/' . $p->id . '.jpeg');
+ $image_file = FixMyStreet->path_to('web/photo/' . $p->id . '.jpeg');
+ ok -e $image_file, 'File uploaded to temp';
+ my $res = $mech->get('/photo/0.jpeg');
+ is $res->code, 404, "got 404";
+};
+
done_testing();
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index c6d112df7..75542d759 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -52,7 +52,7 @@ like $plain->body, qr/fill in our short questionnaire/i, "got questionnaire emai
like $plain->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character';
is $plain->header('Content-Type'), 'text/plain; charset="utf-8"', 'in the right character set';
-my $url = $mech->get_link_from_email($email);
+my $url = $mech->get_link_from_email($email, 0, 1);
my ($token) = $url =~ m{/Q/(\S+)};
ok $token, "extracted questionnaire token '$token'";
$mech->clear_emails_ok;
@@ -108,6 +108,23 @@ foreach my $test (
};
}
+subtest "If been_fixed is provided in the URL" => sub {
+ $mech->get_ok("/Q/" . $token->token . "?been_fixed=Yes");
+ $mech->content_contains('id="been_fixed_yes" value="Yes" checked');
+ $report->discard_changes;
+ is $report->state, 'fixed - user';
+ $questionnaire->discard_changes;
+ is $questionnaire->old_state, 'confirmed';
+ is $questionnaire->new_state, 'fixed - user';
+ $mech->submit_form_ok({ with_fields => { been_fixed => 'Unknown', reported => 'Yes', another => 'No' } });
+ $report->discard_changes;
+ is $report->state, 'confirmed';
+ $questionnaire->discard_changes;
+ is $questionnaire->old_state, 'confirmed';
+ is $questionnaire->new_state, 'unknown';
+ $questionnaire->update({ whenanswered => undef, ever_reported => undef, old_state => undef, new_state => undef });
+};
+
$mech->get_ok("/Q/" . $token->token);
$mech->title_like( qr/Questionnaire/ );
$mech->submit_form_ok( );
@@ -399,7 +416,7 @@ FixMyStreet::override_config {
$mech->clear_emails_ok;
$body =~ s/\s+/ /g;
like $body, qr/fill in our short questionnaire/i, "got questionnaire email";
- my $url = $mech->get_link_from_email($email);
+ my $url = $mech->get_link_from_email($email, 0, 1);
($token) = $url =~ m{/Q/(\S+)};
ok $token, "extracted questionnaire token '$token'";
diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t
index e8f65eb7b..367d9a1d4 100644
--- a/t/app/controller/report_as_other.t
+++ b/t/app/controller/report_as_other.t
@@ -1,5 +1,6 @@
use FixMyStreet::TestMech;
use FixMyStreet::App;
+use FixMyStreet::Script::Reports;
# disable info logs for this test run
FixMyStreet::App->log->disable('info');
@@ -15,7 +16,7 @@ my $test_email = 'body-user@example.net';
my $user = $mech->log_in_ok($test_email);
$user->update({ from_body => $body->id, name => 'Body User' });
-my ($report_to_update) = $mech->create_problems_for_body(1, $body->id, 'Title');
+my ($report_to_update) = $mech->create_problems_for_body(1, $body->id, 'Title', { category => 'Potholes' });
subtest "Body user, no permissions, no special reporting tools shown" => sub {
start_report();
@@ -100,6 +101,9 @@ subtest "Body user, has permission to add report as another user with landline n
};
subtest "Body user, has permission to add report as another (existing) user with email" => sub {
+ FixMyStreet::Script::Reports::send();
+ $mech->clear_emails_ok;
+
$mech->create_user_ok('existing@example.net', name => 'Existing User');
my $report = add_report(
'contribute_as_another_user',
@@ -116,6 +120,15 @@ subtest "Body user, has permission to add report as another (existing) user with
isnt $report->user->id, $user->id, 'user does not match';
like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/;
push @users, $report->user;
+
+ my $send_confirmation_mail_override = Sub::Override->new(
+ "FixMyStreet::Cobrand::Default::report_sent_confirmation_email",
+ sub { return 1; }
+ );
+ FixMyStreet::Script::Reports::send();
+ $mech->email_count_is(2);
+ $mech->clear_emails_ok;
+ $send_confirmation_mail_override->restore();
};
subtest "Body user, has permission to add report as another (existing) user with phone" => sub {
@@ -138,6 +151,9 @@ subtest "Body user, has permission to add report as another (existing) user with
};
subtest "Body user, has permission to add report as anonymous user" => sub {
+ FixMyStreet::Script::Reports::send();
+ $mech->clear_emails_ok;
+
my $report = add_report(
'contribute_as_anonymous_user',
form_as => 'anonymous_user',
@@ -149,6 +165,19 @@ subtest "Body user, has permission to add report as anonymous user" => sub {
is $report->user->name, 'Body User', 'user name unchanged';
is $report->user->id, $user->id, 'user matches';
is $report->anonymous, 1, 'report anonymous';
+
+ my $send_confirmation_mail_override = Sub::Override->new(
+ "FixMyStreet::Cobrand::Default::report_sent_confirmation_email",
+ sub { return 1; }
+ );
+
+ FixMyStreet::Script::Reports::send();
+ # No report sent email is sent
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ like $email->header('Subject'), qr/Problem Report: Test Report/, 'report email title correct';
+ $mech->clear_emails_ok;
+ $send_confirmation_mail_override->restore();
};
subtest "Body user, has permission to add update as council" => sub {
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index f0913fbd2..17b9180c1 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -115,6 +115,12 @@ subtest "duplicate reports are signposted correctly" => sub {
$report2->update;
};
+subtest "test /report/ajax" => sub {
+ my $json = $mech->get_ok_json( "/report/ajax/$report_id" );
+ is $json->{report}->{title}, "Test 2", "correct title";
+ is $json->{report}->{state}, "confirmed", "correct state";
+};
+
subtest "test a good report" => sub {
$mech->get_ok("/report/$report_id");
is $mech->uri->path, "/report/$report_id", "at /report/$report_id";
@@ -419,106 +425,6 @@ for my $test (
};
}
-subtest "Zurich unconfirmeds are 200" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->host( 'zurich.example.com' );
- ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report';
- $mech->get_ok("/report/$report_id");
- $mech->content_contains( '&Uuml;berpr&uuml;fung ausstehend' );
- ok $report->update( { state => 'confirmed' } ), 'confirm report again';
- $mech->host( 'www.fixmystreet.com' );
- };
-};
-
-subtest "Zurich banners are displayed correctly" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->host( 'zurich.example.com' );
-
- for my $test (
- {
- description => 'new report',
- state => 'unconfirmed',
- banner_id => 'closed',
- banner_text => 'Erfasst'
- },
- {
- description => 'confirmed report',
- state => 'confirmed',
- banner_id => 'closed',
- banner_text => 'Aufgenommen',
- },
- {
- description => 'fixed report',
- state => 'fixed - council',
- banner_id => 'fixed',
- banner_text => 'Beantwortet',
- },
- {
- description => 'closed report',
- state => 'closed',
- banner_id => 'closed',
- banner_text => _('Extern'),
- },
- {
- description => 'in progress report',
- state => 'in progress',
- banner_id => 'progress',
- banner_text => 'In Bearbeitung',
- },
- {
- description => 'planned report',
- state => 'planned',
- banner_id => 'progress',
- banner_text => 'In Bearbeitung',
- },
- {
- description => 'planned report',
- state => 'planned',
- banner_id => 'progress',
- banner_text => 'In Bearbeitung',
- },
- {
- description => 'jurisdiction unknown',
- state => 'unable to fix',
- banner_id => 'fixed',
- # We can't use _('Jurisdiction Unknown') here because
- # TestMech::extract_problem_banner decodes the HTML entities before
- # the string is passed back.
- banner_text => 'Zust\x{e4}ndigkeit unbekannt',
- },
- ) {
- subtest "banner for $test->{description}" => sub {
- $report->state( $test->{state} );
- $report->update;
-
- $mech->get_ok("/report/$report_id");
- is $mech->uri->path, "/report/$report_id", "at /report/$report_id";
- my $banner = $mech->extract_problem_banner;
- if ( $banner->{text} ) {
- $banner->{text} =~ s/^ //g;
- $banner->{text} =~ s/ $//g;
- }
-
- is $banner->{id}, $test->{banner_id}, 'banner id';
- if ($test->{banner_text}) {
- like_string( $banner->{text}, qr/$test->{banner_text}/i, 'banner text is ' . $test->{banner_text} );
- } else {
- is $banner->{text}, $test->{banner_text}, 'banner text';
- }
-
- };
- }
-
- $mech->host( 'www.fixmystreet.com' );
- };
-};
-
my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council');
my $oxfordshireuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $oxfordshire);
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 239cc408b..6a001225d 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -36,8 +36,8 @@ my $report_id = $report->id;
my $report2_id = $report2->id;
my $report3_id = $report3->id;
-
-my $user = $mech->log_in_ok('test@example.com');
+$mech->create_user_ok('body@example.com', name => 'Body User');
+my $user = $mech->log_in_ok('body@example.com');
$user->set_extra_metadata('categories', [ $contact->id ]);
$user->update( { from_body => $oxon } );
@@ -50,18 +50,36 @@ FixMyStreet::override_config {
$mech->content_lacks('Save changes');
$mech->content_lacks('Priority');
$mech->content_lacks('Traffic management');
+ $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)');
$user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
$mech->get_ok("/report/$report_id");
$mech->content_contains('Save changes');
$mech->content_contains('Priority');
$mech->content_lacks('Traffic management');
+ $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)');
$user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' });
$mech->get_ok("/report/$report_id");
$mech->content_contains('Save changes');
$mech->content_contains('Priority');
$mech->content_contains('Traffic management');
+ $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)');
+ };
+
+ subtest "council staff can't see admin report edit link on FMS.com" => sub {
+ my $report_edit_permission = $user->user_body_permissions->create({
+ body => $oxon, permission_type => 'report_edit' });
+ $mech->get_ok("/report/$report_id");
+ $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)');
+ $report_edit_permission->delete;
+ };
+
+ subtest "superusers can see admin report edit link on FMS.com" => sub {
+ $user->update({is_superuser => 1});
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains('/admin/report_edit/'.$report_id.'">admin</a>)');
+ $user->update({is_superuser => 0});
};
subtest "test basic inspect submission" => sub {
@@ -539,6 +557,13 @@ FixMyStreet::override_config {
is $report->get_extra_metadata('traffic_information'), 'Signs and Cones', 'report data changed';
};
+ subtest "admin link present on inspect page on cobrand" => sub {
+ my $report_edit_permission = $user->user_body_permissions->create({
+ body => $oxon, permission_type => 'report_edit' });
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains('/admin/report_edit/'.$report_id.'">admin</a>)');
+ $report_edit_permission->delete;
+ };
};
FixMyStreet::override_config {
@@ -559,6 +584,7 @@ FixMyStreet::override_config {
my $expected_fields = {
state => 'action scheduled',
category => 'Cows',
+ non_public => undef,
public_update => '',
priority => $rp->id,
include_update => '1',
@@ -594,6 +620,35 @@ FixMyStreet::override_config {
is $report->comments->count, 1, "Only leaves one update";
like $report->comments->first->text, qr/Category changed.*Badgers/, 'update text included category change';
};
+
+ subtest "test non-public changing" => sub {
+ $report->comments->delete;
+ is $report->non_public, 0, 'Not set to non-public';
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form(button => 'save', with_fields => { include_update => 0, non_public => 1 });
+ is $report->comments->count, 0, "No updates left";
+ $report->discard_changes;
+ is $report->non_public, 1, 'Now set to non-public';
+ $mech->submit_form(button => 'save', with_fields => { include_update => 0, non_public => 0 });
+ is $report->comments->count, 0, "No updates left";
+ $report->discard_changes;
+ is $report->non_public, 0, 'Not set to non-public';
+ };
+
+ subtest "test saved-at setting" => sub {
+ $report->comments->delete;
+ $mech->get_ok("/report/$report_id");
+ # set the timezone on this so the date comparison below doesn't fail due to mismatched
+ # timezones
+ my $now = DateTime->now(
+ time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone
+ )->subtract(days => 1);
+ $mech->submit_form(button => 'save', form_id => 'report_inspect_form',
+ fields => { include_update => 1, public_update => 'An update', saved_at => $now->epoch });
+ $report->discard_changes;
+ is $report->comments->count, 1, "One update";
+ is $report->comments->first->confirmed, $now;
+ };
};
FixMyStreet::override_config {
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 3c120b0b0..dff04176b 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -1,3 +1,4 @@
+use Test::MockModule;
use FixMyStreet::TestMech;
use FixMyStreet::App;
use Web::Scraper;
@@ -86,6 +87,16 @@ my $contact8 = $mech->create_contact_ok(
category => 'Street lighting',
email => 'highways@example.com'
);
+my $contact9 = $mech->create_contact_ok(
+ body_id => $body_ids{2226}, # Gloucestershire
+ category => 'Street lighting',
+ email => 'streetlights-2226@example.com',
+);
+my $contact10 = $mech->create_contact_ok(
+ body_id => $body_ids{2326}, # Cheltenham
+ category => 'Street lighting',
+ email => 'streetlights-2326@example.com',
+);
# test that the various bit of form get filled in and errors correctly
# generated.
@@ -932,6 +943,125 @@ foreach my $test (
}
+# XXX add test for category with multiple bodies
+foreach my $test (
+ {
+ desc => "test report creation for multiple bodies",
+ category => 'Street lighting',
+ councils => [ 2226, 2326 ],
+ extra_fields => {},
+ email_count => 2,
+ },
+ {
+ desc => "test single_body_only means only one report body",
+ category => 'Street lighting',
+ councils => [ 2326 ],
+ extra_fields => { single_body_only => 'Cheltenham Borough Council' },
+ email_count => 1,
+ },
+ {
+ desc => "test invalid single_body_only means multiple report bodies",
+ category => 'Street lighting',
+ councils => [ 2226, 2326 ],
+ extra_fields => { single_body_only => 'Invalid council' },
+ email_count => 1,
+ },
+) {
+ subtest $test->{desc} => sub {
+
+ # check that the user does not exist
+ my $test_email = 'test-2@example.com';
+
+ $mech->clear_emails_ok;
+ my $user = $mech->log_in_ok($test_email);
+
+ # setup the user.
+ ok $user->update(
+ {
+ name => 'Test User',
+ phone => '01234 567 890',
+ }
+ ),
+ "set users 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 => 'GL50 2PR', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ # check that the fields are correctly prefilled
+ is_deeply(
+ $mech->visible_form_values,
+ {
+ title => '',
+ detail => '',
+ may_show_name => '1',
+ name => 'Test User',
+ phone => '01234 567 890',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ category => '-- Pick a category --',
+ },
+ "user's details prefilled"
+ );
+
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ title => "Test Report at café",
+ detail => 'Test report details.',
+ photo1 => '',
+ name => 'Joe Bloggs',
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => $test->{category},
+ %{$test->{extra_fields}}
+ }
+ },
+ "submit good details"
+ );
+ };
+
+ # find the report
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+
+ # Check the report has been assigned appropriately
+ is $report->bodies_str, join(',', @body_ids{@{$test->{councils}}});
+
+ $mech->content_contains('Thank you for reporting this issue');
+
+ # check that no emails have been sent
+ $mech->email_count_is(0);
+
+ # check report is confirmed and available
+ is $report->state, 'confirmed', "report is now confirmed";
+ $mech->get_ok( '/report/' . $report->id );
+
+ # Test that AJAX pages return the right data
+ $mech->get_ok(
+ '/around?ajax=1&bbox=' . ($report->longitude - 0.01) . ',' . ($report->latitude - 0.01)
+ . ',' . ($report->longitude + 0.01) . ',' . ($report->latitude + 0.01)
+ );
+ $mech->content_contains( "Test Report at caf\xc3\xa9" );
+ $saved_lat = $report->latitude;
+ $saved_lon = $report->longitude;
+
+ # cleanup
+ $mech->delete_user($user);
+ };
+
+}
+
subtest "Test inactive categories" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
@@ -958,6 +1088,21 @@ subtest "Test inactive categories" => sub {
};
};
+subtest "category groups" => sub {
+ my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::FixMyStreet');
+ $cobrand->mock('enable_category_groups', sub { 1 });
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $contact2->update( { extra => { group => 'Roads' } } );
+ $contact9->update( { extra => { group => 'Roads' } } );
+ $contact10->update( { extra => { group => 'Roads' } } );
+ $mech->get_ok("/report/new?lat=$saved_lat&lon=$saved_lon");
+ $mech->content_like(qr{<optgroup label="Roads">\s*<option value='Potholes'>Potholes</option>\s*<option value='Street lighting'>Street lighting</option></optgroup>});
+ };
+};
+
subtest "test report creation for a category that is non public" => sub {
$mech->log_out_ok;
$mech->clear_emails_ok;
@@ -1040,6 +1185,7 @@ FixMyStreet::override_config {
$extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon );
};
$mech->content_contains( "Pothol\xc3\xa9s" );
+like $extra_details->{councils_text}, qr/<strong>Cheltenham/;
ok !$extra_details->{titles_list}, 'Non Bromley does not send back list of titles';
FixMyStreet::override_config {
@@ -1733,7 +1879,11 @@ subtest "extra google analytics code displayed on email confirmation problem cre
};
};
-subtest "inspectors get redirected directly to the report page" => sub {
+foreach my $test (
+ { non_public => 0 },
+ { non_public => 1 },
+) {
+ subtest "inspectors get redirected directly to the report page, non_public=$test->{non_public}" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
BASE_URL => 'https://www.fixmystreet.com',
@@ -1746,10 +1896,14 @@ subtest "inspectors get redirected directly to the report page" => sub {
body => $bodies[0],
permission_type => 'planned_reports',
});
+ $user->user_body_permissions->find_or_create({
+ body => $bodies[0],
+ permission_type => 'report_inspect',
+ });
$mech->log_in_ok('inspector@example.org');
$mech->get_ok('/');
- $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR' } },
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"submit location" );
$mech->follow_link_ok(
{ text_regex => qr/skip this step/i, },
@@ -1766,6 +1920,7 @@ subtest "inspectors get redirected directly to the report page" => sub {
may_show_name => '1',
phone => '07903 123 456',
category => 'Trees',
+ non_public => $test->{non_public},
}
},
"submit good details"
@@ -1773,6 +1928,7 @@ subtest "inspectors get redirected directly to the report page" => sub {
like $mech->uri->path, qr/\/report\/[0-9]+/, 'Redirects directly to report';
}
-};
+ };
+}
done_testing();
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index 0224e7e47..17b489447 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -1,5 +1,6 @@
use FixMyStreet::TestMech;
use FixMyStreet::App;
+use Test::LongString;
use Web::Scraper;
# disable info logs for this test run
@@ -39,32 +40,57 @@ my $contact2 = $mech->create_contact_ok(
category => 'Graffiti Removal',
email => '101',
);
+$mech->create_contact_ok(
+ body_id => $body->id, # Edinburgh
+ category => 'Ball lighting',
+ email => '102',
+ extra => { _fields => [
+ { description => 'Size', code => 'size', required => 'True', automated => '' },
+ { description => 'Speed', code => 'speed', required => 'True', automated => 'server_set' },
+ { description => 'Colour', code => 'colour', required => 'True', automated => 'hidden_field' },
+ ] },
+);
+
+my $body2 = $mech->create_body_ok(2651, 'Edinburgh Council');
+my $contact4 = $mech->create_contact_ok(
+ body_id => $body2->id, # Edinburgh
+ category => 'Pothole',
+ email => '103',
+ extra => { _fields => [
+ { description => 'USRN', code => 'usrn', required => 'true', automated => 'hidden_field', variable => 'true', order => '1' },
+ { description => 'Asset ID', code => 'central_asset_id', required => 'true', automated => 'hidden_field', variable => 'true', order => '2' },
+ ] },
+);
# test that the various bit of form get filled in and errors correctly
# generated.
+my $empty_form = {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => '',
+ may_show_name => '1',
+ username => '',
+ email => '',
+ phone => '',
+ category => '',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+};
foreach my $test (
{
msg => 'all fields empty',
pc => 'EH99 1SP',
fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => '',
- may_show_name => '1',
- username => '',
- email => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- remember_me => undef,
+ %$empty_form,
+ category => 'Street lighting',
},
changes => {
number => '',
- type => 'old',
+ type => '',
},
errors => [
'This information is required',
@@ -80,6 +106,7 @@ foreach my $test (
username => 'testopen311@example.com',
category => 'Street lighting',
number => 27,
+ type => 'old',
},
extra => [
{
@@ -94,6 +121,45 @@ foreach my $test (
}
]
},
+ {
+ msg => 'automated things',
+ pc => 'EH99 1SP',
+ fields => {
+ %$empty_form,
+ category => 'Ball lighting',
+ },
+ changes => {
+ size => '',
+ },
+ hidden => [ 'colour' ],
+ errors => [
+ 'This information is required',
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ submit_with => {
+ title => 'test',
+ detail => 'test detail',
+ name => 'Test User',
+ username => 'testopen311@example.com',
+ size => 'big',
+ colour => 'red',
+ },
+ extra => [
+ {
+ name => 'size',
+ value => 'big',
+ description => 'Size',
+ },
+ {
+ name => 'colour',
+ value => 'red',
+ description => 'Colour',
+ }
+ ]
+ },
)
{
subtest "check form errors where $test->{msg}" => sub {
@@ -139,6 +205,12 @@ foreach my $test (
};
is_deeply $mech->visible_form_values, $new_values,
"values correctly changed";
+ if ($test->{hidden}) {
+ my %hidden_fields = map { $_->name => 1 } grep { $_->type eq 'hidden' } ($mech->forms)[0]->inputs;
+ foreach (@{$test->{hidden}}) {
+ is $hidden_fields{$_}, 1;
+ }
+ }
if ( $test->{fields}->{category} eq 'Street lighting' ) {
my $result = scraper {
@@ -146,7 +218,7 @@ foreach my $test (
}
->scrape( $mech->response );
- is_deeply $result->{option}, [ qw/old modern/], 'displayed streetlight type select';
+ is_deeply $result->{option}, [ "", qw/old modern/], 'displayed streetlight type select';
}
$new_values = {
@@ -172,4 +244,38 @@ foreach my $test (
};
}
+subtest "Category extras omits description label when all fields are hidden" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579');
+ my $category_extra = $json->{category_extra};
+ contains_string($category_extra, "usrn");
+ contains_string($category_extra, "central_asset_id");
+ lacks_string($category_extra, "USRN", "Lacks 'USRN' label");
+ lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label");
+ lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text");
+ };
+};
+
+subtest "Category extras includes description label for user" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $contact4->push_extra_fields({ description => 'Size?', code => 'size', required => 'true', automated => '', variable => 'true', order => '3' });
+ $contact4->update;
+
+ my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579');
+ my $category_extra = $json->{category_extra};
+ contains_string($category_extra, "usrn");
+ contains_string($category_extra, "central_asset_id");
+ lacks_string($category_extra, "USRN", "Lacks 'USRN' label");
+ lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label");
+ contains_string($category_extra, "Size?");
+ contains_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Contains description text");
+ };
+};
+
done_testing();
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index aefe77e47..aba7340b0 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -146,6 +146,42 @@ subtest "unconfirmed updates not displayed" => sub {
};
subtest "several updates shown in correct order" => sub {
+ my @qs;
+ for my $fields ( { # One with an associated update below
+ problem_id => $report_id,
+ whensent => '2011-03-10 12:23:16',
+ whenanswered => '2011-03-10 12:23:16',
+ old_state => 'confirmed',
+ new_state => 'confirmed',
+ },
+ { # One with no associated update
+ problem_id => $report_id,
+ whensent => '2011-03-11 12:23:16',
+ whenanswered => '2011-03-11 12:23:16',
+ old_state => 'confirmed',
+ new_state => 'confirmed',
+ },
+ { # One with no associated update, different state (doesn't match problem state, never mind)
+ problem_id => $report_id,
+ whensent => '2011-03-12 12:23:16',
+ whenanswered => '2011-03-12 12:23:16',
+ old_state => 'investigating',
+ new_state => 'investigating',
+ },
+ { # One for the fixed update
+ problem_id => $report_id,
+ whensent => '2011-03-15 08:12:36',
+ whenanswered => '2011-03-15 08:12:36',
+ old_state => 'confirmed',
+ new_state => 'fixed - user',
+ },
+ ) {
+ my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_create(
+ $fields
+ );
+ push @qs, $q;
+ }
+
for my $fields ( {
problem_id => $report_id,
user_id => $user2->id,
@@ -180,16 +216,27 @@ subtest "several updates shown in correct order" => sub {
my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create(
$fields
);
+ if ($fields->{text} eq 'Second update') {
+ $comment->set_extra_metadata(questionnaire_id => $qs[0]->id);
+ $comment->update;
+ }
+ if ($fields->{text} eq 'Third update') {
+ $comment->set_extra_metadata(questionnaire_id => $qs[3]->id);
+ $comment->update;
+ }
}
$mech->get_ok("/report/$report_id");
my $meta = $mech->extract_update_metas;
- is scalar @$meta, 4, 'number of updates';
+ is scalar @$meta, 6, 'number of updates';
is $meta->[0], 'Posted by Other User at 12:23, Thu 10 March 2011', 'first update';
- is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011', 'second update';
- is $meta->[2], 'State changed to: Fixed', 'third update, part 1';
- is $meta->[3], 'Posted anonymously at 08:12, Tue 15 March 2011', 'third update, part 2';
+ is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011 Still open, via questionnaire', 'second update';
+ is $meta->[2], 'Still open, via questionnaire, 12:23, Fri 11 March 2011', 'questionnaire';
+ is $meta->[3], 'Still open, via questionnaire, 12:23, Sat 12 March 2011', 'questionnaire';
+ is $meta->[4], 'State changed to: Fixed', 'third update, part 1';
+ is $meta->[5], 'Posted anonymously at 08:12, Tue 15 March 2011', 'third update, part 2';
+ $report->questionnaires->delete;
};
for my $test (
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index 76c920562..8cdfddd1b 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -95,6 +95,9 @@ $fife_problems[10]->update( {
state => 'hidden',
});
+# Run the cron script old-data (for the table no longer used by default)
+FixMyStreet::Script::UpdateAllReports::generate(1);
+
# Run the cron script that makes the data for /reports so we don't get an error.
my $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard();