aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/helpers/send_email.t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-07-15 18:31:52 +0100
committerDave Arter <davea@mysociety.org>2016-08-01 11:52:22 +0100
commit1820db45188fd62699223f63167c5f7250d1b7a6 (patch)
tree116814d9bb6ebd7f6fa015d3e492993b620ac6b1 /t/app/helpers/send_email.t
parent0271c3fa016178f8c72b1192f1d0ed57437ec4c4 (diff)
Add HTML email templates.
Design is all Zarino. This adds the ability to send HTML emails, including attached inline images. When included, this is done as a multipart/related email containing a multipart/alternative (of plain and HTML) and any attached images, so that the images are available even if HTML mail is not. The alert emails list data has been improved so it can be constructed in the templates rather than the code. Various templates have been tidied. Various workarounds for email clients have been made, including: * <th> is used so that the Android 4.x mail client can give them `block` styling in the small screen media query. * Font settings defined on every table cell (<th>) so that sans-serif fonts are used in Outlook, rather than Times New Roman. * A three-column wrapper table to create a 620px centred content area that also shrinks down on narrow screens. (Outlook doesn’t like max-width, so this is the simplest alternative.) * Enforcing a sensible (500px) min-width for the main content area, on clients that don’t support media queries (eg: native Gmail app). * Giant borders on buttons so Outlook displays them * Image alignment with align rather than float.
Diffstat (limited to 't/app/helpers/send_email.t')
-rw-r--r--t/app/helpers/send_email.t32
1 files changed, 27 insertions, 5 deletions
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
index e2c8688a8..3975002fa 100644
--- a/t/app/helpers/send_email.t
+++ b/t/app/helpers/send_email.t
@@ -2,6 +2,12 @@ use strict;
use warnings;
use utf8;
+package FixMyStreet::Cobrand::Tester;
+use parent 'FixMyStreet::Cobrand::Default';
+sub path_to_email_templates { [ FixMyStreet->path_to( 't', 'app', 'helpers', 'emails') ] }
+
+package main;
+
BEGIN {
use FixMyStreet;
FixMyStreet->test_mode(1);
@@ -28,8 +34,12 @@ $c->stash->{foo} = 'bar';
Email::Send::Test->clear;
# send the test email
-ok $c->send_email( 'test.txt', { to => 'test@recipient.com' } ),
- "sent an email";
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+}, sub {
+ 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;
@@ -51,9 +61,7 @@ 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;
- Email::Send::Test->clear;
- my @emails = Email::Send::Test->emails;
- is scalar(@emails), 0, "reset";
+ $mech->clear_emails_ok;
ok $c->send_email( 'test.txt',
{ to => 'test@recipient.com',
@@ -108,6 +116,20 @@ subtest 'MIME attachments' => sub {
$path->spew($email_as_string);
diag "Saved output in $path";
};
+ $mech->clear_emails_ok;
+};
+
+subtest 'Inline emails!' => sub {
+ ok $c->send_email( 'html_test.txt', { to => 'test@recipient.com' } ), "sent an email with email attachments";
+
+ my $email = $mech->get_email;
+ like $email->debug_structure, qr[
+ \+\ multipart/related.*\n
+ \ {5}\+\ multipart/alternative.*\n
+ \ {10}\+\ text/plain.*\n
+ \ {10}\+\ text/html.*\n
+ \ {5}\+\ image/gif]x;
+ $mech->clear_emails_ok;
};
done_testing;