diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/my.t | 51 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 6 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 20 |
3 files changed, 62 insertions, 15 deletions
diff --git a/t/app/controller/my.t b/t/app/controller/my.t index 8803e7877..47539ba55 100644 --- a/t/app/controller/my.t +++ b/t/app/controller/my.t @@ -4,9 +4,14 @@ my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/my'); is $mech->uri->path, '/auth', "got sent to the sign in page"; -$mech->create_problems_for_body(1, 1234, 'Test Title'); +$mech->get_ok('/my/anonymize'); +is $mech->uri->path, '/auth', "got sent to the sign in page"; + +my @problems = $mech->create_problems_for_body(3, 1234, 'Test Title'); +$problems[1]->update({anonymous => 1}); + my $other_user = FixMyStreet::DB->resultset('User')->find_or_create({ email => 'another@example.com' }); -$mech->create_problems_for_body(1, 1234, 'Another Title', { user => $other_user }); +my @other = $mech->create_problems_for_body(1, 1234, 'Another Title', { user => $other_user }); my $user = $mech->log_in_ok( 'test@example.com' ); $mech->get_ok('/my'); @@ -15,6 +20,48 @@ is $mech->uri->path, '/my', "stayed on '/my' page"; $mech->content_contains('Test Title'); $mech->content_lacks('Another Title'); +my @update; +my $i = 0; +foreach ($user, $user, $other_user) { + $update[$i] = FixMyStreet::App->model('DB::Comment')->create({ + text => 'this is an update', + user => $_, + state => 'confirmed', + problem => $problems[0], + mark_fixed => 0, + confirmed => \'current_timestamp', + anonymous => $i % 2, + }); + $i++; +} + +foreach ( + { type => 'problem', id => 0, result => 404, desc => 'nothing' }, + { type => 'problem', obj => $problems[0], result => 200, desc => 'own report' }, + { type => 'problem', obj => $problems[1], result => 400, desc => 'already anon report' }, + { type => 'problem', obj => $other[0], result => 400, desc => 'other user report' }, + { type => 'update', id => -1, result => 400, desc => 'non-existent update' }, + { type => 'update', obj => $update[0], result => 200, desc => 'own update' }, + { type => 'update', obj => $update[1], result => 400, desc => 'already anon update' }, + { type => 'update', obj => $update[2], result => 400, desc => 'other user update' }, +) { + my $id = $_->{id} // $_->{obj}->id; + $mech->get("/my/anonymize?$_->{type}=$id"); + is $mech->res->code, $_->{result}, "Got $_->{result} fetching $_->{desc}"; + if ($_->{result} == 200) { + $mech->submit_form_ok( { button => 'hide' }, 'Submit button to hide name' ); + $_->{obj}->discard_changes; + is $_->{obj}->anonymous, 1, 'Object now made anonymous'; + $_->{obj}->update({anonymous => 0}); + } +} + +$mech->get("/my/anonymize?problem=" . $problems[0]->id); +$mech->submit_form_ok( { button => 'hide_everywhere' }, 'Submit button to hide name everywhere' ); +is $problems[0]->discard_changes->anonymous, 1, 'Problem from form made anonymous'; +is $problems[2]->discard_changes->anonymous, 1, 'Other user problem made anonymous'; +is $update[0]->discard_changes->anonymous, 1, 'User update made anonymous'; + done_testing(); END { diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 81b0ffb86..5993a6304 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -547,14 +547,14 @@ subtest "check user details show when a user has correct permissions" => sub { $mech->log_in_ok( $oxfordshireuser->email ); ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; is $mech->extract_problem_meta, - 'Reported in the Roads category by Oxfordshire County Council (Council User) at 15:17, Tue 10 January 2012', + 'Reported in the Roads category by Oxfordshire County Council (Council User) at 15:17, Tue 10 January 2012 (Hide your name?)', 'correct problem meta information'; ok $oxfordshireuser->user_body_permissions->delete_all, "Remove view_body_contribute_details permissions"; ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; is $mech->extract_problem_meta, - 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012', + 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012 (Hide your name?)', 'correct problem meta information for user without relevant permissions'; $mech->log_out_ok; @@ -574,7 +574,7 @@ subtest "check brackets don't appear when username and report name are the same" $mech->log_in_ok( $oxfordshireuser->email ); ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; is $mech->extract_problem_meta, - 'Reported in the Roads category by Council User at 15:17, Tue 10 January 2012', + 'Reported in the Roads category by Council User at 15:17, Tue 10 January 2012 (Hide your name?)', 'correct problem meta information'; }; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 941989f24..2a20320bc 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -716,11 +716,11 @@ for my $test ( my $update_meta = $mech->extract_update_metas; my $meta_state = $test->{meta} || $test->{fields}->{state}; if ( $test->{reopened} ) { - like $update_meta->[0], qr/reopened$/, 'update meta says reopened'; + like $update_meta->[0], qr/reopened/, 'update meta says reopened'; } elsif ( $test->{state} eq 'duplicate' ) { - like $update_meta->[0], qr/closed as $meta_state$/, 'update meta includes state change'; + like $update_meta->[0], qr/closed as $meta_state/, 'update meta includes state change'; } else { - like $update_meta->[0], qr/marked as $meta_state$/, 'update meta includes state change'; + like $update_meta->[0], qr/marked as $meta_state/, 'update meta includes state change'; } if ($test->{view_username}) { @@ -755,24 +755,24 @@ subtest 'check meta correct for comments marked confirmed but not marked open' = $mech->get_ok( "/report/" . $report->id ); my $update_meta = $mech->extract_update_metas; - unlike $update_meta->[0], qr/reopened$/, + unlike $update_meta->[0], qr/reopened/, 'update meta does not say reopened'; $comment->update( { mark_open => 1, problem_state => undef } ); $mech->get_ok( "/report/" . $report->id ); $update_meta = $mech->extract_update_metas; - unlike $update_meta->[0], qr/marked as open$/, + unlike $update_meta->[0], qr/marked as open/, 'update meta does not says marked as open'; - like $update_meta->[0], qr/reopened$/, 'update meta does say reopened'; + like $update_meta->[0], qr/reopened/, 'update meta does say reopened'; $comment->update( { mark_open => 0, problem_state => undef } ); $mech->get_ok( "/report/" . $report->id ); $update_meta = $mech->extract_update_metas; - unlike $update_meta->[0], qr/marked as open$/, + unlike $update_meta->[0], qr/marked as open/, 'update meta does not says marked as open'; - unlike $update_meta->[0], qr/reopened$/, 'update meta does not say reopened'; + unlike $update_meta->[0], qr/reopened/, 'update meta does not say reopened'; }; subtest "check first comment with no status change has no status in meta" => sub { @@ -911,7 +911,7 @@ subtest 'check meta correct for second comment marking as reopened' => sub { $mech->get_ok( "/report/" . $report->id ); my $update_meta = $mech->extract_update_metas; - like $update_meta->[0], qr/fixed$/, 'update meta says fixed'; + like $update_meta->[0], qr/fixed/, 'update meta says fixed'; $comment = FixMyStreet::App->model('DB::Comment')->create( { @@ -929,7 +929,7 @@ subtest 'check meta correct for second comment marking as reopened' => sub { $mech->get_ok( "/report/" . $report->id ); $update_meta = $mech->extract_update_metas; - like $update_meta->[1], qr/reopened$/, 'update meta says reopened'; + like $update_meta->[1], qr/reopened/, 'update meta says reopened'; }; $user->from_body(undef); |