use strict; use warnings; use Test::More; use utf8; use FixMyStreet::TestMech; use FixMyStreet::App; use Data::Dumper; my $mech = FixMyStreet::TestMech->new; $mech->host('www.example.org'); my $BROMLEY_ID = 2482; my $body = $mech->create_body_ok( $BROMLEY_ID, 'Bromley Council' ); my $dt = DateTime->now; my $user = $mech->create_user_ok('test-moderation@example.com', name => 'Test User'); $user->user_body_permissions->delete_all; $user->discard_changes; my $user2 = $mech->create_user_ok('test-moderation2@example.com', name => 'Test User 2'); sub create_report { FixMyStreet::App->model('DB::Problem')->create( { postcode => 'BR1 3SB', bodies_str => $body->id, areas => ",$BROMLEY_ID,", category => 'Other', title => 'Good bad good', detail => 'Good bad bad bad good bad', used_map => 't', name => 'Test User 2', anonymous => 'f', state => 'confirmed', confirmed => $dt->ymd . ' ' . $dt->hms, lang => 'en-gb', service => '', cobrand => 'default', cobrand_data => '', send_questionnaire => 't', latitude => '51.4129', longitude => '0.007831', user_id => $user2->id, photo => $mech->get_photo_data, }); } my $report = create_report(); my $report2 = create_report(); my $REPORT_URL = '/report/' . $report->id ; subtest 'Auth' => sub { subtest 'Unaffiliated user cannot see moderation' => sub { $mech->get_ok($REPORT_URL); $mech->content_lacks('Moderat'); $mech->log_in_ok( $user->email ); $mech->get_ok($REPORT_URL); $mech->content_lacks('Moderat'); $user->update({ from_body => $body->id }); $mech->get_ok($REPORT_URL); $mech->content_lacks('Moderat'); $mech->get('/contact?m=1&id=' . $report->id); is $mech->res->code, 400; $mech->content_lacks('Good bad bad bad'); }; subtest 'Affiliated and permissioned user can see moderation' => sub { # login and from_body are done in previous test. $user->user_body_permissions->create({ body => $body, permission_type => 'moderate', }); $mech->get_ok($REPORT_URL); $mech->content_contains('Moderat'); }; }; my %problem_prepopulated = ( problem_show_name => 1, problem_show_photo => 1, problem_title => 'Good bad good', problem_detail => 'Good bad bad bad good bad', ); subtest 'Problem moderation' => sub { subtest 'Post modify title and text' => sub { $mech->get_ok($REPORT_URL); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_title => 'Good good', problem_detail => 'Good good improved', }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_like(qr/Moderated by Bromley Council/); $report->discard_changes; is $report->title, 'Good [...] good'; is $report->detail, 'Good [...] good [...]improved'; }; subtest 'Revert title and text' => sub { $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_revert_title => 1, problem_revert_detail => 1, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $report->discard_changes; is $report->title, 'Good bad good'; is $report->detail, 'Good bad bad bad good bad'; }; subtest 'Make anonymous' => sub { $mech->content_lacks('Reported anonymously'); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_show_name => 0, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_contains('Reported anonymously'); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_show_name => 1, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_lacks('Reported anonymously'); }; subtest 'Hide photo' => sub { $mech->content_contains('Photo of this report'); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_show_photo => 0, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_lacks('Photo of this report'); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_show_photo => 1, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_contains('Photo of this report'); }; subtest 'Hide report' => sub { $mech->clear_emails_ok; $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_hide => 1, }}); $mech->base_unlike( qr{/report/}, 'redirected to front page' ); $report->discard_changes; is $report->state, 'hidden', 'Is hidden'; my $email = $mech->get_email; is $email->header('To'), '"Test User 2" ', 'Sent to correct email'; my $url = $mech->get_link_from_email($email); ok $url, "extracted complain url '$url'";