aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/admin/bodies.t
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
committerMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
commit09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch)
tree7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /t/app/controller/admin/bodies.t
parent585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff)
parentcea89fb87a96943708a1db0f646492fbfaaf000f (diff)
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 't/app/controller/admin/bodies.t')
-rw-r--r--t/app/controller/admin/bodies.t164
1 files changed, 163 insertions, 1 deletions
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index c73a90da1..811ac4362 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -1,3 +1,13 @@
+package FixMyStreet::Cobrand::AnonAllowedByCategory;
+use parent 'FixMyStreet::Cobrand::UKCouncils';
+sub council_url { 'anonbycategory' }
+sub council_name { 'Aberdeen City Council' }
+sub council_area { 'Aberdeen' }
+sub council_area_id { 2650 }
+sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } }
+
+package main;
+
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -5,6 +15,10 @@ 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 );
my $body = $mech->create_body_ok(2650, 'Aberdeen City Council');
+my $body2 = $mech->create_body_ok(2237, 'Oxfordshire County Council');
+
+my $user = $mech->create_user_ok('user@example.com', name => 'OCC User', from_body => $body2);
+$user->user_body_permissions->create({ body => $body2, permission_type => 'category_edit' });
# This override is wrapped around ALL the /admin/body tests
FixMyStreet::override_config {
@@ -101,11 +115,14 @@ subtest 'check contact renaming' => sub {
$mech->get('/admin/body/' . $body->id . '/test%20category');
is $mech->res->code, 404;
$mech->get_ok('/admin/body/' . $body->id . '/testing%20category');
+ $mech->content_contains('<td><strong>test2@example.com</strong></td>');
$report->discard_changes;
is $report->category, 'testing category';
$mech->submit_form_ok( { with_fields => { category => 'test category' } } );
};
+
+
subtest 'check contact updating' => sub {
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_like(qr{test2\@example.com</strong>[^<]*</td>[^<]*<td>unconfirmed}s);
@@ -210,6 +227,7 @@ subtest 'check open311 configuring' => sub {
subtest 'check open311 devolved editing' => sub {
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->content_contains("name=\"category\"\n size=\"30\" value=\"test category\"\n readonly>", 'Cannot edit Open311 category name');
$mech->submit_form_ok( { with_fields => {
send_method => 'Email',
email => 'testing@example.org',
@@ -217,11 +235,13 @@ subtest 'check open311 devolved editing' => sub {
} } );
$mech->content_contains('Values updated');
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->content_contains("name=\"category\"\n size=\"30\" value=\"test category\"\n required>", 'Can edit as now devolved');
$mech->submit_form_ok( { with_fields => {
send_method => '',
- email => 'open311-code',
+ email => 'open311 code',
note => 'Removing email send method',
} } );
+ $mech->content_contains('open311 code');
$mech->content_contains('Values updated');
};
@@ -261,8 +281,64 @@ subtest 'open311 protection editing' => sub {
is $contact->get_extra_metadata('open311_protect'), 1, 'Open311 protect flag set';
};
+subtest 'test assigned_users_only setting' => sub {
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->submit_form_ok( { with_fields => {
+ assigned_users_only => 1,
+ } } );
+ $mech->content_contains('Values updated');
+ my $contact = $body->contacts->find({ category => 'test category' });
+ is $contact->get_extra_metadata('assigned_users_only'), 1;
+};
+
+subtest 'updates disabling' => sub {
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->submit_form_ok( { with_fields => {
+ updates_disallowed => 1,
+ note => 'Disabling updates',
+ } } );
+ $mech->content_contains('Values updated');
+ my $contact = $body->contacts->find({ category => 'test category' });
+ is $contact->get_extra_metadata('updates_disallowed'), 1, 'Updates disallowed flag set';
+};
+
+subtest 'reopen disabling' => sub {
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->submit_form_ok( { with_fields => {
+ reopening_disallowed => 1,
+ note => 'Disabling reopening',
+ } } );
+ $mech->content_contains('Values updated');
+ my $contact = $body->contacts->find({ category => 'test category' });
+ is $contact->get_extra_metadata('reopening_disallowed'), 1, 'Reopening disallowed flag set';
+};
+
+subtest 'allow anonymous reporting' => sub {
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->content_lacks('Allow anonymous reports');
+};
}; # END of override wrap
+FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ MAPIT_TYPES => [ 'UTA' ],
+ BASE_URL => 'http://www.example.org',
+ ALLOWED_COBRANDS => [ "fixmystreet", "anonallowedbycategory" ],
+}, sub {
+
+subtest 'allow anonymous reporting' => sub {
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->submit_form_ok( { with_fields => {
+ anonymous_allowed => 1,
+ note => 'Anonymous Allowed',
+ } } );
+ $mech->content_contains('Values updated');
+ my $contact = $body->contacts->find({ category => 'test category' });
+ is $contact->get_extra_metadata('anonymous_allowed'), 1, 'Anonymous reports allowed flag set';
+};
+
+};
+
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
@@ -345,4 +421,90 @@ subtest 'check log of the above' => sub {
$mech->content_contains('Edited body <a href="/admin/body/' . $body->id . '">Aberdeen City Council</a>');
};
+subtest 'check update disallowed message' => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'bathnes',
+ COBRAND_FEATURES => { updates_allowed => { bathnes => 'open' } }
+ }, sub {
+ $mech->get_ok('/admin/body/' . $body->id .'/test%20category');
+ $mech->content_contains('even if this is unticked, only open reports can have updates left on them.');
+ };
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'bathnes',
+ COBRAND_FEATURES => { updates_allowed => { bathnes => 'staff' } }
+ }, sub {
+ $mech->get_ok('/admin/body/' . $body->id .'/test%20category');
+ $mech->content_contains('even if this is unticked, only staff will be able to leave updates.');
+ };
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'bathnes',
+ COBRAND_FEATURES => { updates_allowed => { bathnes => 'reporter' } }
+ }, sub {
+ $mech->get_ok('/admin/body/' . $body->id .'/test%20category');
+ $mech->content_contains('even if this is unticked, only the problem reporter will be able to leave updates');
+ };
+};
+
+subtest 'check hardcoded contact renaming' => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ 'ALLOWED_COBRANDS' => [ 'oxfordshire' ],
+ }, sub {
+ my $contact = FixMyStreet::DB->resultset('Contact')->create(
+ {
+ body_id => $body2->id,
+ category => 'protected category',
+ state => 'confirmed',
+ editor => $0,
+ whenedited => \'current_timestamp',
+ note => 'protected contact',
+ email => 'protected@example.org',
+ }
+ );
+ $contact->set_extra_metadata( 'hardcoded', 1 );
+ $contact->update;
+ $mech->get_ok('/admin/body/' . $body2->id .'/protected%20category');
+ $mech->content_contains( 'name="hardcoded"' );
+ $mech->content_like( qr'value="protected category"[^>]*readonly's );
+ $mech->submit_form_ok( { with_fields => { category => 'non protected category', note => 'rename category' } } );
+ $mech->content_contains( 'protected category' );
+ $mech->content_lacks( 'non protected category' );
+ $mech->get('/admin/body/' . $body2->id . '/non%20protected%20category');
+ is $mech->res->code, 404;
+
+ $mech->get_ok('/admin/body/' . $body2->id .'/protected%20category');
+ $mech->submit_form_ok( { with_fields => { hardcoded => 0, note => 'remove hardcoding' } } );
+ $mech->get_ok('/admin/body/' . $body2->id .'/protected%20category');
+ $mech->content_unlike( qr'value="protected category"[^>]*readonly's );
+ $mech->submit_form_ok( { with_fields => { category => 'non protected category', note => 'rename category' } } );
+ $mech->content_contains( 'non protected category' );
+ $mech->get_ok('/admin/body/' . $body2->id . '/non%20protected%20category');
+ $mech->get('/admin/body/' . $body2->id . '/protected%20category');
+ is $mech->res->code, 404;
+
+ $contact->discard_changes;
+ $contact->set_extra_metadata( 'hardcoded', 1 );
+ $contact->update;
+
+ $mech->log_out_ok( $superuser->email );
+ $mech->log_in_ok( $user->email );
+ $mech->get_ok('/admin/body/' . $body2->id . '/non%20protected%20category');
+ $mech->content_lacks( 'name="hardcoded"' );
+ $user->update( { is_superuser => 1 } );
+ $mech->get_ok('/admin/body/' . $body2->id . '/non%20protected%20category');
+ $mech->content_contains('name="hardcoded"' );
+ $user->update( { is_superuser => 0 } );
+ $mech->submit_form_ok( { with_fields => { hardcoded => 0, note => 'remove hardcoding' } } );
+ $mech->content_lacks( 'name="hardcoded"' );
+
+ $contact->discard_changes;
+ is $contact->get_extra_metadata('hardcoded'), 1, "non superuser can't remove hardcoding";
+
+ $mech->log_out_ok( $user->email );
+ };
+};
+
done_testing();