aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller')
-rw-r--r--t/app/controller/admin/manifesttheme.t340
-rw-r--r--t/app/controller/admin/users.t11
-rw-r--r--t/app/controller/around.t3
-rw-r--r--t/app/controller/offline.t19
-rw-r--r--t/app/controller/report_new.t203
-rw-r--r--t/app/controller/report_new_staff.t257
6 files changed, 629 insertions, 204 deletions
diff --git a/t/app/controller/admin/manifesttheme.t b/t/app/controller/admin/manifesttheme.t
new file mode 100644
index 000000000..c1b2d4542
--- /dev/null
+++ b/t/app/controller/admin/manifesttheme.t
@@ -0,0 +1,340 @@
+use Path::Tiny;
+use FixMyStreet::DB;
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
+
+$mech->log_in_ok( $superuser->email );
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'lincolnshire', 'tfl', 'fixmystreet' ],
+}, sub {
+
+ok $mech->host('lincolnshire.fixmystreet.com');
+
+subtest "theme link on cobrand admin goes to create form if no theme exists" => sub {
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "no themes yet" );
+
+ $mech->get_ok("/admin");
+ $mech->follow_link_ok({ text => "Manifest Theme" });
+
+ is $mech->res->previous->code, 302, "got 302 for redirect";
+ is $mech->res->previous->base->path, "/admin/manifesttheme", "redirected from index";
+ is $mech->uri->path, '/admin/manifesttheme/create', "redirected to create page";
+};
+
+subtest "name and short_name are required fields" => sub {
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "no themes yet" );
+
+ $mech->get_ok("/admin/manifesttheme/create");
+ $mech->content_lacks("Delete theme");
+
+ $mech->submit_form_ok({});
+ is $mech->uri->path, '/admin/manifesttheme/create', "stayed on create page";
+ $mech->content_contains("field is required");
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "theme not created" );
+
+ $mech->get_ok("/admin/manifesttheme/create");
+ $mech->submit_form_ok({ with_fields => { short_name => "Lincs FMS" } });
+ is $mech->uri->path, '/admin/manifesttheme/create', "stayed on create page";
+ $mech->content_contains("field is required", "name is required");
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "theme not created" );
+
+ $mech->get_ok("/admin/manifesttheme/create");
+ $mech->submit_form_ok({ with_fields => { name => "Lincolnshire FixMyStreet" } });
+ is $mech->uri->path, '/admin/manifesttheme/create', "stayed on create page";
+ $mech->content_contains("field is required", "short_name is required");
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "theme not created" );
+};
+
+subtest "cobrand admin lets you create a new theme" => sub {
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "no themes yet" );
+
+ $mech->get_ok("/admin/manifesttheme/create");
+ $mech->content_lacks("Delete theme");
+
+ my $fields = {
+ name => "Lincolnshire FixMyStreet",
+ short_name => "Lincs FMS",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/manifesttheme/lincolnshire', "redirected to edit page";
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 1, "theme was created" );
+
+ my $theme = FixMyStreet::DB->resultset('ManifestTheme')->find({ cobrand => 'lincolnshire' });
+ is $theme->name, "Lincolnshire FixMyStreet";
+ is $theme->short_name, "Lincs FMS";
+ is $theme->background_colour, undef;
+
+ my $log = $superuser->admin_logs->search({}, { order_by => { -desc => 'id' } })->first;
+ is $log->object_id, $theme->id;
+ is $log->action, "add";
+ is $log->object_summary, "lincolnshire";
+ is $log->link, "/admin/manifesttheme/lincolnshire";
+};
+
+subtest "cobrand admin lets you update an existing theme" => sub {
+ $mech->get_ok("/admin/manifesttheme/lincolnshire");
+
+ my $fields = {
+ background_colour => "#663399",
+ theme_colour => "rgb(102, 51, 153)",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+
+ my $theme = FixMyStreet::DB->resultset('ManifestTheme')->find({ cobrand => 'lincolnshire' });
+ is $theme->background_colour, "#663399";
+ is $theme->theme_colour, "rgb(102, 51, 153)";
+
+ my $log = $superuser->admin_logs->search({}, { order_by => { -desc => 'id' } })->first;
+ is $log->object_id, $theme->id;
+ is $log->action, "edit";
+};
+
+subtest "cobrand admin lets you add an icon to an existing theme" => sub {
+ $mech->get_ok("/admin/manifesttheme/lincolnshire");
+
+ my $sample_jpeg = path(__FILE__)->parent->parent->child("sample.jpg");
+ ok $sample_jpeg->exists, "sample image $sample_jpeg exists";
+ my $icon_filename = '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpg';
+
+ $mech->post( '/admin/manifesttheme/lincolnshire',
+ Content_Type => 'form-data',
+ Content => {
+ name => "Lincolnshire FixMyStreet",
+ short_name => "Lincs FMS",
+ background_colour => "#663399",
+ theme_colour => "rgb(102, 51, 153)",
+ cobrand => 'lincolnshire',
+ icon => [ $sample_jpeg, undef, Content_Type => 'image/jpeg' ],
+ },
+ );
+ ok $mech->success, 'Posted request successfully';
+
+ is $mech->uri->path, '/admin/manifesttheme/lincolnshire', "redirected back to edit page";
+ $mech->content_contains("<img src=\"/theme/lincolnshire/" . $icon_filename);
+ $mech->content_contains("<td class=\"icon-size\">133x100</td>");
+ my $icon_dest = path(FixMyStreet->path_to('web/theme/lincolnshire/', $icon_filename));
+ ok $icon_dest->exists, "Icon stored on disk";
+};
+
+subtest "cobrand admin lets you delete an icon from an existing theme" => sub {
+ my $icon_filename = '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpg';
+ my $icon_dest = path(FixMyStreet->path_to('web/theme/lincolnshire/', $icon_filename));
+ ok $icon_dest->exists, "Icon exists on disk";
+
+ $mech->get_ok("/admin/manifesttheme/lincolnshire");
+ my $fields = {
+ delete_icon => "/theme/lincolnshire/$icon_filename",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+
+ is $mech->uri->path, '/admin/manifesttheme/lincolnshire', "redirected back to edit page";
+ $mech->content_lacks("<img src=\"/theme/lincolnshire/" . $icon_filename);
+ $mech->content_lacks("<td class=\"icon-size\">133x100</td>");
+ ok !$icon_dest->exists, "Icon removed from disk";
+};
+
+subtest "cobrand admin rejects non-images" => sub {
+ $mech->get_ok("/admin/manifesttheme/lincolnshire");
+
+ my $sample_pdf = path(__FILE__)->parent->parent->child("sample.pdf");
+ ok $sample_pdf->exists, "sample image $sample_pdf exists";
+
+ $mech->post( '/admin/manifesttheme/lincolnshire',
+ Content_Type => 'form-data',
+ Content => {
+ name => "Lincolnshire FixMyStreet",
+ short_name => "Lincs FMS",
+ background_colour => "#663399",
+ theme_colour => "rgb(102, 51, 153)",
+ cobrand => 'lincolnshire',
+ icon => [ $sample_pdf, undef, Content_Type => 'application/pdf' ],
+ },
+ );
+ ok $mech->success, 'Posted request successfully';
+
+ is $mech->uri->path, '/admin/manifesttheme/lincolnshire', "redirected back to edit page";
+ $mech->content_lacks("90f7a64043fb458d58de1a0703a6355e2856b15e.pdf");
+ $mech->content_contains("File type not recognised. Please upload an image.");
+};
+
+subtest "theme link on cobrand admin goes to edit form when theme exists" => sub {
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 1, "theme exists" );
+
+ $mech->get_ok("/admin");
+ $mech->follow_link_ok({ text => "Manifest Theme" });
+
+ is $mech->res->previous->code, 302, "got 302 for redirect";
+ is $mech->res->previous->base->path, "/admin/manifesttheme", "redirected from index";
+ is $mech->uri->path, '/admin/manifesttheme/lincolnshire', "redirected to edit page";
+};
+
+subtest "create page on cobrand admin redirects to edit form when theme exists" => sub {
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 1, "theme exists" );
+
+ $mech->get_ok("/admin/manifesttheme/create");
+
+ is $mech->res->previous->code, 302, "got 302 for redirect";
+ is $mech->uri->path, '/admin/manifesttheme/lincolnshire', "redirected to edit page";
+};
+
+subtest "can delete theme" => sub {
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 1, "theme exists" );
+
+ my $theme_id = FixMyStreet::DB->resultset('ManifestTheme')->find({ cobrand => 'lincolnshire' })->id;
+
+ # Add an icon so we can test it gets deleted when the theme is deleted
+ my $sample_jpeg = path(__FILE__)->parent->parent->child("sample.jpg");
+ ok $sample_jpeg->exists, "sample image $sample_jpeg exists";
+ my $icon_filename = '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpg';
+
+ $mech->post( '/admin/manifesttheme/lincolnshire',
+ Content_Type => 'form-data',
+ Content => {
+ name => "Lincolnshire FixMyStreet",
+ short_name => "Lincs FMS",
+ background_colour => "#663399",
+ theme_colour => "rgb(102, 51, 153)",
+ cobrand => "lincolnshire",
+ icon => [ $sample_jpeg, undef, Content_Type => 'image/jpeg' ],
+ },
+ );
+ ok $mech->success, 'Posted request successfully';
+
+ is $mech->uri->path, '/admin/manifesttheme/lincolnshire', "redirected back to edit page";
+ my $icon_dest = path(FixMyStreet->path_to('web/theme/lincolnshire/', $icon_filename));
+ ok $icon_dest->exists, "Icon stored on disk";
+
+ $mech->submit_form_ok({ button => 'delete_theme' });
+ is $mech->uri->path, '/admin/manifesttheme/create', "redirected to create page";
+
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "theme deleted" );
+ ok !$icon_dest->exists, "Icon removed from disk";
+
+ my $log = $superuser->admin_logs->search({}, { order_by => { -desc => 'id' } })->first;
+ is $log->object_id, $theme_id;
+ is $log->action, "delete";
+};
+
+subtest "can't edit another cobrand's theme" => sub {
+ FixMyStreet::DB->resultset('ManifestTheme')->create({
+ cobrand => "tfl",
+ name => "Transport for London Street Care",
+ short_name => "TfL Street Care",
+ });
+
+ $mech->get("/admin/manifesttheme/tfl");
+ ok !$mech->res->is_success(), "want a bad response";
+ is $mech->res->code, 404, "got 404";
+};
+
+ok $mech->host('www.fixmystreet.com');
+
+subtest "fms cobrand lets you view all manifest themes" => sub {
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 1, "theme already exists" );
+
+ $mech->get_ok("/admin");
+ $mech->follow_link_ok({ text => "Manifest Theme" });
+
+ is $mech->uri->path, '/admin/manifesttheme', "taken to list page";
+
+ $mech->content_contains("Transport for London Street Care");
+ $mech->content_contains("TfL Street Care");
+
+};
+
+subtest "fms cobrand lets you edit a cobrand's manifest theme" => sub {
+ $mech->get_ok("/admin/manifesttheme");
+ $mech->follow_link_ok({ url => "manifesttheme/tfl" }) or diag $mech->content;
+
+ my $fields = {
+ name => "Transport for London Report It",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/manifesttheme', "redirected back to list page";
+
+ my $theme = FixMyStreet::DB->resultset('ManifestTheme')->find({ cobrand => 'tfl' });
+ is $theme->name, "Transport for London Report It";
+
+};
+
+subtest "fms cobrand lets you create a new manifest theme" => sub {
+ $mech->get_ok("/admin/manifesttheme");
+ $mech->follow_link_ok({ text => "Create" });
+
+ my $fields = {
+ name => "FixMyStreet Pro",
+ short_name => "FMS Pro",
+ cobrand => "fixmystreet",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/manifesttheme', "redirected to list page";
+
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 2, "theme added" );
+ my $theme = FixMyStreet::DB->resultset('ManifestTheme')->find({ cobrand => 'fixmystreet' });
+ is $theme->name, "FixMyStreet Pro";
+};
+
+subtest "fms cobrand prevents you creating a duplicate theme" => sub {
+ $mech->get_ok("/admin/manifesttheme");
+ $mech->follow_link_ok({ text => "Create" });
+
+ my $fields = {
+ name => "FixMyStreet Pro",
+ short_name => "FMS Pro",
+ cobrand => "fixmystreet",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/manifesttheme/create', "stayed on create form";
+
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 2, "theme not added" );
+};
+
+subtest "fms cobrand prevents creating a duplicate by editing" => sub {
+ $mech->get_ok("/admin/manifesttheme");
+ $mech->follow_link_ok({ url => "manifesttheme/tfl" });
+
+ my $fields = {
+ cobrand => "fixmystreet",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/manifesttheme/tfl', "stayed on edit page";
+};
+
+};
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixamingata' ],
+}, sub {
+
+ok $mech->host("www.fixamingata.se"), "change host to FixaMinGata";
+
+subtest "single cobrand behaves correctly" => sub {
+ FixMyStreet::DB->resultset('ManifestTheme')->delete_all;
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 0, "themes all deleted" );
+
+ $mech->get_ok("/admin/manifesttheme");
+ is $mech->uri->path, '/admin/manifesttheme/create', "redirected to create page";
+
+ my $fields = {
+ name => "FixaMinGata Theme Test",
+ short_name => "FixaMinGata Short Name",
+ cobrand => "fixamingata",
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/manifesttheme/fixamingata', "redirected to edit form page";
+ $mech->content_contains("FixaMinGata Theme Test");
+ $mech->content_contains("FixaMinGata Short Name");
+
+ is( FixMyStreet::DB->resultset('ManifestTheme')->count, 1, "theme added" );
+ my $theme = FixMyStreet::DB->resultset('ManifestTheme')->find({ cobrand => 'fixamingata' });
+ is $theme->name, "FixaMinGata Theme Test";
+};
+
+
+};
+
+done_testing();
diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t
index 2e3ad9e5a..a36a4187a 100644
--- a/t/app/controller/admin/users.t
+++ b/t/app/controller/admin/users.t
@@ -564,7 +564,10 @@ subtest "Send login email from admin for unverified email" => sub {
};
subtest "Anonymizing user from admin" => sub {
- $mech->create_problems_for_body(4, 2237, 'Title');
+ my ($problem) = $mech->create_problems_for_body(4, 2237, 'Title');
+ $mech->create_comment_for_problem($problem, $user, $user->name, 'An update', 'f', 'confirmed', 'confirmed');
+ $mech->create_comment_for_problem($problem, $user, $user->name, '2nd update', 't', 'confirmed', 'fixed - user');
+ $mech->create_comment_for_problem($problem, $user, $user->name, '3rd update', 'f', 'unconfirmed', 'confirmed');
my $count_p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count;
my $count_u = FixMyStreet::DB->resultset('Comment')->search({ user_id => $user->id })->count;
$mech->get_ok( '/admin/users/' . $user->id );
@@ -586,6 +589,12 @@ subtest "Hiding user's reports from admin" => sub {
is $c, $count_u;
};
+subtest "Hiding user with only unconfirmed updates does not error" => sub {
+ FixMyStreet::DB->resultset('Comment')->search({ user_id => $user->id, state => 'hidden' })->update({ state => 'unconfirmed' });
+ $mech->get_ok( '/admin/users/' . $user->id );
+ $mech->submit_form_ok({ button => 'hide_everywhere' });
+};
+
subtest "Logging user out" => sub {
my $mech2 = FixMyStreet::TestMech->new;
$mech2->log_in_ok($user->email);
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index bd2bf2cee..cd992270f 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -261,6 +261,9 @@ subtest 'check category, status and extra filtering works on /around' => sub {
$mech->get_ok( '/around?filter_category=Pothole&bbox=' . $bbox );
$mech->content_contains('<option value="Pothole" selected>');
$mech->content_contains('<optgroup label="Environment">');
+
+ $mech->get_ok( '/around?filter_group=Environment&bbox=' . $bbox );
+ $mech->content_contains('<option value="Flytipping" selected>');
};
$json = $mech->get_ok_json( '/around?ajax=1&filter_category=Pothole&bbox=' . $bbox );
diff --git a/t/app/controller/offline.t b/t/app/controller/offline.t
index d2a5009ec..876475264 100644
--- a/t/app/controller/offline.t
+++ b/t/app/controller/offline.t
@@ -1,5 +1,7 @@
use FixMyStreet::TestMech;
+use FixMyStreet::DB;
use Path::Tiny;
+use Memcached;
my $mech = FixMyStreet::TestMech->new;
@@ -11,6 +13,7 @@ FixMyStreet::override_config {
my $image_path = path('t/app/controller/sample.jpg');
$image_path->copy($theme_dir->child('sample.jpg'));
subtest 'manifest' => sub {
+ Memcached::delete("manifest_theme:test");
my $j = $mech->get_ok_json('/.well-known/manifest.webmanifest');
is $j->{name}, 'FixMyStreet', 'correct name';
is $j->{theme_color}, '#ffd000', 'correct theme colour';
@@ -20,6 +23,22 @@ FixMyStreet::override_config {
sizes => '133x100'
}, 'correct icon';
};
+ subtest 'themed manifest' => sub {
+ Memcached::delete("manifest_theme:test");
+ FixMyStreet::DB->resultset('ManifestTheme')->create({
+ cobrand => "test",
+ name => "My Test Cobrand FMS",
+ short_name => "Test FMS",
+ background_colour => "#ff00ff",
+ theme_colour => "#ffffff",
+ });
+
+ my $j = $mech->get_ok_json('/.well-known/manifest.webmanifest');
+ is $j->{name}, 'My Test Cobrand FMS', 'correctly overridden name';
+ is $j->{short_name}, 'Test FMS', 'correctly overridden short_name';
+ is $j->{background_color}, '#ff00ff', 'correctly overridden background colour';
+ is $j->{theme_color}, '#ffffff', 'correctly overridden theme colour';
+ };
$theme_dir->remove_tree;
};
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 1f5ad2b52..b85bae43a 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -2185,207 +2185,4 @@ subtest "extra google analytics code displayed on email confirmation problem cre
};
};
-
-my $private_perms = $mech->create_user_ok('private_perms@example.org', name => 'private', from_body => $bodies[0]);
-subtest "report_mark_private allows users to mark reports as private" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- BASE_URL => 'https://www.fixmystreet.com',
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->log_out_ok;
-
- $private_perms->user_body_permissions->find_or_create({
- body => $bodies[0],
- permission_type => 'report_mark_private',
- });
-
- $mech->log_in_ok('private_perms@example.org');
- $mech->get_ok('/');
- $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 => "Private report",
- detail => 'Private report details.',
- photo1 => '',
- name => 'Joe Bloggs',
- may_show_name => '1',
- phone => '07903 123 456',
- category => 'Trees',
- non_public => 1,
- }
- },
- "submit good details"
- );
-
- $mech->content_contains('Great work. Now spread the word', 'shown confirmation page');
- }
-};
-
-my $inspector = $mech->create_user_ok('inspector@example.org', name => 'inspector', from_body => $bodies[0]);
-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',
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->log_out_ok;
-
- $inspector->user_body_permissions->find_or_create({
- body => $bodies[0],
- permission_type => 'planned_reports',
- });
- $inspector->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 => '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 => "Inspector report",
- detail => 'Inspector report details.',
- photo1 => '',
- name => 'Joe Bloggs',
- may_show_name => '1',
- phone => '07903 123 456',
- category => 'Trees',
- non_public => $test->{non_public},
- }
- },
- "submit good details"
- );
-
- like $mech->uri->path, qr/\/report\/[0-9]+/, 'Redirects directly to report';
- }
- };
-}
-
-subtest "check map click ajax response for inspector" => sub {
- $mech->log_out_ok;
-
- my $extra_details;
- $inspector->user_body_permissions->find_or_create({
- body => $bodies[0],
- permission_type => 'planned_reports',
- });
- $inspector->user_body_permissions->find_or_create({
- body => $bodies[0],
- permission_type => 'report_inspect',
- });
-
- $mech->log_in_ok('inspector@example.org');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
- };
- like $extra_details->{category}, qr/data-prefill="0/, 'inspector prefill not set';
- ok !$extra_details->{contribute_as}, 'no contribute as section';
-};
-
-subtest "check map click ajax response for inspector and uk cobrand" => sub {
- $mech->log_out_ok;
-
- my $extra_details;
- $inspector->user_body_permissions->find_or_create({
- body => $bodies[4],
- permission_type => 'planned_reports',
- });
- $inspector->user_body_permissions->find_or_create({
- body => $bodies[4],
- permission_type => 'report_inspect',
- });
-
- $mech->log_in_ok('inspector@example.org');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { bromley => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.402096&longitude=0.015784' );
- };
- like $extra_details->{category}, qr/data-prefill="0/, 'inspector prefill not set';
-};
-
-for my $test (
- {
- desc => 'map click ajax for contribute_as_another_user',
- permissions => {
- contribute_as_another_user => 1,
- contribute_as_anonymous_user => undef,
- contribute_as_body => undef,
- }
- },
- {
- desc => 'map click ajax for contribute_as_anonymous_user',
- permissions => {
- contribute_as_another_user => undef,
- contribute_as_anonymous_user => 1,
- contribute_as_body => undef,
- }
- },
- {
- desc => 'map click ajax for contribute_as_body',
- permissions => {
- contribute_as_another_user => undef,
- contribute_as_anonymous_user => undef,
- contribute_as_body => 1,
- }
- },
-) {
- subtest $test->{desc} => sub {
- $mech->log_out_ok;
- my $extra_details;
- (my $name = $test->{desc}) =~ s/.*(contri.*)/$1/;
- my $user = $mech->create_user_ok("$name\@example.org", name => 'test user', from_body => $bodies[0]);
- for my $p ( keys %{$test->{permissions}} ) {
- next unless $test->{permissions}->{$p};
- $user->user_body_permissions->find_or_create({
- body => $bodies[0],
- permission_type => $p,
- });
- }
- $mech->log_in_ok("$name\@example.org");
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
- };
- for my $p ( keys %{$test->{permissions}} ) {
- (my $key = $p) =~ s/contribute_as_//;
- is $extra_details->{contribute_as}->{$key}, $test->{permissions}->{$p}, "$key correctly set";
- }
-
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.754926&longitude=-1.256179' );
- };
- ok !$extra_details->{contribute_as}, 'no contribute as section for other council';
- };
-}
-
done_testing();
diff --git a/t/app/controller/report_new_staff.t b/t/app/controller/report_new_staff.t
new file mode 100644
index 000000000..ee9dff9e4
--- /dev/null
+++ b/t/app/controller/report_new_staff.t
@@ -0,0 +1,257 @@
+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_ids;
+for my $body (
+ { area_id => 2651, name => 'City of Edinburgh Council' },
+ { area_id => 2482, name => 'Bromley Council' },
+ { area_id => 2237, name => 'Oxfordshire County 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{2651}, category => 'Street lighting', email => 'highways@example.com' );
+my $edin_trees = $mech->create_contact_ok( body_id => $body_ids{2651}, category => 'Trees', email => 'trees@example.com' );
+$mech->create_contact_ok( body_id => $body_ids{2482}, category => 'Trees', email => 'trees@example.com' );
+$mech->create_contact_ok( body_id => $body_ids{2237}, category => 'Trees', email => 'trees-2247@example.com' );
+
+my $private_perms = $mech->create_user_ok('private_perms@example.org', name => 'private', from_body => $body_ids{2651});
+subtest "report_mark_private allows users to mark reports as private" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ BASE_URL => 'https://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->log_out_ok;
+
+ $private_perms->user_body_permissions->find_or_create({
+ body_id => $body_ids{2651},
+ permission_type => 'report_mark_private',
+ });
+
+ $mech->log_in_ok('private_perms@example.org');
+ $mech->get_ok('/');
+ $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 => "Private report",
+ detail => 'Private report details.',
+ photo1 => '',
+ name => 'Joe Bloggs',
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => 'Trees',
+ non_public => 1,
+ }
+ },
+ "submit good details"
+ );
+
+ $mech->content_contains('Great work. Now spread the word', 'shown confirmation page');
+ }
+};
+
+my $inspector = $mech->create_user_ok('inspector@example.org', name => 'inspector', from_body => $body_ids{2651});
+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',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->log_out_ok;
+
+ $inspector->user_body_permissions->find_or_create({
+ body_id => $body_ids{2651},
+ permission_type => 'planned_reports',
+ });
+ $inspector->user_body_permissions->find_or_create({
+ body_id => $body_ids{2651},
+ permission_type => 'report_inspect',
+ });
+
+ $mech->log_in_ok('inspector@example.org');
+ $mech->get_ok('/');
+ $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 => "Inspector report",
+ detail => 'Inspector report details.',
+ photo1 => '',
+ name => 'Joe Bloggs',
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => 'Trees',
+ non_public => $test->{non_public},
+ }
+ },
+ "submit good details"
+ );
+
+ like $mech->uri->path, qr/\/report\/[0-9]+/, 'Redirects directly to report';
+ }
+ };
+}
+
+subtest "check map click ajax response for inspector" => sub {
+ $mech->log_out_ok;
+
+ my $extra_details;
+ $inspector->user_body_permissions->find_or_create({
+ body_id => $body_ids{2651},
+ permission_type => 'planned_reports',
+ });
+ $inspector->user_body_permissions->find_or_create({
+ body_id => $body_ids{2651},
+ permission_type => 'report_inspect',
+ });
+
+ $mech->log_in_ok('inspector@example.org');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
+ };
+ like $extra_details->{category}, qr/data-prefill="0/, 'inspector prefill not set';
+ ok !$extra_details->{contribute_as}, 'no contribute as section';
+};
+
+subtest "check map click ajax response for inspector and uk cobrand" => sub {
+ $mech->log_out_ok;
+
+ my $extra_details;
+ $inspector->user_body_permissions->find_or_create({
+ body_id => $body_ids{2482},
+ permission_type => 'planned_reports',
+ });
+ $inspector->user_body_permissions->find_or_create({
+ body_id => $body_ids{2482},
+ permission_type => 'report_inspect',
+ });
+
+ $mech->log_in_ok('inspector@example.org');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'bromley',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.402096&longitude=0.015784' );
+ };
+ like $extra_details->{category}, qr/data-prefill="0/, 'inspector prefill not set';
+};
+
+for my $test (
+ {
+ desc => 'map click ajax for contribute_as_another_user',
+ permissions => {
+ contribute_as_another_user => 1,
+ contribute_as_anonymous_user => undef,
+ contribute_as_body => undef,
+ }
+ },
+ {
+ desc => 'map click ajax for contribute_as_anonymous_user',
+ permissions => {
+ contribute_as_another_user => undef,
+ contribute_as_anonymous_user => 1,
+ contribute_as_body => undef,
+ }
+ },
+ {
+ desc => 'map click ajax for contribute_as_body',
+ permissions => {
+ contribute_as_another_user => undef,
+ contribute_as_anonymous_user => undef,
+ contribute_as_body => 1,
+ }
+ },
+) {
+ subtest $test->{desc} => sub {
+ $mech->log_out_ok;
+ my $extra_details;
+ (my $name = $test->{desc}) =~ s/.*(contri.*)/$1/;
+ my $user = $mech->create_user_ok("$name\@example.org", name => 'test user', from_body => $body_ids{2651});
+ for my $p ( keys %{$test->{permissions}} ) {
+ next unless $test->{permissions}->{$p};
+ $user->user_body_permissions->find_or_create({
+ body_id => $body_ids{2651},
+ permission_type => $p,
+ });
+ }
+ $mech->log_in_ok("$name\@example.org");
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
+ };
+ for my $p ( keys %{$test->{permissions}} ) {
+ (my $key = $p) =~ s/contribute_as_//;
+ is $extra_details->{contribute_as}->{$key}, $test->{permissions}->{$p}, "$key correctly set";
+ }
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.754926&longitude=-1.256179' );
+ };
+ ok !$extra_details->{contribute_as}, 'no contribute as section for other council';
+ };
+}
+
+subtest 'staff-only categories when reporting' => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ MAPIT_TYPES => ['UTA'],
+ }, sub {
+ $inspector->update({ is_superuser => 1 });
+ $mech->log_in_ok('inspector@example.org');
+
+ $mech->get_ok('/admin/body/' . $body_ids{2651} . '/Trees');
+ $mech->submit_form_ok({ with_fields => { state => 'staff' } }, 'mark Trees as staff-only');
+ $edin_trees->discard_changes;
+ is $edin_trees->state, 'staff', 'category is staff only';
+
+ my $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
+ is_deeply [ sort keys %{$extra_details->{by_category}} ], [ 'Street lighting', 'Trees' ], 'Superuser can see staff-only category';
+
+ $inspector->update({ is_superuser => 0 });
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
+ is_deeply [ sort keys %{$extra_details->{by_category}} ], [ 'Street lighting', 'Trees' ], 'Body staff user can see staff-only category';
+
+ $inspector->update({ from_body => $body_ids{2482} });
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
+ is_deeply [ sort keys %{$extra_details->{by_category}} ], [ 'Street lighting' ], 'Different body staff user cannot see staff-only category';
+
+ $mech->log_out_ok;
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' );
+ is_deeply [ sort keys %{$extra_details->{by_category}} ], [ 'Street lighting' ], 'Normal user cannot see staff-only category';
+ };
+};
+
+done_testing;