xref: /dokuwiki/_test/tests/inc/mailer.test.php (revision 102cdbd7657b117b2967af069ab689838e74bdaf)
1cc92aca7SAndreas Gohr<?php
2cc92aca7SAndreas Gohr
3cc92aca7SAndreas Gohr/**
4cc92aca7SAndreas Gohr * Extends the mailer class to expose internal variables for testing
5cc92aca7SAndreas Gohr */
6cc92aca7SAndreas Gohrclass TestMailer extends Mailer {
7cc92aca7SAndreas Gohr    public function prop($name){
8cc92aca7SAndreas Gohr        return $this->$name;
9cc92aca7SAndreas Gohr    }
101f61f312SDominik Eckelmann
111f61f312SDominik Eckelmann    public function &propRef($name) {
121f61f312SDominik Eckelmann        return $this->$name;
131f61f312SDominik Eckelmann    }
141f61f312SDominik Eckelmann
151f61f312SDominik Eckelmann    public function prepareHeaders() {
161f61f312SDominik Eckelmann        return parent::prepareHeaders();
171f61f312SDominik Eckelmann    }
18b6c97c70SAndreas Gohr
19b6c97c70SAndreas Gohr    public function cleanHeaders() {
20b6c97c70SAndreas Gohr        parent::cleanHeaders();
21b6c97c70SAndreas Gohr    }
22b6c97c70SAndreas Gohr
23cc92aca7SAndreas Gohr}
24cc92aca7SAndreas Gohr
25*102cdbd7SLarsGit223/**
26*102cdbd7SLarsGit223 * @group mailer_class
27*102cdbd7SLarsGit223 */
28cc92aca7SAndreas Gohrclass mailer_test extends DokuWikiTest {
29cc92aca7SAndreas Gohr
30cc92aca7SAndreas Gohr
31cc92aca7SAndreas Gohr    function test_userheader(){
32cc92aca7SAndreas Gohr        $mail = new TestMailer();
33cc92aca7SAndreas Gohr        $headers = $mail->prop('headers');
34cc92aca7SAndreas Gohr        $this->assertArrayNotHasKey('X-Dokuwiki-User',$headers);
35cc92aca7SAndreas Gohr
36cc92aca7SAndreas Gohr        $_SERVER['REMOTE_USER'] = 'andi';
37cc92aca7SAndreas Gohr        $mail = new TestMailer();
38cc92aca7SAndreas Gohr        $headers = $mail->prop('headers');
39cc92aca7SAndreas Gohr        $this->assertArrayHasKey('X-Dokuwiki-User',$headers);
40cc92aca7SAndreas Gohr    }
41cc92aca7SAndreas Gohr
42cc92aca7SAndreas Gohr    function test_setHeader(){
43cc92aca7SAndreas Gohr        $mail = new TestMailer();
44cc92aca7SAndreas Gohr
45cc92aca7SAndreas Gohr        // check existance of default headers
46cc92aca7SAndreas Gohr        $headers = $mail->prop('headers');
47cc92aca7SAndreas Gohr        $this->assertArrayHasKey('X-Mailer',$headers);
48cc92aca7SAndreas Gohr        $this->assertArrayHasKey('X-Dokuwiki-Title',$headers);
49cc92aca7SAndreas Gohr        $this->assertArrayHasKey('X-Dokuwiki-Server',$headers);
50cc92aca7SAndreas Gohr        $this->assertArrayHasKey('X-Auto-Response-Suppress',$headers);
51cc92aca7SAndreas Gohr        $this->assertArrayHasKey('List-Id',$headers);
52cc92aca7SAndreas Gohr
53cc92aca7SAndreas Gohr        // set a bunch of test headers
54cc92aca7SAndreas Gohr        $mail->setHeader('test-header','bla');
55cc92aca7SAndreas Gohr        $mail->setHeader('to','A valid ASCII name <test@example.com>');
56c8d2e830SChristopher Smith        $mail->setHeader('from',"Thös ne\needs\x00serious cleaning\$§%.");
57c8d2e830SChristopher Smith        $mail->setHeader('bad',"Thös ne\needs\x00serious cleaning\$§%.",false);
58cc92aca7SAndreas Gohr        $mail->setHeader("weird\n*+\x00foo.-_@bar?",'now clean');
59cc92aca7SAndreas Gohr
60cc92aca7SAndreas Gohr        // are they set?
61cc92aca7SAndreas Gohr        $headers = $mail->prop('headers');
62cc92aca7SAndreas Gohr        $this->assertArrayHasKey('Test-Header',$headers);
63cc92aca7SAndreas Gohr        $this->assertEquals('bla',$headers['Test-Header']);
64cc92aca7SAndreas Gohr        $this->assertArrayHasKey('To',$headers);
65cc92aca7SAndreas Gohr        $this->assertEquals('A valid ASCII name <test@example.com>',$headers['To']);
66cc92aca7SAndreas Gohr        $this->assertArrayHasKey('From',$headers);
67cc92aca7SAndreas Gohr        $this->assertEquals('Ths neeedsserious cleaning.',$headers['From']);
68cc92aca7SAndreas Gohr        $this->assertArrayHasKey('Bad',$headers);
69d1612d99SAndreas Gohr        $this->assertEquals("Thös ne\needs\x00serious cleaning\$§%.",$headers['Bad']);
70cc92aca7SAndreas Gohr        $this->assertArrayHasKey('Weird+foo.-_@bar',$headers);
71cc92aca7SAndreas Gohr
72cc92aca7SAndreas Gohr        // unset a header again
73cc92aca7SAndreas Gohr        $mail->setHeader('test-header','');
74cc92aca7SAndreas Gohr        $headers = $mail->prop('headers');
75cc92aca7SAndreas Gohr        $this->assertArrayNotHasKey('Test-Header',$headers);
76cc92aca7SAndreas Gohr    }
77cc92aca7SAndreas Gohr
78b6c97c70SAndreas Gohr    function test_addresses(){
791d7c1f1bSYurii K        if (isWindows()) {
801d7c1f1bSYurii K            $this->markTestSkipped();
811d7c1f1bSYurii K        }
821d7c1f1bSYurii K
83b6c97c70SAndreas Gohr        $mail = new TestMailer();
84b6c97c70SAndreas Gohr
85b6c97c70SAndreas Gohr        $mail->to('andi@splitbrain.org');
86b6c97c70SAndreas Gohr        $mail->cleanHeaders();
87b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
88b6c97c70SAndreas Gohr        $this->assertEquals('andi@splitbrain.org', $headers['To']);
89b6c97c70SAndreas Gohr
90b6c97c70SAndreas Gohr        $mail->to('<andi@splitbrain.org>');
91b6c97c70SAndreas Gohr        $mail->cleanHeaders();
92b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
93b6c97c70SAndreas Gohr        $this->assertEquals('andi@splitbrain.org', $headers['To']);
94b6c97c70SAndreas Gohr
95b6c97c70SAndreas Gohr        $mail->to('Andreas Gohr <andi@splitbrain.org>');
96b6c97c70SAndreas Gohr        $mail->cleanHeaders();
97b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
98b6c97c70SAndreas Gohr        $this->assertEquals('Andreas Gohr <andi@splitbrain.org>', $headers['To']);
99b6c97c70SAndreas Gohr
100*102cdbd7SLarsGit223        $mail->to('"Andreas Gohr" <andi@splitbrain.org>');
101*102cdbd7SLarsGit223        $mail->cleanHeaders();
102*102cdbd7SLarsGit223        $headers = $mail->prop('headers');
103*102cdbd7SLarsGit223        $this->assertEquals('"Andreas Gohr" <andi@splitbrain.org>', $headers['To']);
104*102cdbd7SLarsGit223
105b6c97c70SAndreas Gohr        $mail->to('Andreas Gohr <andi@splitbrain.org> , foo <foo@example.com>');
106b6c97c70SAndreas Gohr        $mail->cleanHeaders();
107b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
108b6c97c70SAndreas Gohr        $this->assertEquals('Andreas Gohr <andi@splitbrain.org>, foo <foo@example.com>', $headers['To']);
109b6c97c70SAndreas Gohr
110*102cdbd7SLarsGit223        $mail->to('"Foo, Dr." <foo@example.com> , foo <foo@example.com>');
111*102cdbd7SLarsGit223        $mail->cleanHeaders();
112*102cdbd7SLarsGit223        $headers = $mail->prop('headers');
113*102cdbd7SLarsGit223        $this->assertEquals('=?UTF-8?B?IkZvbywgRHIuIg==?= <foo@example.com>, foo <foo@example.com>', $headers['To']);
114*102cdbd7SLarsGit223
115b6c97c70SAndreas Gohr        $mail->to('Möp <moep@example.com> , foo <foo@example.com>');
116b6c97c70SAndreas Gohr        $mail->cleanHeaders();
117b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
118b6c97c70SAndreas Gohr        $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
119b6c97c70SAndreas Gohr
120b6c97c70SAndreas Gohr        $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
121b6c97c70SAndreas Gohr        $mail->cleanHeaders();
122b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
123b6c97c70SAndreas Gohr        $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
124b6c97c70SAndreas Gohr
125b6c97c70SAndreas Gohr        $mail->to(array('Beet, L van <lvb@example.com>',' foo <foo@example.com>'));
126b6c97c70SAndreas Gohr        $mail->cleanHeaders();
127b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
128b6c97c70SAndreas Gohr        $this->assertEquals('=?UTF-8?B?QmVldCwgTCB2YW4=?= <lvb@example.com>, foo <foo@example.com>', $headers['To']);
129b6c97c70SAndreas Gohr
130b6c97c70SAndreas Gohr
131b6c97c70SAndreas Gohr    }
132b6c97c70SAndreas Gohr
133cc92aca7SAndreas Gohr    function test_simplemail(){
134cc92aca7SAndreas Gohr        global $conf;
135cc92aca7SAndreas Gohr        $conf['htmlmail'] = 0;
1369ea45836SChristopher Smith
1379ea45836SChristopher Smith        $mailbody = 'A test mail in ASCII';
138cc92aca7SAndreas Gohr        $mail = new TestMailer();
139cc92aca7SAndreas Gohr        $mail->to('test@example.com');
1409ea45836SChristopher Smith        $mail->setBody($mailbody);
141cc92aca7SAndreas Gohr
142cc92aca7SAndreas Gohr        $dump = $mail->dump();
1439ea45836SChristopher Smith
1449ea45836SChristopher Smith        // construct the expected mail body text - include the expected dokuwiki signature
1459ea45836SChristopher Smith        $replacements = $mail->prop('replacements');
1469ea45836SChristopher Smith        $expected_mail_body = chunk_split(base64_encode($mailbody.$replacements['text']['EMAILSIGNATURE']),72,MAILHEADER_EOL);
1479ea45836SChristopher Smith
148cc92aca7SAndreas Gohr        $this->assertNotRegexp('/Content-Type: multipart/',$dump);
149cc92aca7SAndreas Gohr        $this->assertRegexp('#Content-Type: text/plain; charset=UTF-8#',$dump);
1509ea45836SChristopher Smith        $this->assertRegexp('/'.preg_quote($expected_mail_body,'/').'/',$dump);
151cc92aca7SAndreas Gohr
152cc92aca7SAndreas Gohr        $conf['htmlmail'] = 1;
153cc92aca7SAndreas Gohr    }
154cc92aca7SAndreas Gohr
155cc92aca7SAndreas Gohr    function test_replacements(){
156cc92aca7SAndreas Gohr        $mail = new TestMailer();
157cc92aca7SAndreas Gohr
1589e01e280SChristopher Smith        $replacements = array( '@DATE@','@BROWSER@','@IPADDRESS@','@HOSTNAME@','@EMAILSIGNATURE@',
159cc92aca7SAndreas Gohr                               '@TITLE@','@DOKUWIKIURL@','@USER@','@NAME@','@MAIL@');
160cc92aca7SAndreas Gohr        $mail->setBody('A test mail in with replacements '.join(' ',$replacements));
161cc92aca7SAndreas Gohr
162cc92aca7SAndreas Gohr        $text = $mail->prop('text');
163cc92aca7SAndreas Gohr        $html = $mail->prop('html');
164cc92aca7SAndreas Gohr
165cc92aca7SAndreas Gohr        foreach($replacements as $repl){
166cc92aca7SAndreas Gohr            $this->assertNotRegexp("/$repl/",$text,"$repl replacement still in text");
167cc92aca7SAndreas Gohr            $this->assertNotRegexp("/$repl/",$html,"$repl replacement still in html");
168cc92aca7SAndreas Gohr        }
169cc92aca7SAndreas Gohr    }
170cc92aca7SAndreas Gohr
17191effd8dSDominik Eckelmann    /**
17291effd8dSDominik Eckelmann     * @see https://forum.dokuwiki.org/post/35822
17391effd8dSDominik Eckelmann     */
1741f61f312SDominik Eckelmann    function test_emptyBCCorCC() {
1751f61f312SDominik Eckelmann        $mail = new TestMailer();
1761f61f312SDominik Eckelmann        $headers = &$mail->propRef('headers');
1771f61f312SDominik Eckelmann        $headers['Bcc'] = '';
1781f61f312SDominik Eckelmann        $headers['Cc'] = '';
1791f61f312SDominik Eckelmann        $header = $mail->prepareHeaders();
1801f61f312SDominik Eckelmann        $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
1816be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.');
1826be717dbSMichael Hamann    }
1836be717dbSMichael Hamann
1846be717dbSMichael Hamann    function test_nullTOorCCorBCC() {
1856be717dbSMichael Hamann        $mail = new TestMailer();
1866be717dbSMichael Hamann        $headers = &$mail->propRef('headers');
1876be717dbSMichael Hamann        $headers['Bcc'] = NULL;
1886be717dbSMichael Hamann        $headers['Cc'] = NULL;
1896be717dbSMichael Hamann        $headers['To'] = NULL;
1906be717dbSMichael Hamann        $header = $mail->prepareHeaders();
1916be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
1926be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.');
1936be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)To: (\n|$)/', $header), 'To found in headers.');
1941f61f312SDominik Eckelmann    }
1950ee5ed1eSAndreas Gohr
1960ee5ed1eSAndreas Gohr    /**
1970ee5ed1eSAndreas Gohr     * @group internet
1980ee5ed1eSAndreas Gohr     */
1990ee5ed1eSAndreas Gohr    function test_lint(){
2000ee5ed1eSAndreas Gohr        // prepare a simple multipart message
2010ee5ed1eSAndreas Gohr        $mail = new TestMailer();
2020ee5ed1eSAndreas Gohr        $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
203d6e04b60SAndreas Gohr        $mail->from('Me <test@example.com>');
2040ee5ed1eSAndreas Gohr        $mail->subject('This is a töst');
2050ee5ed1eSAndreas Gohr        $mail->setBody('Hello Wörld,
2060ee5ed1eSAndreas Gohr
2070ee5ed1eSAndreas Gohr        please don\'t burn, okay?
2080ee5ed1eSAndreas Gohr        ');
209ec82d005SAndreas Gohr        $mail->attachContent('some test data', 'text/plain', 'a text.txt');
2100ee5ed1eSAndreas Gohr        $msg = $mail->dump();
2110ee5ed1eSAndreas Gohr        $msglines = explode("\n", $msg);
2120ee5ed1eSAndreas Gohr
213d6e04b60SAndreas Gohr        //echo $msg;
214d6e04b60SAndreas Gohr
2150ee5ed1eSAndreas Gohr        // ask message lint if it is okay
2160ee5ed1eSAndreas Gohr        $html = new HTTPClient();
2177468fb90SAndreas Gohr        $results = $html->post('https://tools.ietf.org/tools/msglint/msglint', array('msg'=>$msg));
21895e6ded1SAndreas Gohr        if($results === false) {
21995e6ded1SAndreas Gohr            $this->markTestSkipped('no response from validator');
22095e6ded1SAndreas Gohr            return;
22195e6ded1SAndreas Gohr        }
2220ee5ed1eSAndreas Gohr
2230ee5ed1eSAndreas Gohr        // parse the result lines
2240ee5ed1eSAndreas Gohr        $lines = explode("\n", $results);
2250ee5ed1eSAndreas Gohr        $rows  = count($lines);
2260ee5ed1eSAndreas Gohr        $i=0;
2270ee5ed1eSAndreas Gohr        while(trim($lines[$i]) != '-----------' && $i<$rows) $i++; //skip preamble
2280ee5ed1eSAndreas Gohr        for($i=$i+1; $i<$rows; $i++){
2290ee5ed1eSAndreas Gohr            $line = trim($lines[$i]);
2300ee5ed1eSAndreas Gohr            if($line == '-----------') break; //skip appendix
2310ee5ed1eSAndreas Gohr
2320ee5ed1eSAndreas Gohr            // get possible continuation of the line
2330ee5ed1eSAndreas Gohr            while($lines[$i+1][0] == ' '){
2340ee5ed1eSAndreas Gohr                $line .= ' '.trim($lines[$i+1]);
2350ee5ed1eSAndreas Gohr                $i++;
2360ee5ed1eSAndreas Gohr            }
2370ee5ed1eSAndreas Gohr
2380ee5ed1eSAndreas Gohr            // check the line for errors
239ec82d005SAndreas Gohr            if(substr($line,0,5) == 'ERROR' || substr($line,0,7) == 'WARNING'){
240d6e04b60SAndreas Gohr                // ignore some errors
241d6e04b60SAndreas Gohr                if(strpos($line, "missing mandatory header 'return-path'")) continue; #set by MDA
242acb389a8SAndreas Gohr                if(strpos($line, "bare newline in text body decoded")) continue; #we don't send mail bodies as CRLF, yet
243acb389a8SAndreas Gohr                if(strpos($line, "last decoded line too long")) continue; #we don't send mail bodies as CRLF, yet
244d6e04b60SAndreas Gohr
2450ee5ed1eSAndreas Gohr                // get the context in which the error occured
2460ee5ed1eSAndreas Gohr                $errorin = '';
2470ee5ed1eSAndreas Gohr                if(preg_match('/line (\d+)$/', $line, $m)){
2480ee5ed1eSAndreas Gohr                    $errorin .= "\n".$msglines[$m[1] - 1];
2490ee5ed1eSAndreas Gohr                }
2500ee5ed1eSAndreas Gohr                if(preg_match('/lines (\d+)-(\d+)$/', $line, $m)){
2510ee5ed1eSAndreas Gohr                    for($x=$m[1]-1; $x<$m[2]; $x++){
2520ee5ed1eSAndreas Gohr                        $errorin .= "\n".$msglines[$x];
2530ee5ed1eSAndreas Gohr                    }
2540ee5ed1eSAndreas Gohr                }
2550ee5ed1eSAndreas Gohr
2560ee5ed1eSAndreas Gohr                // raise the error
2570ee5ed1eSAndreas Gohr                throw new Exception($line.$errorin);
2580ee5ed1eSAndreas Gohr            }
2590ee5ed1eSAndreas Gohr        }
2600ee5ed1eSAndreas Gohr
2611bff2abaSAndreas Gohr        $this->assertTrue(true); // avoid being marked as risky for having no assertion
2620ee5ed1eSAndreas Gohr    }
263774514c9SGerrit Uitslag
264774514c9SGerrit Uitslag    function test_simplemailsignature() {
265774514c9SGerrit Uitslag        global $conf;
266774514c9SGerrit Uitslag        $conf['htmlmail'] = 0;
267774514c9SGerrit Uitslag
268774514c9SGerrit Uitslag        $mailbody = 'A test mail in ASCII';
269774514c9SGerrit Uitslag        $signature = "\n-- \n" . 'This mail was generated by DokuWiki at' . "\n" . DOKU_URL . "\n";
270774514c9SGerrit Uitslag        $mail = new TestMailer();
271774514c9SGerrit Uitslag        $mail->to('test@example.com');
272774514c9SGerrit Uitslag        $mail->setBody($mailbody);
273774514c9SGerrit Uitslag
274774514c9SGerrit Uitslag        $dump = $mail->dump();
275774514c9SGerrit Uitslag
276774514c9SGerrit Uitslag        // construct the expected mail body text - include the expected dokuwiki signature
277774514c9SGerrit Uitslag        $expected_mail_body = chunk_split(base64_encode($mailbody . $signature), 72, MAILHEADER_EOL);
278774514c9SGerrit Uitslag        $this->assertRegexp('/' . preg_quote($expected_mail_body, '/') . '/', $dump);
279774514c9SGerrit Uitslag
280774514c9SGerrit Uitslag        $conf['htmlmail'] = 1;
281774514c9SGerrit Uitslag    }
282774514c9SGerrit Uitslag
283774514c9SGerrit Uitslag    function test_htmlmailsignature() {
284774514c9SGerrit Uitslag        $mailbody_text = 'A test mail in ASCII :)';
285774514c9SGerrit Uitslag        $mailbody_html = 'A test mail in <strong>html</strong>';
286774514c9SGerrit Uitslag        $htmlmsg_expected = '<html>
287774514c9SGerrit Uitslag<head>
288774514c9SGerrit Uitslag    <title>My Test Wiki</title>
289774514c9SGerrit Uitslag    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
290774514c9SGerrit Uitslag</head>
291774514c9SGerrit Uitslag<body>
292774514c9SGerrit Uitslag
293774514c9SGerrit UitslagA test mail in <strong>html</strong>
294774514c9SGerrit Uitslag
295774514c9SGerrit Uitslag<br /><hr />
296f3cd98a0SGerrit Uitslag<small>This mail was generated by DokuWiki at<br /><a href="' . DOKU_URL . '">' . DOKU_URL . '</a></small>
297774514c9SGerrit Uitslag</body>
298774514c9SGerrit Uitslag</html>
299774514c9SGerrit Uitslag';
300774514c9SGerrit Uitslag
301774514c9SGerrit Uitslag        $mail = new TestMailer();
302774514c9SGerrit Uitslag        $mail->to('test@example.com');
303774514c9SGerrit Uitslag        $mail->setBody($mailbody_text, null, null, $mailbody_html);
304774514c9SGerrit Uitslag
305774514c9SGerrit Uitslag        $dump = $mail->dump();
306774514c9SGerrit Uitslag
307774514c9SGerrit Uitslag        // construct the expected mail body text - include the expected dokuwiki signature
308774514c9SGerrit Uitslag        $expected_mail_body = chunk_split(base64_encode($htmlmsg_expected), 72, MAILHEADER_EOL);
309774514c9SGerrit Uitslag
310774514c9SGerrit Uitslag        $this->assertRegexp('/Content-Type: multipart/', $dump);
311774514c9SGerrit Uitslag        $this->assertRegexp('#Content-Type: text/plain; charset=UTF-8#', $dump);
312774514c9SGerrit Uitslag        $this->assertRegexp('/' . preg_quote($expected_mail_body, '/') . '/', $dump);
313774514c9SGerrit Uitslag
314774514c9SGerrit Uitslag    }
315774514c9SGerrit Uitslag
316774514c9SGerrit Uitslag    function test_htmlmailsignaturecustom() {
317774514c9SGerrit Uitslag        global $lang;
318774514c9SGerrit Uitslag        $lang['email_signature_html'] = 'Official message from your DokuWiki @DOKUWIKIURL@<br />Created by wonderful mail class <a href="https://www.dokuwiki.org/devel:mail">https://www.dokuwiki.org/devel:mail</a>';
319774514c9SGerrit Uitslag
320774514c9SGerrit Uitslag        $mailbody_text = 'A test mail in ASCII :)';
321774514c9SGerrit Uitslag        $mailbody_html = 'A test mail in <strong>html</strong>';
322774514c9SGerrit Uitslag        $htmlmsg_expected = '<html>
323774514c9SGerrit Uitslag<head>
324774514c9SGerrit Uitslag    <title>My Test Wiki</title>
325774514c9SGerrit Uitslag    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
326774514c9SGerrit Uitslag</head>
327774514c9SGerrit Uitslag<body>
328774514c9SGerrit Uitslag
329774514c9SGerrit UitslagA test mail in <strong>html</strong>
330774514c9SGerrit Uitslag
331774514c9SGerrit Uitslag<br /><hr />
332f3cd98a0SGerrit Uitslag<small>Official message from your DokuWiki <a href="' . DOKU_URL . '">' . DOKU_URL . '</a><br />Created by wonderful mail class <a href="https://www.dokuwiki.org/devel:mail">https://www.dokuwiki.org/devel:mail</a></small>
333774514c9SGerrit Uitslag</body>
334774514c9SGerrit Uitslag</html>
335774514c9SGerrit Uitslag';
336774514c9SGerrit Uitslag
337774514c9SGerrit Uitslag        $mail = new TestMailer();
338774514c9SGerrit Uitslag        $mail->to('test@example.com');
339774514c9SGerrit Uitslag        $mail->setBody($mailbody_text, null, null, $mailbody_html);
340774514c9SGerrit Uitslag
341774514c9SGerrit Uitslag        $dump = $mail->dump();
342774514c9SGerrit Uitslag
343774514c9SGerrit Uitslag        // construct the expected mail body text - include the expected dokuwiki signature
344774514c9SGerrit Uitslag        $replacements = $mail->prop('replacements');
345774514c9SGerrit Uitslag        $expected_mail_body = chunk_split(base64_encode($htmlmsg_expected), 72, MAILHEADER_EOL);
346774514c9SGerrit Uitslag
347774514c9SGerrit Uitslag        $this->assertRegexp('/' . preg_quote($expected_mail_body, '/') . '/', $dump);
348774514c9SGerrit Uitslag
349774514c9SGerrit Uitslag    }
350*102cdbd7SLarsGit223
351*102cdbd7SLarsGit223    function test_getCleanName() {
352*102cdbd7SLarsGit223        $mail = new TestMailer();
353*102cdbd7SLarsGit223        $name = $mail->getCleanName('Foo Bar');
354*102cdbd7SLarsGit223        $this->assertEquals('Foo Bar', $name);
355*102cdbd7SLarsGit223        $name = $mail->getCleanName('Foo, Bar');
356*102cdbd7SLarsGit223        $this->assertEquals('"Foo, Bar"', $name);
357*102cdbd7SLarsGit223        $name = $mail->getCleanName('Foo" Bar');
358*102cdbd7SLarsGit223        $this->assertEquals('"Foo\" Bar"', $name);
359*102cdbd7SLarsGit223    }
360cc92aca7SAndreas Gohr}
361cc92aca7SAndreas Gohr//Setup VIM: ex: et ts=4 :
362