added patch from ticket https://rt.cpan.org/Ticket/Display.html?id=66495
[catagits/Catalyst-View-Email.git] / t / 05template.t
CommitLineData
82300460 1use strict;
2use warnings;
ce1977b0 3
4BEGIN { $ENV{EMAIL_SENDER_TRANSPORT} = 'Test' }
8b10ee55 5use Test::More;
69237653 6use Test::Requires {
cdce082b 7 'Catalyst::View::TT' => '0.31',
69237653 8};
ce1977b0 9use Email::Sender::Simple;
82300460 10use FindBin;
11use lib "$FindBin::Bin/lib";
12
13use_ok('Catalyst::Test', 'TestApp');
14
15my $response;
16my $time = time;
17ok( ( $response = request("/template_email?time=$time"))->is_success,
18 'request ok' );
ce1977b0 19my @emails = Email::Sender::Simple->default_transport->deliveries;
82300460 20like( $response->content, qr/Template Email Ok/, 'controller says ok' );
82300460 21cmp_ok(@emails, '==', 1, 'got emails');
ce1977b0 22isa_ok( $emails[0]->{'email'}, 'Email::Abstract', 'email is ok' );
ab4326b4 23
ce1977b0 24like($emails[0]->{'email'}[0]->header("Content-type"), qr#^multipart/alternative#, 'Multipart email');
ab4326b4 25
ce1977b0 26my @parts = $emails[0]->{'email'}[0]->parts;
82300460 27cmp_ok(@parts, '==', 2, 'got parts');
28
28151039 29is($parts[0]->content_type, 'text/plain', 'text/plain part ok');
fd0033bc 30like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
43090696 31
28151039 32is($parts[1]->content_type, 'text/html', 'text/html ok');
fd0033bc 33like($parts[1]->body, qr{<em>test-email\@example.com</em> on $time}, 'got content back');
82300460 34#like($emails[0]->body, qr/$time/, 'Got our email');
ce1977b0 35done_testing();