initial commit
[catagits/Catalyst-View-Email.git] / t / lib / TestApp / Controller / Root.pm
1 package  # Hide from PAUSE
2     TestApp::Controller::Root;
3
4 use base qw(Catalyst::Controller);
5
6 use Encode;
7
8 sub default : Private {
9     my ( $self, $c ) = @_;
10
11     $c->res->body(qq{Nothing Here});
12 }
13
14 sub email : Global('email') {
15     my ($self, $c, @args) = @_;
16
17     my $time = $c->req->params->{time} || time;
18
19     $c->stash->{email} = {
20         to      => 'test-email@example.com',
21         from    => 'no-reply@example.com',
22         subject => 'Email Test',
23         body    => "Email Sent at: $time"
24     };
25
26     $c->forward('TestApp::View::Email');
27
28     if ( scalar( @{ $c->error } ) ) {
29         $c->res->status(500);
30         $c->res->body('Email Failed');
31     } else {
32         $c->res->body('Plain Email Ok');
33     }
34 }
35
36 sub email_app_config : Global('email_app_config') {
37     my ($self, $c, @args) = @_;
38
39     my $time = $c->req->params->{time} || time;
40
41     $c->stash->{email} = {
42         to      => 'test-email@example.com',
43         from    => 'no-reply@example.com',
44         subject => 'Email Test',
45         body    => "Email Sent at: $time"
46     };
47
48     $c->forward('TestApp::View::Email::AppConfig');
49
50     if ( scalar( @{ $c->error } ) ) {
51         $c->res->status(500);
52         $c->res->body('Email Failed');
53     } else {
54         $c->res->body('Plain Email Ok');
55     }
56 }
57
58 sub template_email : Global('template_email') {
59     my ($self, $c, @args) = @_;
60
61     $c->stash->{time} = $c->req->params->{time} || time;
62
63     $c->stash->{email} = {
64         to           => 'test-email@example.com',
65         from         => 'no-reply@example.com',
66         subject      => 'Just a test',
67         content_type => 'multipart/alternative',
68         templates => [
69             {
70                 template        => 'text_plain/test.tt',
71                 content_type    => 'text/plain',
72             },
73             {
74                 view            => 'TT',
75                 template        => 'text_html/test.tt',
76                 content_type    => 'text/html',
77             },
78         ],
79     };
80
81     $c->forward('TestApp::View::Email::Template');    
82
83     if ( scalar( @{ $c->error } ) ) {
84         $c->res->status(500);
85         $c->res->body('Template Email Failed');
86     } else {
87         $c->res->body('Template Email Ok');
88     }
89 }
90
91 sub template_email_utf8 : Global('template_email_utf8') {
92     my ($self, $c, @args) = @_;
93
94     $c->stash->{time} = $c->req->params->{time} || time;
95
96     $c->stash->{chars} = decode('utf-8', "✔ ✈ ✉");
97
98     $c->stash->{email} = {
99         to           => 'test-email@example.com',
100         from         => 'no-reply@example.com',
101         subject      => 'Just a test',
102         content_type => 'multipart/alternative',
103        templates => [
104             {
105                 template        => 'text_plain/test.tt',
106                 content_type    => 'text/plain',
107                 charset      => 'utf-8',
108                 encoding     => 'quoted-printable',
109             },
110             {
111                 view            => 'TT',
112                 template        => 'text_html/test_utf8.tt',
113                 content_type    => 'text/html',
114                 charset      => 'utf-8',
115                 encoding     => 'quoted-printable',
116              },
117         ],
118     };
119
120     $c->forward('TestApp::View::Email::Template');    
121
122     if ( scalar( @{ $c->error } ) ) {
123         $c->res->status(500);
124         $c->res->body('Template Email Failed');
125     } else {
126         $c->res->body('Template Email Ok');
127     }
128 }
129
130
131
132 sub template_email_app_config : Global('template_email_app_config') {
133     my ($self, $c, @args) = @_;
134
135     $c->stash->{time} = $c->req->params->{time} || time;
136
137     $c->stash->{template_email} = {
138         to      => 'test-email@example.com',
139         from    => 'no-reply@example.com',
140         subject => 'Just a test',
141         templates => [
142             {
143                 template        => 'text_plain/test.tt',
144                 content_type    => 'text/plain',
145             },
146             {
147                 view            => 'TT',
148                 template        => 'text_html/test.tt',
149                 content_type    => 'text/html',
150             },
151         ],
152     };
153
154     $c->forward('TestApp::View::Email::Template::AppConfig');
155
156     if ( scalar( @{ $c->error } ) ) {
157         $c->res->status(500);
158         $c->res->body('Template Email Failed');
159     } else {
160         $c->res->body('Template Email Ok');
161     }
162 }
163
164 sub mason_email : Global('mason_email') {
165     my ($self, $c, @args) = @_;
166
167     $c->stash->{time} = $c->req->params->{time} || time;
168
169     $c->stash->{email} = {
170         to      => 'test-email@example.com',
171         from    => 'no-reply@example.com',
172         subject => 'Just a test',
173         templates => [
174             {
175                 view            => 'Mason',
176                         template        => 'text_plain/test.m',
177                 content_type    => 'text/plain',
178             },
179             {
180                 view            => 'Mason',
181                 template        => 'text_html/test.m',
182                 content_type    => 'text/html',
183             },
184         ],
185     };
186
187     $c->forward('TestApp::View::Email::Template');    
188
189     if ( scalar( @{ $c->error } ) ) {
190         $c->res->status(500);
191         $c->res->body('Mason Email Failed');
192     } else {
193         $c->res->body('Mason Email Ok');
194     }
195 }
196
197
198 1;