diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-03-15 13:29:42 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-03-23 08:56:06 +0000 |
commit | cb49284dc0503b2a05ca2bb98b8a1320431c2616 (patch) | |
tree | be4ddb1fc16cf45b67e3cf0683506a493de4b27e /t/app/helpers/send_email.t | |
parent | d3d0ab6d5a753d1e5c8277db981f03823683ae1f (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/send_email.t')
-rw-r--r-- | t/app/helpers/send_email.t | 26 |
1 files changed, 20 insertions, 6 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"); |