aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/helpers/send_email.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/helpers/send_email.t')
-rw-r--r--t/app/helpers/send_email.t47
1 files changed, 47 insertions, 0 deletions
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
new file mode 100644
index 000000000..97006c7e2
--- /dev/null
+++ b/t/app/helpers/send_email.t
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use utf8;
+
+BEGIN {
+ use FixMyStreet;
+ FixMyStreet->test_mode(1);
+}
+
+use Test::More tests => 5;
+
+use Email::Send::Test;
+use Path::Class;
+
+use_ok 'FixMyStreet::App';
+my $c = FixMyStreet::App->new;
+
+# fake up the request a little
+$c->req->uri( URI->new('http://localhost/') );
+$c->req->base( $c->req->uri );
+
+# set some values in the stash
+$c->stash->{foo} = 'bar';
+
+# clear the email queue
+Email::Send::Test->clear;
+
+# send the test email
+ok $c->send_email( 'test.txt', { to => 'test@recipient.com' } ),
+ "sent an email";
+
+# check it got templated and sent correctly
+my @emails = Email::Send::Test->emails;
+is scalar(@emails), 1, "caught one email";
+
+# Get the email, check it has a date and then strip it out
+my $email_as_string = $emails[0]->as_string;
+ok $email_as_string =~ s{\s+Date:\s+\S.*?$}{}xms, "Found and stripped out date";
+
+my $expected_email_content = file(__FILE__)->dir->file('send_email_sample.txt')->slurp;
+$expected_email_content =~ s{TESTING_EMAIL}{ FixMyStreet->config('TESTING_EMAIL') }e;
+
+is $email_as_string,
+$expected_email_content,
+ "email is as expected";