7a4ef2e299e3a8f3cc84402a6b9d2aedc30b1337
[catagits/Catalyst-View-Email.git] / t / 07mason.t
1 use strict;
2 use warnings;
3 use Test::More;
4 ## skip unless MASON_TEST specified
5
6 ## ...
7
8 ##
9 BEGIN { $ENV{EMAIL_SENDER_TRANSPORT} = 'Test' }
10 use FindBin;
11 use lib "$FindBin::Bin/lib";
12
13 use Email::Sender::Simple;
14
15 eval "use Catalyst::View::Mason";
16 if ( $@ ) {
17     plan skip_all => 'Catalyst::View::Mason required for Mason tests';
18     exit;
19 }
20
21 use_ok('Catalyst::Test', 'TestApp');
22
23 TestApp->config->{default_view} = 'Mason';
24 my $response;
25 my $time = time;
26 ok( ( $response = request("/mason_email?time=$time"))->is_success,
27     'request ok' );
28 like( $response->content, qr/Mason Email Ok/, 'controller says ok' );
29 my @emails = Email::Sender::Simple->default_transport->deliveries;
30 cmp_ok(@emails, '==', 1, 'got emails');
31 isa_ok( $emails[0]->{'email'}, 'Email::Abstract', 'email is ok' );
32 my @parts = $emails[0]->{'email'}[0]->parts;
33 cmp_ok(@parts, '==', 2, 'got parts');
34 is($parts[0]->content_type, 'text/plain', 'text/plain ok');
35 like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
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();