Fixing content type ordering when content_type is not defined.
[akelos.git] / test / fixtures / app / models / test_mailer.php
blob0da1bb399d2fe8095fcf0ee0b2484994aa0d697a
1 <?php
3 class TestMailer extends AkActionMailer
5 var $delivery_method = 'test';
7 function signed_up($recipient)
9 $this->set(array(
10 'recipients' => $recipient,
11 'subject' => "[Signed up] Welcome $recipient",
12 'from' => "system@example.com",
13 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
14 'body' => array('recipient' => $recipient)
15 ));
18 function cancelled_account($recipient)
20 $this->set(array(
21 'recipients' => $recipient,
22 'subject' => "[Cancelled] Goodbye $recipient",
23 'from' => "system@example.com",
24 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
25 'body' => "Goodbye, Mr. $recipient"
26 ));
29 function cc_bcc($recipient)
31 $this->set(array(
32 'recipients' => $recipient,
33 'subject' => "testing bcc/cc",
34 'from' => "system@example.com",
35 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
36 'cc' => "nobody@example.com",
37 'bcc' => "root@example.com",
38 'body' => "Nothing to see here."
39 ));
42 function iso_charset($recipient)
44 $this->set(array(
45 'recipients' => $recipient,
46 'subject' => Ak::recode('testing isø charsets','ISO-8859-1', 'UTF-8'),
47 'from' => "system@example.com",
48 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
49 'cc' => "nobody@example.com",
50 'bcc' => "root@example.com",
51 'body' => "Nothing to see here.",
52 'charset' => "ISO-8859-1"
53 ));
56 function unencoded_subject($recipient)
58 $this->set(array(
59 'recipients' => $recipient,
60 'subject' => "testing unencoded subject",
61 'from' => "system@example.com",
62 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
63 'cc' => "nobody@example.com",
64 'bcc' => "root@example.com",
65 'body' => "Nothing to see here."
66 ));
70 function extended_headers($recipient)
72 $this->set(array(
73 'recipients' => $recipient,
74 'subject' => "testing extended headers",
75 'from' => "Grytøyr <stian1@example.com>",
76 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
77 'cc' => "Grytøyr <stian2@example.com>",
78 'bcc' => "Grytøyr <stian3@example.com>",
79 'body' => "Nothing to see here.",
80 'charset' => "ISO-8859-1"
81 ));
84 function utf8_body($recipient)
86 $this->set(array(
87 'recipients' => $recipient,
88 'subject' => "testing utf-8 body",
89 'from' => "Foo áëô îü <extended@example.com>",
90 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
91 'cc' => "Foo áëô îü <extended@example.com>",
92 'bcc' => "Foo áëô îü <extended@example.com>",
93 'body' => "åœö blah",
94 'charset' => "UTF-8"
95 ));
98 function multipart_with_mime_version($recipient)
100 $this->set(array(
101 'recipients' => $recipient,
102 'subject' => "multipart with mime_version",
103 'from' => "test@example.com",
104 'sent_on' => Ak::getDate(strtotime('2004-12-12')),
105 'mime_version' => "1.1",
106 'content_type' => "multipart/alternative",
107 'parts' => array(
108 array('content_type' => 'text/plain', 'body' => 'blah'),
109 array('content_type' => 'text/html', 'body' => '<b>blah</b>'),
115 function multipart_with_utf8_subject($recipient)
117 $this->set(array(
118 'recipients' => $recipient,
119 'subject' => "Foo áëô îü",
120 'from' => "test@example.com",
121 'charset' => "UTF-8",
122 'parts' => array(
123 array('content_type' => 'text/plain', 'body' => 'blah'),
124 array('content_type' => 'text/html', 'body' => '<b>blah</b>'),
130 function explicitly_multipart_example($recipient, $content_type = null)
132 empty($content_type) ? null : $this->setContentType($content_type);
133 $this->set(array(
134 'recipients' => $recipient,
135 'subject' => "multipart example",
136 'from' => "test@example.com",
137 'body' => "plain text default",
138 'parts' => array('content_type' => 'text/html', 'body' => 'blah', 'charset' => 'iso-8859-1'),
139 'attachment' => array('content_type' => 'image/jpeg', 'filename'=> 'foo.jpg', 'body' => '123456789'),
144 function implicitly_multipart_example($recipient, $charset = null, $order = null)
146 empty($charset) ? null : $this->setCharset($charset);
147 empty($order) ? null : $this->setImplicitPartsOrder($order);
149 $this->set(array(
150 'recipients' => $recipient,
151 'subject' => "multipart example",
152 'from' => "test@example.com",
153 'body' => array('recipient' => $recipient)
157 function implicitly_multipart_with_utf8()
159 empty($charset) ? null : $this->setCharset($charset);
160 empty($order) ? null : $this->setImplicitPartsOrder($order);
162 $this->set(array(
163 'recipients' => 'no.one@example.com',
164 'subject' => "Foo áëô îü",
165 'from' => "some.one@example.com",
166 'body' => array('recipient' => "no.one@example.com"),
167 'template' => 'implicitly_multipart_example'
171 function html_mail($recipient)
173 $this->set(array(
174 'recipients' => $recipient,
175 'subject' => "html mail",
176 'from' => "test@example.com",
177 'body' => "<em>Emphasize</em> <strong>this</strong>",
178 'content_type' => 'text/html'
183 function html_mail_with_underscores()
185 $this->set(array(
186 'subject' => "html mail with underscores",
187 'body' => '<a href="http://google.com" target="_blank">_Google</a>'
192 function custom_template($recipient)
194 $this->set(array(
195 'recipients' => $recipient,
196 'subject' => "[Signed up] Welcome $recipient",
197 'from' => "system@example.com",
198 'body' => array('recipient' => $recipient),
199 'template' => 'signed_up'
203 function various_newlines($recipient)
205 $this->set(array(
206 'recipients' => $recipient,
207 'subject' => "various newlines",
208 'from' => "test@example.com",
209 'body' => "line #1\nline #2\rline #3\r\nline #4\r\r" .
210 "line #5\n\nline#6\r\n\r\nline #7"
214 function various_newlines_multipart($recipient)
216 $this->set(array(
217 'recipients' => $recipient,
218 'subject' => "various newlines multipart",
219 'from' => "test@example.com",
220 'content_type' => "multipart/alternative",
221 'parts' => array(
222 array('content_type' => 'text/plain', 'body' => "line #1\nline #2\rline #3\r\nline #4\r\r"),
223 array('content_type' => 'text/html', 'body' => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r"))
227 function nested_multipart($recipient)
229 $this->set(array(
230 'recipients' => $recipient,
231 'subject' => "nested multipart",
232 'from' => "test@example.com",
233 'content_type' => "multipart/mixed",
235 'parts' => array(
236 array(
237 'content_type' => 'multipart/alternative',
238 'content_disposition' => 'inline',
239 'headers' => array("Foo" => "bar"),
240 'parts' => array(
241 array('content_type' => 'text/plain', 'body' => "test text\nline #2"),
242 array('content_type' => 'text/html', 'body' => "<b>test</b> HTML<br/>\nline #2")
247 'attachment' => array(
248 'content_type' => 'application/octet-stream','filename' => 'test.txt', 'body' => "test abcdefghijklmnopqstuvwxyz"
253 function attachment_with_custom_header($recipient)
255 $this->set(array(
256 'recipients' => $recipient,
257 'subject' => "custom header in attachment",
258 'from' => "test@example.com",
259 'content_type' => "multipart/related",
261 'part' => array('content_type' => 'text/html', 'body' => 'yo'),
263 'attachment' => array(
264 'content_type' => 'image/jpeg','filename' => 'test.jpeg', 'body' => "i am not a real picture", 'headers' => array('Content-ID' => '<test@test.com>')
269 function unnamed_attachment($recipient)
271 $this->set(array(
272 'recipients' => $recipient,
273 'subject' => "unnamed attachment",
274 'from' => "test@example.com",
275 'content_type' => "multipart/mixed",
277 'part' => array('content_type' => 'text/plain', 'body' => 'hullo'),
279 'attachment' => array(
280 'content_type' => 'application/octet-stream','body' => "test abcdefghijklmnopqstuvwxyz"
285 function headers_with_nonalpha_chars($recipient)
287 $this->set(array(
288 'recipients' => $recipient,
289 'subject' => "nonalpha chars",
290 'from' => "One: Two <test@example.com>",
291 'cc' => "Three: Four <test@example.com>",
292 'bcc' => "Five: Six <test@example.com>",
293 'body' => "testing"));
297 function custom_content_type_attributes()
299 $this->set(array(
300 'recipients' => "no.one@example.com",
301 'subject' => "custom content types",
302 'from' => "some.one@example.com",
303 'content_type' => "text/plain; format=flowed",
304 'body' => "testing"
310 function alternative_message_from_templates($recipient, $include_logo = false, $include_external_image = false, $add_attachment = false)
312 $this->set(array(
313 'recipients' => $recipient,
314 'subject' => "Alternative message from template",
315 'from' => "some.one@example.com",
316 'body' => array('include_logo' => $include_logo, 'include_external_image' => $include_external_image)
321 * @todo Adding an attachment overides rendered views
323 if($add_attachment){
325 $this->addAttachment(array(
327 'content_type' => 'text/php',
328 'body' => '<?php ?>',
329 'filename' => 'test_mailer.php'
336 function &receive($raw_email)
338 $Mail =& parent::receive($raw_email);
339 $this->received_body = $Mail->body;
340 return $Mail;