diff options
Diffstat (limited to 't/app/controller/moderate.t')
-rw-r--r-- | t/app/controller/moderate.t | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t index 7ef24bbe8..8e84bd392 100644 --- a/t/app/controller/moderate.t +++ b/t/app/controller/moderate.t @@ -12,9 +12,9 @@ sub moderate_permission_title { 0 } package main; +use Path::Tiny; +use File::Temp 'tempdir'; use FixMyStreet::TestMech; -use FixMyStreet::App; -use Data::Dumper; my $mech = FixMyStreet::TestMech->new; $mech->host('www.example.org'); @@ -29,7 +29,7 @@ my $user = $mech->create_user_ok('test-moderation@example.com', name => 'Test Us my $user2 = $mech->create_user_ok('test-moderation2@example.com', name => 'Test User 2'); sub create_report { - FixMyStreet::App->model('DB::Problem')->create( + FixMyStreet::DB->resultset('Problem')->create( { postcode => 'BR1 3SB', bodies_str => $body->id, @@ -174,23 +174,42 @@ subtest 'Problem moderation' => sub { }; subtest 'Hide photo' => sub { - $mech->content_contains('Photo of this report'); + my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); - $mech->submit_form_ok({ with_fields => { - %problem_prepopulated, - problem_photo => 0, - }}); - $mech->base_like( qr{\Q$REPORT_URL\E} ); + FixMyStreet::override_config { + PHOTO_STORAGE_BACKEND => 'FileSystem', + PHOTO_STORAGE_OPTIONS => { + UPLOAD_DIR => $UPLOAD_DIR, + }, + }, sub { + my $image_path = path('t/app/controller/sample.jpg'); + $image_path->copy( path($UPLOAD_DIR, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg') ); - $mech->content_lacks('Photo of this report'); + $mech->get_ok('/photo/' . $report->id . '.0.jpeg'); - $mech->submit_form_ok({ with_fields => { - %problem_prepopulated, - problem_photo => 1, - }}); - $mech->base_like( qr{\Q$REPORT_URL\E} ); + $mech->get_ok($REPORT_URL); + $mech->content_contains('Photo of this report'); - $mech->content_contains('Photo of this report'); + $mech->submit_form_ok({ with_fields => { + %problem_prepopulated, + problem_photo => 0, + }}); + $mech->base_like( qr{\Q$REPORT_URL\E} ); + + my $res = $mech->get('/photo/' . $report->id . '.0.jpeg'); + is $res->code, 404, 'got 404'; + + $mech->get_ok($REPORT_URL); + $mech->content_lacks('Photo of this report'); + + $mech->submit_form_ok({ with_fields => { + %problem_prepopulated, + problem_photo => 1, + }}); + $mech->base_like( qr{\Q$REPORT_URL\E} ); + + $mech->content_contains('Photo of this report'); + }; }; subtest 'Hide report' => sub { @@ -206,7 +225,7 @@ subtest 'Problem moderation' => sub { is $report->state, 'hidden', 'Is hidden'; my $email = $mech->get_email; - is $email->header('To'), '"Test User 2" <test-moderation2@example.com>', 'Sent to correct email'; + is $email->header('To'), '"Test User 2" <' . $user2->email . '>', 'Sent to correct email'; my $url = $mech->get_link_from_email($email); ok $url, "extracted complain url '$url'"; @@ -477,8 +496,6 @@ subtest 'updates' => sub { }}); $mech->content_lacks('update good good bad good'); }; - - $update->moderation_original_data->delete; }; my $update2 = create_update(); @@ -517,4 +534,14 @@ subtest 'And do it as a superuser' => sub { subtest 'Check moderation history in admin' => sub { $mech->get_ok('/admin/report_edit/' . $report->id); }; + +subtest 'Check moderation in user log' => sub { + $mech->get_ok('/admin/users/' . $user->id . '/log'); + my $report_id = $report->id; + $mech->content_like(qr/Moderated report.*?$report_id/); + my $update_id = $update->id; + $mech->content_like(qr/Moderated update.*?$update_id/); +}; + + done_testing(); |