[Catalyst-commits] r6451 - in trunk/Catalyst-View-Email/t: . lib
lib/TestApp lib/TestApp/Controller lib/TestApp/View
lib/TestApp/View/Email root root/text_html root/text_plain
jshirley at dev.catalyst.perl.org
jshirley at dev.catalyst.perl.org
Fri Jun 1 01:40:41 GMT 2007
Author: jshirley
Date: 2007-06-01 01:40:39 +0100 (Fri, 01 Jun 2007)
New Revision: 6451
Added:
trunk/Catalyst-View-Email/t/04basic.t
trunk/Catalyst-View-Email/t/05template.t
trunk/Catalyst-View-Email/t/lib/TestApp.pm
trunk/Catalyst-View-Email/t/lib/TestApp/
trunk/Catalyst-View-Email/t/lib/TestApp/Controller/
trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm
trunk/Catalyst-View-Email/t/lib/TestApp/View/
trunk/Catalyst-View-Email/t/lib/TestApp/View/Email.pm
trunk/Catalyst-View-Email/t/lib/TestApp/View/Email/
trunk/Catalyst-View-Email/t/lib/TestApp/View/Email/Template.pm
trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm
trunk/Catalyst-View-Email/t/root/
trunk/Catalyst-View-Email/t/root/text_html/
trunk/Catalyst-View-Email/t/root/text_html/test.tt
trunk/Catalyst-View-Email/t/root/text_plain/
trunk/Catalyst-View-Email/t/root/text_plain/test.tt
Log:
Adding basic test cases for the view.
Added: trunk/Catalyst-View-Email/t/04basic.t
===================================================================
--- trunk/Catalyst-View-Email/t/04basic.t (rev 0)
+++ trunk/Catalyst-View-Email/t/04basic.t 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+use Email::Send::Test;
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+
+my $response;
+my $time = time;
+ok( ($response = request("/email?time=$time"))->is_success, 'request ok');
+
+my @emails = Email::Send::Test->emails;
+
+is(@emails, 1, "got emails");
+isa_ok( $emails[0], 'Email::MIME', 'email is ok' );
+like($emails[0]->body, qr/$time/, 'Got our email');
Added: trunk/Catalyst-View-Email/t/05template.t
===================================================================
--- trunk/Catalyst-View-Email/t/05template.t (rev 0)
+++ trunk/Catalyst-View-Email/t/05template.t 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+use Email::Send::Test;
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+
+my $response;
+my $time = time;
+ok( ( $response = request("/template_email?time=$time"))->is_success,
+ 'request ok' );
+like( $response->content, qr/Template Email Ok/, 'controller says ok' );
+my @emails = Email::Send::Test->emails;
+
+cmp_ok(@emails, '==', 1, 'got emails');
+isa_ok( $emails[0], 'Email::MIME', 'email is ok' );
+my @parts = $emails[0]->parts;
+cmp_ok(@parts, '==', 2, 'got parts');
+
+is($parts[0]->content_type, 'text/plain; charset="us-ascii"', 'text/plain ok');
+like($parts[0]->body, qr/jshirley\@picturetrail.com on $time/, 'got content back');
+is($parts[1]->content_type, 'text/html; charset="us-ascii"', 'text/html ok');
+like($parts[1]->body, qr{<em>jshirley\@picturetrail.com</em> on $time}, 'got content back');
+#like($emails[0]->body, qr/$time/, 'Got our email');
+
Added: trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm (rev 0)
+++ trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,60 @@
+package # Hide from PAUSE
+ TestApp::Controller::Root;
+
+use base qw(Catalyst::Controller);
+
+sub default : Private {
+ my ( $self, $c ) = @_;
+
+ $c->res->body(qq{Nothing Here});
+}
+
+sub email : Global('email') {
+ my ($self, $c, @args) = @_;
+
+ my $time = $c->req->params->{time} || time;
+
+ $c->stash->{email} = {
+ to => 'jshirley at picturetrail.com',
+ from => 'no-reply at toeat.com',
+ subject => 'Email Test',
+ body => "Email Sent at: $time"
+ };
+
+ $c->forward('TestApp::View::Email');
+
+ if ( scalar( @{ $c->error } ) ) {
+ $c->res->status(500);
+ $c->res->body('Email Failed');
+ } else {
+ $c->res->body('Plain Email Ok');
+ }
+}
+
+sub template_email : Global('template_email') {
+ my ($self, $c, @args) = @_;
+
+ $c->stash->{time} = $c->req->params->{time} || time;
+
+ $c->stash->{email} = {
+ to => 'jshirley at picturetrail.com',
+ from => 'no-reply at toeat.com',
+ subject => 'Just a test',
+ content_type => 'multipart/alternative',
+ templates => [
+ qw{text_plain/test.tt},
+ qw{text_html/test.tt}
+ ]
+ };
+
+ $c->forward('TestApp::View::Email::Template');
+
+ if ( scalar( @{ $c->error } ) ) {
+ $c->res->status(500);
+ $c->res->body('Template Email Failed');
+ } else {
+ $c->res->body('Template Email Ok');
+ }
+}
+
+1;
Added: trunk/Catalyst-View-Email/t/lib/TestApp/View/Email/Template.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp/View/Email/Template.pm (rev 0)
+++ trunk/Catalyst-View-Email/t/lib/TestApp/View/Email/Template.pm 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,15 @@
+package # Hide me
+ TestApp::View::Email::Template;
+
+use strict;
+use base 'Catalyst::View::Email::Template';
+
+__PACKAGE__->config(
+ sender => {
+ method => 'Test'
+ },
+ stash_key => 'email',
+ template_prefix => ''
+);
+
+1;
Added: trunk/Catalyst-View-Email/t/lib/TestApp/View/Email.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp/View/Email.pm (rev 0)
+++ trunk/Catalyst-View-Email/t/lib/TestApp/View/Email.pm 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,14 @@
+package # Hide from PAUSE
+ TestApp::View::Email;
+
+use Email::Send::Test;
+
+use base 'Catalyst::View::Email';
+
+__PACKAGE__->config(
+ sender => {
+ method => 'Test'
+ },
+);
+
+1;
Added: trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm (rev 0)
+++ trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,7 @@
+package # Hide me.
+ TestApp::View::TT;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+1;
Added: trunk/Catalyst-View-Email/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp.pm (rev 0)
+++ trunk/Catalyst-View-Email/t/lib/TestApp.pm 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,14 @@
+package # Hide from PAUSE
+ TestApp;
+
+use Catalyst;
+use FindBin;
+
+TestApp->config(
+ root => "$FindBin::Bin/root",
+ default_view => 'TT'
+);
+
+TestApp->setup;
+
+1;
Added: trunk/Catalyst-View-Email/t/root/text_html/test.tt
===================================================================
--- trunk/Catalyst-View-Email/t/root/text_html/test.tt (rev 0)
+++ trunk/Catalyst-View-Email/t/root/text_html/test.tt 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,7 @@
+<html>
+ <body>
+ <h1>Look at my style</h1>
+ <p>I was sent to <em>[% email.to %]</em> on [% time %]</p>
+ </body>
+</html>
+
Added: trunk/Catalyst-View-Email/t/root/text_plain/test.tt
===================================================================
--- trunk/Catalyst-View-Email/t/root/text_plain/test.tt (rev 0)
+++ trunk/Catalyst-View-Email/t/root/text_plain/test.tt 2007-06-01 00:40:39 UTC (rev 6451)
@@ -0,0 +1,3 @@
+I am plain text. I have no style.
+
+I was sent to [% email.to %] on [% time %]
More information about the Catalyst-commits
mailing list