removed that rat bastard Email::Send::Test stuff
[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 lib "$FindBin::Bin/lib";
10
11 eval "use Catalyst::View::TT";
12 if ( $@ ) {
13     plan skip_all => 'Catalyst::View::TT required for Template tests';
14     exit;
15 }
16
17 use_ok('Catalyst::Test', 'TestApp');
18
19 my $response;
20 my $time = time;
21 ok( ( $response = request("/template_email?time=$time"))->is_success,
22     'request ok' );
23 my @emails = Email::Sender::Simple->default_transport->deliveries;
24 like( $response->content, qr/Template Email Ok/, 'controller says ok' );
25 cmp_ok(@emails, '==', 1, 'got emails');
26 isa_ok( $emails[0]->{'email'}, 'Email::Abstract', 'email is ok' );
27
28 like($emails[0]->{'email'}[0]->header("Content-type"), qr#^multipart/alternative#, 'Multipart email');
29
30 my @parts = $emails[0]->{'email'}[0]->parts;
31 cmp_ok(@parts, '==', 2, 'got parts');
32
33 is($parts[0]->content_type, 'text/plain', 'text/plain part ok');
34 like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
35
36 is($parts[1]->content_type, 'text/html', 'text/html ok');
37 like($parts[1]->body, qr{<em>test-email\@example.com</em> on $time}, 'got content back');
38 #like($emails[0]->body, qr/$time/, 'Got our email');
39 done_testing();