aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/moderate.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/moderate.t')
-rw-r--r--t/app/controller/moderate.t217
1 files changed, 181 insertions, 36 deletions
diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t
index 4b2f0cfe3..7ef24bbe8 100644
--- a/t/app/controller/moderate.t
+++ b/t/app/controller/moderate.t
@@ -4,6 +4,12 @@ use parent 'FixMyStreet::Cobrand::Default';
sub send_moderation_notifications { 0 }
+package FixMyStreet::Cobrand::TestTitle;
+
+use parent 'FixMyStreet::Cobrand::Default';
+
+sub moderate_permission_title { 0 }
+
package main;
use FixMyStreet::TestMech;
@@ -15,6 +21,7 @@ $mech->host('www.example.org');
my $BROMLEY_ID = 2482;
my $body = $mech->create_body_ok( $BROMLEY_ID, 'Bromley Council' );
+$mech->create_contact_ok( body => $body, category => 'Lost toys', email => 'losttoys@example.net' );
my $dt = DateTime->now;
@@ -43,11 +50,11 @@ sub create_report {
latitude => '51.4129',
longitude => '0.007831',
user_id => $user2->id,
- photo => $mech->get_photo_data,
+ photo => '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg',
+ extra => { moon => 'waxing full' },
});
}
my $report = create_report();
-my $report2 = create_report();
my $REPORT_URL = '/report/' . $report->id ;
@@ -57,6 +64,9 @@ subtest 'Auth' => sub {
$mech->get_ok($REPORT_URL);
$mech->content_lacks('Moderat');
+ $mech->get_ok("$REPORT_URL/moderate");
+ $mech->content_lacks('Moderat');
+
$mech->log_in_ok( $user->email );
$mech->get_ok($REPORT_URL);
@@ -86,7 +96,7 @@ subtest 'Auth' => sub {
my %problem_prepopulated = (
problem_show_name => 1,
- problem_show_photo => 1,
+ problem_photo => 1,
problem_title => 'Good bad good',
problem_detail => 'Good bad bad bad good bad',
);
@@ -95,6 +105,9 @@ subtest 'Problem moderation' => sub {
subtest 'Post modify title and text' => sub {
$mech->get_ok($REPORT_URL);
+ $mech->content_lacks('show-moderation');
+ $mech->follow_link_ok({ text_regex => qr/^Moderate$/ });
+ $mech->content_contains('show-moderation');
$mech->submit_form_ok({ with_fields => {
%problem_prepopulated,
problem_title => 'Good good',
@@ -119,6 +132,25 @@ subtest 'Problem moderation' => sub {
$report->discard_changes;
is $report->title, 'Good bad good';
is $report->detail, 'Good bad bad bad good bad';
+
+ my @history = $report->moderation_original_datas->search(undef, { order_by => 'id' })->all;
+ is @history, 2, 'Right number of entries';
+ is $history[0]->title, 'Good bad good', 'Correct original title';
+ is $history[1]->title, 'Good good', 'Correct second title';
+ };
+
+ subtest 'Post modified title after edited elsewhere' => sub {
+ $mech->submit_form_ok({ with_fields => {
+ %problem_prepopulated,
+ problem_title => 'Good good',
+ form_started => 1, # January 1970!
+ }});
+ $mech->base_like( qr{\Q/moderate$REPORT_URL\E} );
+ $mech->content_contains('Good bad good'); # Displayed title
+ $mech->content_contains('Good good'); # Form edit
+
+ $report->discard_changes;
+ is $report->title, 'Good bad good', 'title unchanged';
};
subtest 'Make anonymous' => sub {
@@ -146,7 +178,7 @@ subtest 'Problem moderation' => sub {
$mech->submit_form_ok({ with_fields => {
%problem_prepopulated,
- problem_show_photo => 0,
+ problem_photo => 0,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -154,7 +186,7 @@ subtest 'Problem moderation' => sub {
$mech->submit_form_ok({ with_fields => {
%problem_prepopulated,
- problem_show_photo => 1,
+ problem_photo => 1,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -208,34 +240,124 @@ subtest 'Problem moderation' => sub {
$report->update({ state => 'confirmed' });
}
};
+
+ subtest 'Try and moderate title when not allowed' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'testtitle'
+ }, sub {
+ $mech->get_ok($REPORT_URL);
+ $mech->submit_form_ok({ with_fields => {
+ problem_show_name => 1,
+ problem_photo => 1,
+ problem_detail => 'Changed detail',
+ }});
+ $mech->base_like( qr{\Q$REPORT_URL\E} );
+ $mech->content_like(qr/Moderated by Bromley Council/);
+
+ $report->discard_changes;
+ is $report->title, 'Good bad good';
+ is $report->detail, 'Changed detail';
+ }
+ };
+
+ subtest 'Moderate extra data' => sub {
+ my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/;
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
+ %problem_prepopulated,
+ 'extra.weather' => 'snow',
+ 'extra.moon' => 'waning full',
+ token => $csrf,
+ });
+ $report->discard_changes;
+ is $report->get_extra_metadata('weather'), 'snow';
+ is $report->get_extra_metadata('moon'), 'waning full';
+ my $mod = $report->moderation_original_data;
+ is $mod->get_extra_metadata('moon'), 'waxing full';
+ is $mod->get_extra_metadata('weather'), undef;
+
+ my $diff = $mod->extra_diff($report, 'moon');
+ is $diff, "wa<del style='background-color:#fcc'>x</del><ins style='background-color:#cfc'>n</ins>ing full", 'Correct diff';
+ };
+
+ subtest 'Moderate category' => sub {
+ $report->update;
+ my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/;
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
+ %problem_prepopulated,
+ 'category' => 'Lost toys',
+ token => $csrf,
+ });
+ $report->discard_changes;
+ is $report->category, 'Lost toys';
+ };
+
+ subtest 'Moderate state' => sub {
+ my $mods_count = $report->moderation_original_datas->count;
+ my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/;
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
+ %problem_prepopulated,
+ state => 'confirmed',
+ token => $csrf,
+ });
+ $report->discard_changes;
+ is $report->state, 'confirmed', 'state has not changed';
+ is $report->comments->count, 0, 'same state, no update';
+ is $report->moderation_original_datas->count, $mods_count, 'No moderation entry either';
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
+ %problem_prepopulated,
+ state => 'in progress',
+ token => $csrf,
+ });
+ $report->discard_changes;
+ is $report->state, 'in progress', 'state has changed';
+ is $report->comments->count, 1, 'a new update added';
+ $report->update({ state => 'confirmed' });
+ is $report->moderation_original_datas->count, $mods_count, 'No moderation entry, only state changed';
+ };
+
+ subtest 'Moderate location' => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'fixmystreet',
+ }, sub {
+ my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/;
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
+ %problem_prepopulated,
+ latitude => '53',
+ longitude => '0.01578',
+ token => $csrf,
+ });
+ $report->discard_changes;
+ is $report->latitude, 51.4129, 'No change when moved out of area';
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
+ %problem_prepopulated,
+ latitude => '51.4021',
+ longitude => '0.01578',
+ token => $csrf,
+ });
+ $report->discard_changes;
+ is $report->latitude, 51.4021, 'Updated when same body';
+ };
+ };
};
$mech->content_lacks('Posted anonymously', 'sanity check');
+my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/;
-subtest 'Problem 2' => sub {
- my $REPORT2_URL = '/report/' . $report2->id ;
- $mech->get_ok($REPORT2_URL);
- $mech->submit_form_ok({ with_fields => {
+subtest 'Edit photos' => sub {
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
%problem_prepopulated,
- problem_title => 'Good good',
- problem_detail => 'Good good improved',
- }});
- $mech->base_like( qr{\Q$REPORT2_URL\E} );
-
- $report2->discard_changes;
- is $report2->title, 'Good good';
- is $report2->detail, 'Good good improved';
-
- $mech->submit_form_ok({ with_fields => {
+ photo1 => 'something-wrong',
+ token => $csrf,
+ });
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id, {
%problem_prepopulated,
- problem_revert_title => 1,
- problem_revert_detail => 1,
- }});
- $mech->base_like( qr{\Q$REPORT2_URL\E} );
-
- $report2->discard_changes;
- is $report2->title, 'Good bad good';
- is $report2->detail, 'Good bad bad bad good bad';
+ photo1 => '',
+ upload_fileid => '',
+ token => $csrf,
+ });
+ $report->discard_changes;
+ is $report->photo, undef;
};
sub create_update {
@@ -243,16 +365,17 @@ sub create_update {
user => $user2,
name => 'Test User 2',
anonymous => 'f',
- photo => $mech->get_photo_data,
+ photo => '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg',
text => 'update good good bad good',
state => 'confirmed',
mark_fixed => 0,
+ confirmed => $dt,
});
}
my %update_prepopulated = (
update_show_name => 1,
- update_show_photo => 1,
- update_detail => 'update good good bad good',
+ update_photo => 1,
+ update_text => 'update good good bad good',
);
my $update = create_update();
@@ -261,9 +384,12 @@ subtest 'updates' => sub {
subtest 'Update modify text' => sub {
$mech->get_ok($REPORT_URL);
+ $mech->content_lacks('show-moderation');
+ $mech->follow_link_ok({ text_regex => qr/^Moderate this update$/ });
+ $mech->content_contains('show-moderation');
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_detail => 'update good good good',
+ update_text => 'update good good good',
}}) or die $mech->content;
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -274,12 +400,11 @@ subtest 'updates' => sub {
subtest 'Revert text' => sub {
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_revert_detail => 1,
+ update_revert_text => 1,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
$update->discard_changes;
- $update->discard_changes;
is $update->text, 'update good good bad good',
};
@@ -304,6 +429,20 @@ subtest 'updates' => sub {
$mech->content_lacks('Posted anonymously');
};
+ subtest 'Moderate extra data' => sub {
+ $update->set_extra_metadata('moon', 'waxing full');
+ $update->update;
+ my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/;
+ $mech->post_ok('http://www.example.org/moderate/report/' . $report->id . '/update/' . $update->id, {
+ %update_prepopulated,
+ 'extra.weather' => 'snow',
+ 'extra.moon' => 'waxing full',
+ token => $csrf,
+ });
+ $update->discard_changes;
+ is $update->get_extra_metadata('weather'), 'snow';
+ };
+
subtest 'Hide photo' => sub {
$report->update({ photo => undef }); # hide the main photo so we can just look for text in comment
@@ -314,7 +453,7 @@ subtest 'updates' => sub {
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_show_photo => 0,
+ update_photo => 0,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -322,7 +461,7 @@ subtest 'updates' => sub {
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_show_photo => 1,
+ update_photo => 1,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -348,7 +487,7 @@ subtest 'Update 2' => sub {
$mech->get_ok($REPORT_URL);
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_detail => 'update good good good',
+ update_text => 'update good good good',
}}) or die $mech->content;
$update2->discard_changes;
@@ -359,6 +498,9 @@ subtest 'Now stop being a staff user' => sub {
$user->update({ from_body => undef });
$mech->get_ok($REPORT_URL);
$mech->content_contains('Moderated by Bromley Council');
+
+ $mech->get_ok("$REPORT_URL/moderate/" . $update->id);
+ $mech->content_lacks('Moderate this update');
};
subtest 'And do it as a superuser' => sub {
@@ -372,4 +514,7 @@ subtest 'And do it as a superuser' => sub {
$mech->content_contains('Moderated by an administrator');
};
+subtest 'Check moderation history in admin' => sub {
+ $mech->get_ok('/admin/report_edit/' . $report->id);
+};
done_testing();