diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/admin.t | 167 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 68 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 80 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 215 | ||||
-rw-r--r-- | t/app/model/alert_type.t | 144 | ||||
-rw-r--r-- | t/app/model/problem.t | 88 | ||||
-rw-r--r-- | t/app/model/questionnaire.t | 106 | ||||
-rw-r--r-- | t/map/tilma/original.t | 108 |
8 files changed, 972 insertions, 4 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index ba5095cea..dcf45e983 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -77,11 +77,13 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( ); subtest 'check summary counts' => sub { - my $problems = FixMyStreet::App->model('DB::Problem')->search( { state => { -in => [qw/confirmed fixed/] } } ); + my $problems = FixMyStreet::App->model('DB::Problem')->search( { state => { -in => [qw/confirmed fixed closed investigating planned/, 'in progress', 'fixed - user', 'fixed - council'] } } ); my $problem_count = $problems->count; $problems->update( { cobrand => '' } ); + FixMyStreet::App->model('DB::Problem')->search( { council => 2489 } )->update( { council => 1 } ); + my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_new( { problem => $report, }); $q->whensent( \'ms_current_timestamp()' ); $q->in_storage ? $q->update : $q->insert; @@ -130,6 +132,7 @@ subtest 'check summary counts' => sub { $alert->cobrand(''); $alert->update; + FixMyStreet::App->model('DB::Problem')->search( { council => 1 } )->update( { council => 2489 } ); ok $mech->host('fixmystreet.com'); }; @@ -636,6 +639,76 @@ for my $test ( }; } +for my $test ( + { + desc => 'user is problem owner', + problem_user => $user, + update_user => $user, + update_fixed => 0, + update_reopen => 0, + update_state => undef, + user_council => undef, + content => 'user is problem owner', + }, + { + desc => 'user is council user', + problem_user => $user, + update_user => $user2, + update_fixed => 0, + update_reopen => 0, + update_state => undef, + user_council => 2504, + content => 'user is from same council as problem - 2504', + }, + { + desc => 'update changed problem state', + problem_user => $user, + update_user => $user2, + update_fixed => 0, + update_reopen => 0, + update_state => 'planned', + user_council => 2504, + content => 'Update changed problem state to planned', + }, + { + desc => 'update marked problem as fixed', + problem_user => $user, + update_user => $user3, + update_fixed => 1, + update_reopen => 0, + update_state => undef, + user_council => undef, + content => 'Update marked problem as fixed', + }, + { + desc => 'update reopened problem', + problem_user => $user, + update_user => $user, + update_fixed => 0, + update_reopen => 1, + update_state => undef, + user_council => undef, + content => 'Update reopened problem', + }, +) { + subtest $test->{desc} => sub { + $report->user( $test->{problem_user} ); + $report->update; + + $update->user( $test->{update_user} ); + $update->problem_state( $test->{update_state} ); + $update->mark_fixed( $test->{update_fixed} ); + $update->mark_open( $test->{update_reopen} ); + $update->update; + + $test->{update_user}->from_council( $test->{user_council} ); + $test->{update_user}->update; + + $mech->get_ok('/admin/update_edit/' . $update->id ); + $mech->content_contains( $test->{content} ); + }; +} + subtest 'editing update email creates new user if required' => sub { my $user = FixMyStreet::App->model('DB::User')->find( { email => 'test4@example.com' } @@ -721,6 +794,98 @@ subtest 'report search' => sub { $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs ); }; +subtest 'user search' => sub { + $mech->get_ok('/admin/search_users'); + $mech->get_ok('/admin/search_users?search=' . $user->name); + + $mech->content_contains( $user->name); + my $u_id = $user->id; + $mech->content_like( qr{user_edit/$u_id">Edit</a>} ); + + $mech->get_ok('/admin/search_users?search=' . $user->email); + + $mech->content_like( qr{user_edit/$u_id">Edit</a>} ); + + $user->from_council(2509); + $user->update; + $mech->get_ok('/admin/search_users?search=2509' ); + $mech->content_contains(2509); +}; + +$log_entries = FixMyStreet::App->model('DB::AdminLog')->search( + { + object_type => 'user', + object_id => $user->id + }, + { + order_by => { -desc => 'id' }, + } +); + +is $log_entries->count, 0, 'no admin log entries'; + +for my $test ( + { + desc => 'edit user name', + fields => { + name => 'Test User', + email => 'test@example.com', + council => 2509, + }, + changes => { + name => 'Changed User', + }, + log_count => 1, + log_entries => [qw/edit/], + }, + { + desc => 'edit user email', + fields => { + name => 'Changed User', + email => 'test@example.com', + council => 2509, + }, + changes => { + email => 'changed@example.com', + }, + log_count => 2, + log_entries => [qw/edit edit/], + }, + { + desc => 'edit user council', + fields => { + name => 'Changed User', + email => 'changed@example.com', + council => 2509, + }, + changes => { + council => 2607, + }, + log_count => 3, + log_entries => [qw/edit edit edit/], + }, +) { + subtest $test->{desc} => sub { + $mech->get_ok( '/admin/user_edit/' . $user->id ); + + my $visible = $mech->visible_form_values; + is_deeply $visible, $test->{fields}, 'expected user'; + + my $expected = { + %{ $test->{fields} }, + %{ $test->{changes} } + }; + + $mech->submit_form_ok( { with_fields => $expected } ); + + $visible = $mech->visible_form_values; + is_deeply $visible, $expected, 'user updated'; + + $mech->content_contains( 'Updated!' ); + }; +} + + $mech->delete_user( $user ); $mech->delete_user( $user2 ); $mech->delete_user( $user3 ); diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index e56734bfc..af3b373ac 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -204,7 +204,12 @@ foreach my $test ( } my $result; - $result = 'fixed' if $test->{fields}{been_fixed} eq 'Yes'; + $result = 'fixed - user' + if $test->{fields}{been_fixed} eq 'Yes' + && $test->{problem_state} ne 'fixed'; + $result = 'fixed' + if $test->{fields}{been_fixed} eq 'Yes' + && $test->{problem_state} eq 'fixed'; $result = 'confirmed' if $test->{fields}{been_fixed} eq 'No'; $result = 'unknown' if $test->{fields}{been_fixed} eq 'Unknown'; @@ -214,7 +219,7 @@ foreach my $test ( # Check the right HTML page has been returned $mech->content_like( qr/<title>[^<]*Questionnaire/m ); $mech->content_contains( 'glad to hear it’s been fixed' ) - if $result eq 'fixed'; + if $result =~ /fixed/; $mech->content_contains( 'get some more information about the status of your problem' ) if $result eq 'unknown'; $mech->content_contains( "sorry to hear that" ) @@ -235,6 +240,16 @@ foreach my $test ( { problem_id => $report->id } ); is $c->text, $test->{fields}{update} || $test->{comment}; + if ( $result =~ /fixed/ ) { + ok $c->mark_fixed, 'comment marked as fixed'; + ok !$c->mark_open, 'comment not marked as open'; + } elsif ( $result eq 'confirmed' ) { + ok $c->mark_open, 'comment marked as open'; + ok !$c->mark_fixed, 'comment not marked as fixed'; + } elsif ( $result eq 'unknown' ) { + ok !$c->mark_open, 'comment not marked as open'; + ok !$c->mark_fixed, 'comment not marked as fixed'; + } } # Reset questionnaire for next test @@ -250,6 +265,55 @@ foreach my $test ( }; } + +for my $test ( + { + state => 'confirmed', + fixed => 0 + }, + { + state => 'planned', + fixed => 0 + }, + { + state => 'in progress', + fixed => 0 + }, + { + state => 'investigating', + fixed => 0 + }, + { + state => 'closed', + fixed => 0 + }, + { + state => 'fixed', + fixed => 1 + }, + { + state => 'fixed - council', + fixed => 1 + }, + { + state => 'fixed - user', + fixed => 1 + }, +) { + subtest "correct fixed text for state $test->{state}" => sub { + $report->state ( $test->{state} ); + $report->update; + + $mech->get_ok("/Q/" . $token->token); + $mech->title_like( qr/Questionnaire/ ); + if ( $test->{fixed} ) { + $mech->content_contains('An update marked this problem as fixed'); + } else { + $mech->content_lacks('An update marked this problem as fixed'); + } + }; +} + # EHA extra checking ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 1f857a387..23b76fbc4 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -235,6 +235,54 @@ for my $test ( banner_text => 'This problem has been fixed.', fixed => 1 }, + { + description => 'user fixed report', + date => DateTime->now, + state => 'fixed - user', + banner_id => 'fixed', + banner_text => 'This problem has been fixed.', + fixed => 1 + }, + { + description => 'council fixed report', + date => DateTime->now, + state => 'fixed - council', + banner_id => 'fixed', + banner_text => 'This problem has been fixed.', + fixed => 1 + }, + { + description => 'closed report', + date => DateTime->now, + state => 'closed', + banner_id => 'closed', + banner_text => 'This problem has been closed.', + fixed => 0 + }, + { + description => 'investigating report', + date => DateTime->now, + state => 'investigating', + banner_id => 'progress', + banner_text => 'This problem is in progress.', + fixed => 0 + }, + { + description => 'planned report', + date => DateTime->now, + state => 'planned', + banner_id => 'progress', + banner_text => 'This problem is in progress.', + fixed => 0 + }, + { + description => 'in progressreport', + date => DateTime->now, + state => 'in progress', + banner_id => 'progress', + banner_text => 'This problem is in progress.', + fixed => 0 + }, ) { subtest "banner for $test->{description}" => sub { $report->confirmed( $test->{date}->ymd . ' ' . $test->{date}->hms ); @@ -260,6 +308,38 @@ for my $test ( }; } +for my $test ( + { + desc => 'no state dropdown if user not from authority', + from_council => 0, + no_state => 1, + }, + { + desc => 'state dropdown if user from authority', + from_council => 2504, + no_state => 0, + }, + { + desc => 'no state dropdown if user not from same council as problem', + from_council => 2505, + no_state => 1, + }, +) { + subtest $test->{desc} => sub { + $mech->log_in_ok( $user->email ); + $user->from_council( $test->{from_council} ); + $user->update; + + $mech->get_ok("/report/$report_id"); + my $fields = $mech->visible_form_values( 'updateForm' ); + if ( $test->{no_state} ) { + ok !$fields->{state}; + } else { + ok $fields->{state}; + } + }; +} + # tidy up $mech->delete_user('test@example.com'); done_testing(); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 9a3cb3947..e8acbfd14 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -404,6 +404,184 @@ for my $test ( }; } +$report->state('confirmed'); +$report->update; + +subtest 'check non authority user cannot change set state' => sub { + $mech->log_in_ok( $user->email ); + $user->from_council( 0 ); + $user->update; + + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok( { + form_number => 2, + fields => { + submit_update => 1, + id => $report_id, + name => $user->name, + rznvy => $user->email, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'this is a forbidden update', + state => 'fixed - council', + }, + }, + 'submitted with state', + ); + + is $mech->uri->path, "/report/update", "at /report/update"; + + my $errors = $mech->page_errors; + is_deeply $errors, [ 'There was a problem with your update. Please try again.' ], 'error message'; + + is $report->state, 'confirmed', 'state unchanged'; +}; + +for my $state ( qw/unconfirmed hidden partial/ ) { + subtest "check that update cannot set state to $state" => sub { + $mech->log_in_ok( $user->email ); + $user->from_council( 2504 ); + $user->update; + + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok( { + form_number => 2, + fields => { + submit_update => 1, + id => $report_id, + name => $user->name, + rznvy => $user->email, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'this is a forbidden update', + state => $state, + }, + }, + 'submitted with state', + ); + + is $mech->uri->path, "/report/update", "at /report/update"; + + my $errors = $mech->page_errors; + is_deeply $errors, [ 'There was a problem with your update. Please try again.' ], 'error message'; + + is $report->state, 'confirmed', 'state unchanged'; + }; +} + +for my $test ( + { + desc => 'from authority user marks report as investigating', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to investigating', + state => 'investigating', + }, + state => 'investigating', + }, + { + desc => 'from authority user marks report as planned', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to planned', + state => 'planned', + }, + state => 'planned', + }, + { + desc => 'from authority user marks report as in progress', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to in progress', + state => 'in progress', + }, + state => 'in progress', + }, + { + desc => 'from authority user marks report as closed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to closed', + state => 'closed', + }, + state => 'closed', + }, + { + desc => 'from authority user marks report as fixed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to fixed', + state => 'fixed', + }, + state => 'fixed - council', + }, + { + desc => 'from authority user marks report as confirmed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to investigating', + state => 'confirmed', + }, + state => 'confirmed', + }, +) { + subtest $test->{desc} => sub { + $report->comments->delete; + + $mech->log_in_ok( $user->email ); + $user->from_council( 2504 ); + $user->update; + + $mech->get_ok("/report/$report_id"); + + $mech->submit_form_ok( + { + with_fields => $test->{fields}, + }, + 'submit update' + ); + + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $test->{fields}->{update}, 'update text'; + is $update->problem_state, $test->{state}, 'problem state set'; + + my $update_meta = $mech->extract_update_metas; + like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change'; + like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name'; + $mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold'); + + $report->discard_changes; + is $report->state, $test->{state}, 'state set'; + }; +} + +$user->from_council(0); +$user->update; + +$report->state('confirmed'); +$report->update; + for my $test ( { desc => 'submit an update for a non registered user, signing in with wrong password', @@ -678,6 +856,34 @@ foreach my $test ( }, changed => { update => 'Update from owner' }, initial_banner => '', + initial_state => 'confirmed', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, + answered => 0, + path => '/report/update', + content => +"Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?", + }, + { + desc => 'logged in reporter submits update and marks in progress problem fixed', + initial_values => { + name => 'Test User', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + email => 'test@example.com', + fields => { + submit_update => 1, + update => 'update from owner', + add_alert => undef, + fixed => 1, + }, + changed => { update => 'Update from owner' }, + initial_banner => ' This problem is in progress. ', + initial_state => 'in progress', alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 0, @@ -705,6 +911,7 @@ foreach my $test ( }, changed => { update => 'Update from owner' }, initial_banner => '', + initial_state => 'confirmed', alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 1, @@ -723,7 +930,7 @@ foreach my $test ( ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments; $report->discard_changes; - $report->state('confirmed'); + $report->state( $test->{initial_state} ); $report->update; my $questionnaire; @@ -765,6 +972,8 @@ foreach my $test ( my $results = { %{ $test->{fields} }, %{ $test->{changed} }, }; + $report->discard_changes; + my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $results->{update}, 'update text'; @@ -772,6 +981,8 @@ foreach my $test ( is $update->state, 'confirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; + is $report->state, 'fixed - user', 'report state'; + SKIP: { skip( 'not answering questionnaire', 5 ) if $questionnaire; @@ -791,6 +1002,8 @@ foreach my $test ( ok $questionnaire, 'questionnaire exists'; ok $questionnaire->ever_reported, 'ever reported is yes'; + is $questionnaire->old_state(), $test->{initial_state}, 'questionnaire old state'; + is $questionnaire->new_state(), 'fixed - user', 'questionnaire new state'; }; if ($questionnaire) { diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t new file mode 100644 index 000000000..c7bfe171c --- /dev/null +++ b/t/app/model/alert_type.t @@ -0,0 +1,144 @@ +use strict; +use warnings; +use Test::More; +use FixMyStreet::TestMech; + +mySociety::Locale::gettext_domain( 'FixMyStreet' ); + +my $mech = FixMyStreet::TestMech->new(); + +# this is the easiest way to make sure we're not going +# to get any emails sent by data kicking about in the database +FixMyStreet::App->model('DB::AlertType')->email_alerts(); +$mech->clear_emails_ok; + +my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); +ok $user, "created test user"; + +my $user2 = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } ); +ok $user2, "created comment user"; + + +my $dt = DateTime->new( + year => 2011, + month => 04, + day => 16, + hour => 15, + minute => 47, + second => 23 +); + +my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'SW1A 1AA', + council => '2504', + areas => ',105255,11806,11828,2247,2504,', + category => 'Other', + title => 'Test 2', + detail => 'Test 2 Detail', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'closed', + confirmed => $dt->ymd . ' ' . $dt->hms, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '51.5016605453401', + longitude => '-0.142497580865087', + user_id => $user->id, + } +); +my $report_id = $report->id; +ok $report, "created test report - $report_id"; + +my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( + { + problem_id => $report_id, + user_id => $user2->id, + name => 'Other User', + mark_fixed => 'false', + text => 'This is some update text', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + anonymous => 'f', + } +); +my $comment2 = FixMyStreet::App->model('DB::Comment')->find_or_create( + { + problem_id => $report_id, + user_id => $user2->id, + name => 'Other User', + mark_fixed => 'false', + text => 'This is other update text', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + anonymous => 'f', + } +); + +$comment->confirmed( \"ms_current_timestamp() - '3 days'::interval" ); +$comment->update; + +my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( + { + user => $user, + parameter => $report_id, + alert_type => 'new_updates', + whensubscribed => $dt->ymd . ' ' . $dt->hms, + confirmed => 1, + } +); + +for my $test ( + { + state => 'closed', + msg => 'This report is currently marked as closed', + }, + { + state => 'fixed', + msg => 'This report is currently marked as fixed', + }, + { + state => 'confirmed', + msg => 'This report is currently marked as open', + }, +) { + subtest "correct summary for state of $test->{state}" => sub { + $mech->clear_emails_ok; + + my $sent = FixMyStreet::App->model('DB::AlertSent')->search( + { + alert_id => $alert->id, + parameter => $comment->id, + } + )->delete; + + $report->state( $test->{state} ); + $report->update; + + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + + $mech->email_count_is( 1 ); + my $email = $mech->get_email; + my $msg = $test->{msg}; + my $body = $email->body; + + like $body, qr/$msg/, 'email says problem is ' . $test->{state}; + like $body, qr{report/$report_id}, 'contains problem url'; + like $body, qr/This is some update text/, 'contains update text'; + unlike $body, qr/This is other update text/, 'does not contains other update text'; + + my $comments = $body =~ s/(------)//gs; + is $comments, 1, 'only 1 update'; + }; +} + +done_testing(); + diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 1b8804fce..4c6be6a8d 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -152,4 +152,92 @@ for my $test ( }; } +for my $test ( + { + state => 'partial', + is_visible => 0, + is_fixed => 0, + is_open => 0, + is_closed => 0, + }, + { + state => 'hidden', + is_visible => 0, + is_fixed => 0, + is_open => 0, + is_closed => 0, + }, + { + state => 'unconfirmed', + is_visible => 0, + is_fixed => 0, + is_open => 0, + is_closed => 0, + }, + { + state => 'confirmed', + is_visible => 1, + is_fixed => 0, + is_open => 1, + is_closed => 0, + }, + { + state => 'investigating', + is_visible => 1, + is_fixed => 0, + is_open => 1, + is_closed => 0, + }, + { + state => 'planned', + is_visible => 1, + is_fixed => 0, + is_open => 1, + is_closed => 0, + }, + { + state => 'in progress', + is_visible => 1, + is_fixed => 0, + is_open => 1, + is_closed => 0, + }, + { + state => 'fixed', + is_visible => 1, + is_fixed => 1, + is_open => 0, + is_closed => 0, + }, + { + state => 'fixed - council', + is_visible => 1, + is_fixed => 1, + is_open => 0, + is_closed => 0, + }, + { + state => 'fixed - user', + is_visible => 1, + is_fixed => 1, + is_open => 0, + is_closed => 0, + }, + { + state => 'closed', + is_visible => 1, + is_fixed => 0, + is_open => 0, + is_closed => 1, + }, +) { + subtest $test->{state} . ' is fixed/open/closed/visible' => sub { + $problem->state( $test->{state} ); + is $problem->is_visible, $test->{is_visible}, 'is_visible'; + is $problem->is_fixed, $test->{is_fixed}, 'is_fixed'; + is $problem->is_closed, $test->{is_closed}, 'is_closed'; + is $problem->is_open, $test->{is_open}, 'is_open'; + }; +} + done_testing(); diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t new file mode 100644 index 000000000..60b52043a --- /dev/null +++ b/t/app/model/questionnaire.t @@ -0,0 +1,106 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +use FixMyStreet; +use FixMyStreet::TestMech; + +my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => 'test@example.com' } ); + +my $problem = FixMyStreet::App->model('DB::Problem')->create( + { + postcode => 'EH99 1SP', + latitude => 1, + longitude => 1, + areas => 1, + title => 'to be sent', + detail => 'detail', + used_map => 1, + user_id => 1, + name => 'A Name', + state => 'confirmed', + service => '', + cobrand => 'default', + cobrand_data => '', + confirmed => \"ms_current_timestamp() - '5 weeks'::interval", + whensent => \"ms_current_timestamp() - '5 weeks'::interval", + user => $user, + anonymous => 0, + } +); + +diag $problem->id; + +my $mech = FixMyStreet::TestMech->new; + +for my $test ( + { + state => 'unconfirmed', + send_email => 0, + }, + { + state => 'partial', + send_email => 0, + }, + { + state => 'hidden', + send_email => 0, + }, + { + state => 'confirmed', + send_email => 1, + }, + { + state => 'investigating', + send_email => 1, + }, + { + state => 'planned', + send_email => 1, + }, + { + state => 'in progress', + send_email => 1, + }, + { + state => 'fixed', + send_email => 1, + }, + { + state => 'fixed - council', + send_email => 1, + }, + { + state => 'fixed - user', + send_email => 1, + }, + { + state => 'closed', + send_email => 1, + }, +) { + subtest "correct questionnaire behviour for state $test->{state}" => sub { + $problem->discard_changes; + $problem->state( $test->{state} ); + $problem->send_questionnaire( 1 ); + $problem->update; + + $problem->questionnaires->delete; + + $mech->email_count_is(0); + + FixMyStreet::App->model('DB::Questionnaire') + ->send_questionnaires( { site => 'fixmystreet' } ); + + $mech->email_count_is( $test->{send_email} ); + + $mech->clear_emails_ok(); + } +} + +$mech->delete_user( $user ); + +done_testing(); diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t new file mode 100644 index 000000000..b953a32b2 --- /dev/null +++ b/t/map/tilma/original.t @@ -0,0 +1,108 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; +use FixMyStreet::App; +use FixMyStreet::Map; +use FixMyStreet::TestMech; +use DateTime; +use mySociety::Locale; + +my $mech = FixMyStreet::TestMech->new; + +mySociety::Locale::gettext_domain('FixMyStreet'); + +FixMyStreet::Map::set_map_class(); +my $r = Catalyst::Request->new( { base => URI->new('/'), uri => URI->new('http://fixmystreet.com/test') } ); + +my $c = FixMyStreet::App->new( { + request => $r, +}); + +$mech->delete_user('test@example.com'); +my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); +ok $user, "created test user"; + +my $dt = DateTime->now(); + + +my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'SW1A 1AA', + council => '2504', + areas => ',105255,11806,11828,2247,2504,', + category => 'Other', + title => 'Test 2', + detail => 'Test 2 Detail', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'fixed', + confirmed => $dt->ymd . ' ' . $dt->hms, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '49.7668057243776', + longitude => '-7.55715980363992', + user_id => $user->id, + } +); + +for my $test ( + { + state => 'fixed', + colour => 'G', + }, + { + state => 'fixed - user', + colour => 'G', + }, + { + state => 'fixed - council', + colour => 'G', + }, + { + state => 'confirmed', + colour => 'R', + }, + { + state => 'investigating', + colour => 'R', + }, + { + state => 'planned', + colour => 'R', + }, + { + state => 'in progress', + colour => 'R', + }, +) { + subtest "pin colour for state $test->{state}" => sub { + $report->state($test->{state}); + $report->update; + + my ( $pins, $around_map_list, $nearby, $dist ) = + FixMyStreet::Map::map_pins( $c, 0, 0, 0, 0 ); + + ok $pins; + ok $around_map_list; + ok $nearby; + ok $dist; + + my $id = $report->id; + my $colour = $test->{colour}; + + like $pins, qr#<a [^>]* /report/$id [^>]*>[^>]*/i/pin$colour#x, 'pin colour'; + }; +} + +$mech->delete_user( $user ); + + +done_testing(); |