aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/helpers
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-03-15 13:29:42 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-03-23 08:56:06 +0000
commitcb49284dc0503b2a05ca2bb98b8a1320431c2616 (patch)
treebe4ddb1fc16cf45b67e3cf0683506a493de4b27e /t/app/helpers
parentd3d0ab6d5a753d1e5c8277db981f03823683ae1f (diff)
Updates to cpanfile and code for perl 5.20/5.22.
The following modules had bugs that have been fixed for working in recent perls: * List::MoreUtils * Guard * PadWalker * aliased * URI * Convert::NLS_DATE_FORMAT The CGI module was removed from core in 5.20, so include it in the snapshot (I don't think it's actually used, but is a dependency). "{" needs to be escaped in regular expressions, and ~~ should not be used. Fix some tests that expect e.g. a certain hash ordering, to use sorted output or better comparisons.
Diffstat (limited to 't/app/helpers')
-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--