05template now passes
[catagits/Catalyst-View-Email.git] / t / 05template.t
1 use strict;
2 use warnings;
3
4 BEGIN { $ENV{EMAIL_SENDER_TRANSPORT} = 'Test' }
5 use Test::More;
6
7 use Email::Sender::Simple;
8 use FindBin;
9 use Data::Dumper;
10 use lib "$FindBin::Bin/lib";
11
12 eval "use Catalyst::View::TT";
13 if ( $@ ) {
14     plan skip_all => 'Catalyst::View::TT required for Template tests';
15     exit;
16 }
17
18 use_ok('Catalyst::Test', 'TestApp');
19
20 my $response;
21 my $time = time;
22 ok( ( $response = request("/template_email?time=$time"))->is_success,
23     'request ok' );
24 my @emails = Email::Sender::Simple->default_transport->deliveries;
25 like( $response->content, qr/Template Email Ok/, 'controller says ok' );
26 cmp_ok(@emails, '==', 1, 'got emails');
27 isa_ok( $emails[0]->{'email'}, 'Email::Abstract', 'email is ok' );
28
29 like($emails[0]->{'email'}[0]->header("Content-type"), qr#^multipart/alternative#, 'Multipart email');
30
31 my @parts = $emails[0]->{'email'}[0]->parts;
32 cmp_ok(@parts, '==', 2, 'got parts');
33
34 is($parts[0]->content_type, 'text/plain', 'text/plain part ok');
35 like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
36
37 is($parts[1]->content_type, 'text/html', 'text/html ok');
38 like($parts[1]->body, qr{<em>test-email\@example.com</em> on $time}, 'got content back');
39 #like($emails[0]->body, qr/$time/, 'Got our email');
40 done_testing();