aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 't/app/helpers')
-rw-r--r--t/app/helpers/send_email.t56
-rw-r--r--t/app/helpers/send_email_sample.txt29
2 files changed, 85 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..ac7e5b5c2
--- /dev/null
+++ b/t/app/helpers/send_email.t
@@ -0,0 +1,56 @@
+#!/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(
+ {
+ request => Catalyst::Request->new(
+ {
+ base => URI->new('http://fixmystreet.com/'),
+ uri => URI->new('http://fixmystreet.com/')
+ }
+ ),
+ }
+);
+$c->setup_request();
+
+# 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;
+my $name = FixMyStreet->config('CONTACT_NAME');
+$name = "\"$name\"" if $name =~ / /;
+my $sender = $name . ' <' . FixMyStreet->config('CONTACT_EMAIL') . '>';
+$expected_email_content =~ s{CONTACT_EMAIL}{$sender};
+
+is $email_as_string,
+$expected_email_content,
+ "email is as expected";
diff --git a/t/app/helpers/send_email_sample.txt b/t/app/helpers/send_email_sample.txt
new file mode 100644
index 000000000..2fe5272cb
--- /dev/null
+++ b/t/app/helpers/send_email_sample.txt
@@ -0,0 +1,29 @@
+MIME-Version: 1.0
+Subject: test email =?utf-8?Q?=E2=98=BA?=
+Content-Type: text/plain; charset="utf-8"
+To: test@recipient.com
+Content-Transfer-Encoding: quoted-printable
+From: CONTACT_EMAIL
+
+ Hello,
+
+ This is a test email where foo: bar.
+
+ utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=
+=E7=BC=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81
+
+ indented_text
+
+ long line: Lorem ipsum dolor sit amet, consectetur adipisicing
+ elit, sed do eiusmod tempor incididunt ut labore et dolore
+ magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo
+ consequat. Duis aute irure dolor in reprehenderit in voluptate
+ velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
+ sint occaecat cupidatat non proident, sunt in culpa qui officia
+ deserunt mollit anim id est laborum.
+
+ Yours,=20=20
+ FixMyStreet.=20=
+
+