aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/helpers/send_email.t
blob: a44ddb01cd6b167d2a1e391d3af041d5e414aef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl

use strict;
use warnings;
use utf8;

BEGIN {
    use FixMyStreet;
    FixMyStreet->test_mode(1);
}

use Test::More tests => 4;

use Email::Send::Test;

use_ok 'FixMyStreet::App';
my $c = FixMyStreet::App->new;

# fake up the request a little
$c->req->uri( URI->new('http://localhost/') );
$c->req->base( $c->req->uri );


# 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', { 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";

is $emails[0]->as_string, << 'END_OF_BODY', "email is as expected";
Subject: test email
From: evdb@ecclestoad.co.uk
To: test@recipient.com
Content-Type: text/plain; charset="utf-8"

Hello,

This is a test email where foo: bar.

utf8: 我们应该能够无缝处理UTF8编码

Yours,
  FixMyStreet.
END_OF_BODY