aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-03-23 11:44:39 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-03-23 11:44:39 +0000
commitf1b3e509455163b0f3362e460d201d04593a8388 (patch)
treeed5833d16c4142a45fb20ff8b8227aeafefbea78 /t/app
parent4210219bed15cbd76c9e351db160f1d0188f78f8 (diff)
parentb33eb7d3bd02ece9ff70a215290a233f6e480378 (diff)
Merge branch 'perl5.22-snapshot-update'
Diffstat (limited to 't/app')
-rw-r--r--t/app/helpers/send_email.t26
-rw-r--r--t/app/helpers/send_email_sample_mime.txt10
2 files changed, 25 insertions, 11 deletions
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
index c4781ac8f..f60f7fa5a 100644
--- a/t/app/helpers/send_email.t
+++ b/t/app/helpers/send_email.t
@@ -7,6 +7,7 @@ BEGIN {
FixMyStreet->test_mode(1);
}
+use Email::MIME;
use Test::More;
use Test::LongString;
@@ -36,14 +37,17 @@ is scalar(@emails), 1, "caught one email";
# Get the email, check it has a date and then strip it out
my $email_as_string = $mech->get_first_email(@emails);
+my $email = Email::MIME->new($email_as_string);
my $expected_email_content = path(__FILE__)->parent->child('send_email_sample.txt')->slurp;
my $name = FixMyStreet->config('CONTACT_NAME');
$name = "\"$name\"" if $name =~ / /;
my $sender = $name . ' <' . FixMyStreet->config('DO_NOT_REPLY_EMAIL') . '>';
$expected_email_content =~ s{CONTACT_EMAIL}{$sender};
+my $expected_email = Email::MIME->new($expected_email_content);
-is_string $email_as_string, $expected_email_content, "email is as expected";
+is_deeply { $email->header_pairs }, { $expected_email->header_pairs }, 'MIME email headers ok';
+is_string $email->body, $expected_email->body, 'email is as expected';
subtest 'MIME attachments' => sub {
my $data = path(__FILE__)->parent->child('grey.gif')->slurp_raw;
@@ -80,15 +84,25 @@ subtest 'MIME attachments' => sub {
is scalar(@emails), 1, "caught one email";
my $email_as_string = $mech->get_first_email(@emails);
-
my ($boundary) = $email_as_string =~ /boundary="([A-Za-z0-9.]*)"/ms;
- my $changes = $email_as_string =~ s{$boundary}{}g;
- is $changes, 5, '5 boundaries'; # header + 4 around the 3x parts (text + 2 images)
+ my $email = Email::MIME->new($email_as_string);
my $expected_email_content = path(__FILE__)->parent->child('send_email_sample_mime.txt')->slurp;
$expected_email_content =~ s{CONTACT_EMAIL}{$sender}g;
-
- is_string $email_as_string, $expected_email_content, 'MIME email text ok'
+ $expected_email_content =~ s{BOUNDARY}{$boundary}g;
+ my $expected_email = Email::MIME->new($expected_email_content);
+
+ my @email_parts;
+ $email->walk_parts(sub {
+ my ($part) = @_;
+ push @email_parts, [ { $part->header_pairs }, $part->body ];
+ });
+ my @expected_email_parts;
+ $expected_email->walk_parts(sub {
+ my ($part) = @_;
+ push @expected_email_parts, [ { $part->header_pairs }, $part->body ];
+ });
+ is_deeply \@email_parts, \@expected_email_parts, 'MIME email text ok'
or do {
(my $test_name = $0) =~ s{/}{_}g;
my $path = path("test-output-$test_name.tmp");
diff --git a/t/app/helpers/send_email_sample_mime.txt b/t/app/helpers/send_email_sample_mime.txt
index 4ce0f9520..c4ca97bcc 100644
--- a/t/app/helpers/send_email_sample_mime.txt
+++ b/t/app/helpers/send_email_sample_mime.txt
@@ -1,12 +1,12 @@
MIME-Version: 1.0
Subject: test email =?utf-8?Q?=E2=98=BA?=
-Content-Type: multipart/mixed; boundary=""
+Content-Type: multipart/mixed; boundary="BOUNDARY"
To: test@recipient.com
Content-Transfer-Encoding: 7bit
From: CONTACT_EMAIL
---
+--BOUNDARY
MIME-Version: 1.0
Subject: test email =?utf-8?Q?=E2=98=BA?=
Content-Type: text/plain; charset="utf-8"
@@ -36,7 +36,7 @@ FixMyStreet.=20=
---
+--BOUNDARY
MIME-Version: 1.0
Content-Type: image/gif; name="foo.gif"
Content-Disposition: inline; filename="foo.gif"
@@ -45,7 +45,7 @@ Content-Transfer-Encoding: quoted-printable
GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
=02=01L=00;=
---
+--BOUNDARY
MIME-Version: 1.0
Content-Type: image/gif; name="bar.gif"
Content-Disposition: inline; filename="bar.gif"
@@ -54,4 +54,4 @@ Content-Transfer-Encoding: quoted-printable
GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
=02=01L=00;=
-----
+--BOUNDARY--