diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 29 | ||||
-rw-r--r-- | t/app/model/problem.t | 47 | ||||
-rw-r--r-- | templates/email/default/confirm_report_sent.txt | 9 |
4 files changed, 87 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 0401f58c3..8f4f589f4 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -756,5 +756,7 @@ sub report_check_for_errors { ); } +sub report_sent_confirmation_email { 0; } + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index bb826a5ca..282ffaea3 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -395,6 +395,9 @@ sub send_reports { whensent => \'ms_current_timestamp()', lastupdate => \'ms_current_timestamp()', } ); + if ( $cobrand->report_sent_confirmation_email ) { + _send_report_sent_email( $row, \%h, $nomail ); + } } else { my @errors; for my $sender ( keys %reporters ) { @@ -440,4 +443,30 @@ sub send_reports { } } +sub _send_report_sent_email { + my $row = shift; + my $h = shift; + my $nomail = shift; + + my $template = 'confirm_report_sent.txt'; + my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $row->lang, $template )->stringify; + $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify + unless -e $template_path; + $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify + unless -e $template_path; + $template = Utils::read_file( $template_path ); + + my $result = FixMyStreet::App->send_email_cron( + { + _template_ => $template, + _parameters_ => $h, + To => $row->user->email, + From => mySociety::Config::get('CONTACT_EMAIL'), + }, + mySociety::Config::get('CONTACT_EMAIL'), + [ $row->user->email ], + $nomail + ); +} + 1; diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 9aa52c3cf..63204e05c 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -540,6 +540,53 @@ foreach my $test ( { }; } +subtest 'check can turn on report sent email alerts' => sub { + eval 'use Test::MockModule; 1' or + plan skip_all => 'Skipping tests that rely on Test::MockModule'; + + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + council => 2651, + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + name => 'Test User', + cobrand => 'fixmystreet', + } ); + + my $m = new Test::MockModule( + 'FixMyStreet::Cobrand::FixMyStreet' ); + $m->mock( report_sent_confirmation_email => 1 ); + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 2 ); + my @emails = $mech->get_email; + my $email = $emails[0]; + + like $email->header('To'),qr/City of Edinburgh Council/, 'to line looks correct'; + is $email->header('From'), '"Test User" <system_user@example.com>', 'from line looks correct'; + like $email->header('Subject'), qr/A Title/, 'subject line looks correct'; + like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report'; + like $email->body, qr/Subject: A Title/, 'more email body checking'; + like $email->body, qr/Dear City of Edinburgh Council/, 'Salutation looks correct'; + + $problem->discard_changes; + ok defined( $problem->whensent ), 'whensent set'; + + $email = $emails[1]; + like $email->header('Subject'), qr/Problem Report Sent/, 'report sent email title correct'; + like $email->body, qr/Your report about/, 'report sent body correct'; +}; + $problem->comments->delete; $problem->delete; $user->delete; diff --git a/templates/email/default/confirm_report_sent.txt b/templates/email/default/confirm_report_sent.txt new file mode 100644 index 000000000..42f200213 --- /dev/null +++ b/templates/email/default/confirm_report_sent.txt @@ -0,0 +1,9 @@ +Subject: Problem Report Sent: <?=$values['title']?> + +Hi, + +Your report about "<?=$values['title']?>" has been sent to <?=$values['councils_name']?>. + +Thanks + +<?=$values['signature']?> |