File: 05template.t

package info (click to toggle)
libcatalyst-view-email-perl 0.36-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 308 kB
  • sloc: perl: 2,665; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,603 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

BEGIN { $ENV{EMAIL_SENDER_TRANSPORT} = 'Test' }
use Test::More;
use Test::Requires {
    'Catalyst::View::TT' => '0.31',
};
use Email::Sender::Simple;
use FindBin;
use lib "$FindBin::Bin/lib";
use Data::Dump qw(ddx);
use_ok('Catalyst::Test', 'TestApp');

my $response;
my $response2;
my $time = time;
ok( ( $response = request("/template_email?time=$time"))->is_success,
    'request ok' );
my @emails = Email::Sender::Simple->default_transport->deliveries;
like( $response->content, qr/Template Email Ok/, 'controller says ok' );
cmp_ok(@emails, '==', 1, 'got emails');
isa_ok( $emails[0]->{'email'}, 'Email::Abstract', 'email is ok' );

like($emails[0]->{'email'}[0]->header("Content-type"), qr#^multipart/alternative#, 'Multipart email');

my @parts = $emails[0]->{'email'}[0]->parts;
cmp_ok(@parts, '==', 2, 'got parts');

is($parts[0]->content_type, 'text/plain', 'text/plain part ok');
like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');

is($parts[1]->content_type, 'text/html', 'text/html ok');
like($parts[1]->body, qr{<em>test-email\@example.com</em> on $time}, 'got content back');

ok( ( $response2 = request("/template_email_single?time=$time"))->is_success,
    'request ok' );
like( $response2->content, qr/Template Email Ok/, 'controller says ok' );
my @emails2 = Email::Sender::Simple->default_transport->deliveries;
my @parts2 = $emails2[0]->{'email'}[0]->parts;
is($parts2[1]->content_type, 'text/html', 'text/html ok');
like($parts2[1]->body, qr{<em>test-email\@example.com</em> on $time}, 'got content back');
done_testing();