/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to includes/PHPMailer-Lite_v5.1/test/phpmailerTest.php

  • Committer: Suren A. Chilingaryan
  • Date: 2011-01-26 02:48:39 UTC
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: csa@dside.dyndns.org-20110126024839-nv6qp2ie9stmd2dn
Support of Appled devices by Toni Pirhonen

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
* PHPMailer - PHP email transport unit tests
 
4
* Before running these tests you need to install PHPUnit 3.3 or later through pear, like this:
 
5
*   pear install "channel://pear.phpunit.de/PHPUnit"
 
6
* Then run the tests like this:
 
7
*   phpunit phpmailerTest
 
8
* @package PHPMailer
 
9
* @author Andy Prevost
 
10
* @author Marcus Bointon
 
11
* @copyright 2004 - 2009 Andy Prevost
 
12
* @version $Id: phpmailerTest.php 444 2009-05-05 11:22:26Z coolbru $
 
13
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 
14
*/
 
15
 
 
16
require 'PHPUnit/Framework.php';
 
17
 
 
18
$INCLUDE_DIR = "../";
 
19
 
 
20
require $INCLUDE_DIR . 'class.phpmailer-lite.php';
 
21
error_reporting(E_ALL);
 
22
 
 
23
/**
 
24
* PHPMailer - PHP email transport unit test class
 
25
* Performs authentication tests
 
26
*/
 
27
class phpmailerTest extends PHPUnit_Framework_TestCase {
 
28
    /**
 
29
     * Holds the default phpmailer instance.
 
30
     * @private
 
31
     * @type object
 
32
     */
 
33
    var $Mail = false;
 
34
 
 
35
    /**
 
36
     * Holds the SMTP mail host.
 
37
     * @public
 
38
     * @type string
 
39
     */
 
40
    var $Host = "";
 
41
 
 
42
    /**
 
43
     * Holds the change log.
 
44
     * @private
 
45
     * @type string array
 
46
     */
 
47
    var $ChangeLog = array();
 
48
 
 
49
     /**
 
50
     * Holds the note log.
 
51
     * @private
 
52
     * @type string array
 
53
     */
 
54
    var $NoteLog = array();
 
55
 
 
56
    /**
 
57
     * Run before each test is started.
 
58
     */
 
59
    function setUp() {
 
60
        global $INCLUDE_DIR;
 
61
 
 
62
  @include './testbootstrap.php'; //Overrides go in here
 
63
 
 
64
        $this->Mail = new PHPMailer();
 
65
 
 
66
        $this->Mail->Priority = 3;
 
67
        $this->Mail->Encoding = "8bit";
 
68
        $this->Mail->CharSet = "iso-8859-1";
 
69
        if (array_key_exists('mail_from', $_REQUEST)) {
 
70
          $this->Mail->From = $_REQUEST['mail_from'];
 
71
      } else {
 
72
          $this->Mail->From = 'unit_test@phpmailer.sf.net';
 
73
      }
 
74
        $this->Mail->FromName = "Unit Tester";
 
75
        $this->Mail->Sender = "";
 
76
        $this->Mail->Subject = "Unit Test";
 
77
        $this->Mail->Body = "";
 
78
        $this->Mail->AltBody = "";
 
79
        $this->Mail->WordWrap = 0;
 
80
        if (array_key_exists('mail_host', $_REQUEST)) {
 
81
          $this->Mail->Host = $_REQUEST['mail_host'];
 
82
      } else {
 
83
          $this->Mail->Host = 'mail.example.com';
 
84
      }
 
85
        $this->Mail->Port = 25;
 
86
        $this->Mail->Helo = "localhost.localdomain";
 
87
        $this->Mail->SMTPAuth = false;
 
88
        $this->Mail->Username = "";
 
89
        $this->Mail->Password = "";
 
90
        $this->Mail->PluginDir = $INCLUDE_DIR;
 
91
    $this->Mail->AddReplyTo("no_reply@phpmailer.sf.net", "Reply Guy");
 
92
        $this->Mail->Sender = "unit_test@phpmailer.sf.net";
 
93
 
 
94
        if(strlen($this->Mail->Host) > 0) {
 
95
            $this->Mail->Mailer = "smtp";
 
96
        } else {
 
97
            $this->Mail->Mailer = "mail";
 
98
            $this->Sender = "unit_test@phpmailer.sf.net";
 
99
        }
 
100
 
 
101
        if (array_key_exists('mail_to', $_REQUEST)) {
 
102
          $this->SetAddress($_REQUEST['mail_to'], 'Test User', 'to');
 
103
      }
 
104
        if (array_key_exists('mail_cc', $_REQUEST) and strlen($_REQUEST['mail_cc']) > 0) {
 
105
          $this->SetAddress($_REQUEST['mail_cc'], 'Carbon User', 'cc');
 
106
      }
 
107
    }
 
108
 
 
109
    /**
 
110
     * Run after each test is completed.
 
111
     */
 
112
    function tearDown() {
 
113
        // Clean global variables
 
114
        $this->Mail = NULL;
 
115
        $this->ChangeLog = array();
 
116
        $this->NoteLog = array();
 
117
    }
 
118
 
 
119
 
 
120
    /**
 
121
     * Build the body of the message in the appropriate format.
 
122
     * @private
 
123
     * @returns void
 
124
     */
 
125
    function BuildBody() {
 
126
        $this->CheckChanges();
 
127
 
 
128
        // Determine line endings for message
 
129
        if($this->Mail->ContentType == "text/html" || strlen($this->Mail->AltBody) > 0)
 
130
        {
 
131
            $eol = "<br/>";
 
132
            $bullet = "<li>";
 
133
            $bullet_start = "<ul>";
 
134
            $bullet_end = "</ul>";
 
135
        }
 
136
        else
 
137
        {
 
138
            $eol = "\n";
 
139
            $bullet = " - ";
 
140
            $bullet_start = "";
 
141
            $bullet_end = "";
 
142
        }
 
143
 
 
144
        $ReportBody = "";
 
145
 
 
146
        $ReportBody .= "---------------------" . $eol;
 
147
        $ReportBody .= "Unit Test Information" . $eol;
 
148
        $ReportBody .= "---------------------" . $eol;
 
149
        $ReportBody .= "phpmailer version: " . PHPMailer::VERSION . $eol;
 
150
        $ReportBody .= "Content Type: " . $this->Mail->ContentType . $eol;
 
151
 
 
152
        if(strlen($this->Mail->Host) > 0)
 
153
            $ReportBody .= "Host: " . $this->Mail->Host . $eol;
 
154
 
 
155
        // If attachments then create an attachment list
 
156
        $attachments = $this->Mail->GetAttachments();
 
157
        if(count($attachments) > 0)
 
158
        {
 
159
            $ReportBody .= "Attachments:" . $eol;
 
160
            $ReportBody .= $bullet_start;
 
161
            foreach($attachments as $attachment) {
 
162
                $ReportBody .= $bullet . "Name: " . $attachment[1] . ", ";
 
163
                $ReportBody .= "Encoding: " . $attachment[3] . ", ";
 
164
                $ReportBody .= "Type: " . $attachment[4] . $eol;
 
165
            }
 
166
            $ReportBody .= $bullet_end . $eol;
 
167
        }
 
168
 
 
169
        // If there are changes then list them
 
170
        if(count($this->ChangeLog) > 0)
 
171
        {
 
172
            $ReportBody .= "Changes" . $eol;
 
173
            $ReportBody .= "-------" . $eol;
 
174
 
 
175
            $ReportBody .= $bullet_start;
 
176
            for($i = 0; $i < count($this->ChangeLog); $i++)
 
177
            {
 
178
                $ReportBody .= $bullet . $this->ChangeLog[$i][0] . " was changed to [" .
 
179
                               $this->ChangeLog[$i][1] . "]" . $eol;
 
180
            }
 
181
            $ReportBody .= $bullet_end . $eol . $eol;
 
182
        }
 
183
 
 
184
        // If there are notes then list them
 
185
        if(count($this->NoteLog) > 0)
 
186
        {
 
187
            $ReportBody .= "Notes" . $eol;
 
188
            $ReportBody .= "-----" . $eol;
 
189
 
 
190
            $ReportBody .= $bullet_start;
 
191
            for($i = 0; $i < count($this->NoteLog); $i++)
 
192
            {
 
193
                $ReportBody .= $bullet . $this->NoteLog[$i] . $eol;
 
194
            }
 
195
            $ReportBody .= $bullet_end;
 
196
        }
 
197
 
 
198
        // Re-attach the original body
 
199
        $this->Mail->Body .= $eol . $eol . $ReportBody;
 
200
    }
 
201
 
 
202
    /**
 
203
     * Check which default settings have been changed for the report.
 
204
     * @private
 
205
     * @returns void
 
206
     */
 
207
    function CheckChanges() {
 
208
        if($this->Mail->Priority != 3)
 
209
            $this->AddChange("Priority", $this->Mail->Priority);
 
210
        if($this->Mail->Encoding != "8bit")
 
211
            $this->AddChange("Encoding", $this->Mail->Encoding);
 
212
        if($this->Mail->CharSet != "iso-8859-1")
 
213
            $this->AddChange("CharSet", $this->Mail->CharSet);
 
214
        if($this->Mail->Sender != "")
 
215
            $this->AddChange("Sender", $this->Mail->Sender);
 
216
        if($this->Mail->WordWrap != 0)
 
217
            $this->AddChange("WordWrap", $this->Mail->WordWrap);
 
218
        if($this->Mail->Mailer != "mail")
 
219
            $this->AddChange("Mailer", $this->Mail->Mailer);
 
220
        if($this->Mail->Port != 25)
 
221
            $this->AddChange("Port", $this->Mail->Port);
 
222
        if($this->Mail->Helo != "localhost.localdomain")
 
223
            $this->AddChange("Helo", $this->Mail->Helo);
 
224
        if($this->Mail->SMTPAuth)
 
225
            $this->AddChange("SMTPAuth", "true");
 
226
    }
 
227
 
 
228
    /**
 
229
     * Adds a change entry.
 
230
     * @private
 
231
     * @returns void
 
232
     */
 
233
    function AddChange($sName, $sNewValue) {
 
234
        $cur = count($this->ChangeLog);
 
235
        $this->ChangeLog[$cur][0] = $sName;
 
236
        $this->ChangeLog[$cur][1] = $sNewValue;
 
237
    }
 
238
 
 
239
    /**
 
240
     * Adds a simple note to the message.
 
241
     * @public
 
242
     * @returns void
 
243
     */
 
244
    function AddNote($sValue) {
 
245
        $this->NoteLog[] = $sValue;
 
246
    }
 
247
 
 
248
    /**
 
249
     * Adds all of the addresses
 
250
     * @public
 
251
     * @returns void
 
252
     */
 
253
    function SetAddress($sAddress, $sName = "", $sType = "to") {
 
254
        switch($sType)
 
255
        {
 
256
            case "to":
 
257
                return $this->Mail->AddAddress($sAddress, $sName);
 
258
            case "cc":
 
259
                return $this->Mail->AddCC($sAddress, $sName);
 
260
            case "bcc":
 
261
                return $this->Mail->AddBCC($sAddress, $sName);
 
262
        }
 
263
    }
 
264
 
 
265
    /////////////////////////////////////////////////
 
266
    // UNIT TESTS
 
267
    /////////////////////////////////////////////////
 
268
 
 
269
    /**
 
270
     * Try a plain message.
 
271
     */
 
272
    function test_WordWrap() {
 
273
 
 
274
        $this->Mail->WordWrap = 40;
 
275
        $my_body = "Here is the main body of this message.  It should " .
 
276
                   "be quite a few lines.  It should be wrapped at the " .
 
277
                   "40 characters.  Make sure that it is.";
 
278
        $nBodyLen = strlen($my_body);
 
279
        $my_body .= "\n\nThis is the above body length: " . $nBodyLen;
 
280
 
 
281
        $this->Mail->Body = $my_body;
 
282
        $this->Mail->Subject .= ": Wordwrap";
 
283
 
 
284
        $this->BuildBody();
 
285
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
286
    }
 
287
 
 
288
    /**
 
289
     * Try a plain message.
 
290
     */
 
291
    function test_Low_Priority() {
 
292
 
 
293
        $this->Mail->Priority = 5;
 
294
        $this->Mail->Body = "Here is the main body.  There should be " .
 
295
                            "a reply to address in this message.";
 
296
        $this->Mail->Subject .= ": Low Priority";
 
297
        $this->Mail->AddReplyTo("nobody@nobody.com", "Nobody (Unit Test)");
 
298
 
 
299
        $this->BuildBody();
 
300
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
301
    }
 
302
 
 
303
    /**
 
304
     * Simple plain file attachment test.
 
305
     */
 
306
    function test_Multiple_Plain_FileAttachment() {
 
307
 
 
308
        $this->Mail->Body = "Here is the text body";
 
309
        $this->Mail->Subject .= ": Plain + Multiple FileAttachments";
 
310
 
 
311
        if(!$this->Mail->AddAttachment("test.png"))
 
312
        {
 
313
            $this->assertTrue(false, $this->Mail->ErrorInfo);
 
314
            return;
 
315
        }
 
316
 
 
317
        if(!$this->Mail->AddAttachment(__FILE__, "test.txt"))
 
318
        {
 
319
            $this->assertTrue(false, $this->Mail->ErrorInfo);
 
320
            return;
 
321
        }
 
322
 
 
323
        $this->BuildBody();
 
324
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
325
    }
 
326
 
 
327
    /**
 
328
     * Simple plain string attachment test.
 
329
     */
 
330
    function test_Plain_StringAttachment() {
 
331
 
 
332
        $this->Mail->Body = "Here is the text body";
 
333
        $this->Mail->Subject .= ": Plain + StringAttachment";
 
334
 
 
335
        $sAttachment = "These characters are the content of the " .
 
336
                       "string attachment.\nThis might be taken from a ".
 
337
                       "database or some other such thing. ";
 
338
 
 
339
        $this->Mail->AddStringAttachment($sAttachment, "string_attach.txt");
 
340
 
 
341
        $this->BuildBody();
 
342
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
343
    }
 
344
 
 
345
    /**
 
346
     * Plain quoted-printable message.
 
347
     */
 
348
    function test_Quoted_Printable() {
 
349
 
 
350
        $this->Mail->Body = "Here is the main body";
 
351
        $this->Mail->Subject .= ": Plain + Quoted-printable";
 
352
        $this->Mail->Encoding = "quoted-printable";
 
353
 
 
354
        $this->BuildBody();
 
355
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
356
 
 
357
  //Check that a quoted printable encode and decode results in the same as went in
 
358
  $t = substr(file_get_contents(__FILE__), 0, 1024); //Just pick a chunk of this file as test content
 
359
  $this->assertEquals($t, quoted_printable_decode($this->Mail->EncodeQP($t)), 'QP encoding round-trip failed');
 
360
        //$this->assertEquals($t, quoted_printable_decode($this->Mail->EncodeQPphp($t)), 'Native PHP QP encoding round-trip failed'); //TODO the PHP qp encoder is quite broken
 
361
 
 
362
    }
 
363
 
 
364
    /**
 
365
     * Try a plain message.
 
366
     */
 
367
    function test_Html() {
 
368
 
 
369
        $this->Mail->IsHTML(true);
 
370
        $this->Mail->Subject .= ": HTML only";
 
371
 
 
372
        $this->Mail->Body = "This is a <b>test message</b> written in HTML. </br>" .
 
373
                            "Go to <a href=\"http://phpmailer.sourceforge.net/\">" .
 
374
                            "http://phpmailer.sourceforge.net/</a> for new versions of " .
 
375
                            "phpmailer.  <p/> Thank you!";
 
376
 
 
377
        $this->BuildBody();
 
378
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
379
    }
 
380
 
 
381
    /**
 
382
     * Simple HTML and attachment test
 
383
     */
 
384
    function test_HTML_Attachment() {
 
385
 
 
386
        $this->Mail->Body = "This is the <b>HTML</b> part of the email.";
 
387
        $this->Mail->Subject .= ": HTML + Attachment";
 
388
        $this->Mail->IsHTML(true);
 
389
 
 
390
        if(!$this->Mail->AddAttachment(__FILE__, "test_attach.txt"))
 
391
        {
 
392
            $this->assertTrue(false, $this->Mail->ErrorInfo);
 
393
            return;
 
394
        }
 
395
 
 
396
        $this->BuildBody();
 
397
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
398
    }
 
399
 
 
400
    /**
 
401
     * An embedded attachment test.
 
402
     */
 
403
    function test_Embedded_Image() {
 
404
 
 
405
        $this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" .
 
406
                     "Here is an image!</a>";
 
407
        $this->Mail->Subject .= ": Embedded Image";
 
408
        $this->Mail->IsHTML(true);
 
409
 
 
410
        if(!$this->Mail->AddEmbeddedImage("test.png", "my-attach", "test.png",
 
411
                                          "base64", "image/png"))
 
412
        {
 
413
            $this->assertTrue(false, $this->Mail->ErrorInfo);
 
414
            return;
 
415
        }
 
416
 
 
417
        $this->BuildBody();
 
418
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
419
  //For code coverage
 
420
  $this->Mail->AddEmbeddedImage('thisfiledoesntexist', 'xyz'); //Non-existent file
 
421
  $this->Mail->AddEmbeddedImage(__FILE__, '123'); //Missing name
 
422
 
 
423
    }
 
424
 
 
425
    /**
 
426
     * An embedded attachment test.
 
427
     */
 
428
    function test_Multi_Embedded_Image() {
 
429
 
 
430
        $this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" .
 
431
                     "Here is an image!</a>";
 
432
        $this->Mail->Subject .= ": Embedded Image + Attachment";
 
433
        $this->Mail->IsHTML(true);
 
434
 
 
435
        if(!$this->Mail->AddEmbeddedImage("test.png", "my-attach", "test.png",
 
436
                                          "base64", "image/png"))
 
437
        {
 
438
            $this->assertTrue(false, $this->Mail->ErrorInfo);
 
439
            return;
 
440
        }
 
441
 
 
442
        if(!$this->Mail->AddAttachment(__FILE__, "test.txt"))
 
443
        {
 
444
            $this->assertTrue(false, $this->Mail->ErrorInfo);
 
445
            return;
 
446
        }
 
447
 
 
448
        $this->BuildBody();
 
449
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
450
    }
 
451
 
 
452
    /**
 
453
     * Simple multipart/alternative test.
 
454
     */
 
455
    function test_AltBody() {
 
456
 
 
457
        $this->Mail->Body = "This is the <b>HTML</b> part of the email.";
 
458
        $this->Mail->AltBody = "Here is the text body of this message.  " .
 
459
                   "It should be quite a few lines.  It should be wrapped at the " .
 
460
                   "40 characters.  Make sure that it is.";
 
461
        $this->Mail->WordWrap = 40;
 
462
        $this->AddNote("This is a mulipart alternative email");
 
463
        $this->Mail->Subject .= ": AltBody + Word Wrap";
 
464
 
 
465
        $this->BuildBody();
 
466
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
467
    }
 
468
 
 
469
    /**
 
470
     * Simple HTML and attachment test
 
471
     */
 
472
    function test_AltBody_Attachment() {
 
473
 
 
474
        $this->Mail->Body = "This is the <b>HTML</b> part of the email.";
 
475
        $this->Mail->AltBody = "This is the text part of the email.";
 
476
        $this->Mail->Subject .= ": AltBody + Attachment";
 
477
        $this->Mail->IsHTML(true);
 
478
 
 
479
        if(!$this->Mail->AddAttachment(__FILE__, "test_attach.txt"))
 
480
        {
 
481
            $this->assertTrue(false, $this->Mail->ErrorInfo);
 
482
            return;
 
483
        }
 
484
 
 
485
        $this->BuildBody();
 
486
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
487
        if (is_writable('.')) {
 
488
            file_put_contents('message.txt', $this->Mail->CreateHeader() . $this->Mail->CreateBody());
 
489
        } else {
 
490
            $this->assertTrue(false, 'Could not write local file - check permissions');
 
491
        }
 
492
    }
 
493
 
 
494
    function test_MultipleSend() {
 
495
        $this->Mail->Body = "Sending two messages without keepalive";
 
496
        $this->BuildBody();
 
497
        $subject = $this->Mail->Subject;
 
498
 
 
499
        $this->Mail->Subject = $subject . ": SMTP 1";
 
500
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
501
 
 
502
        $this->Mail->Subject = $subject . ": SMTP 2";
 
503
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
504
    }
 
505
 
 
506
    function test_SendmailSend() {
 
507
        $this->Mail->Body = "Sending via sendmail";
 
508
        $this->BuildBody();
 
509
        $subject = $this->Mail->Subject;
 
510
 
 
511
        $this->Mail->Subject = $subject . ": sendmail";
 
512
  $this->Mail->IsSendmail();
 
513
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
514
    }
 
515
 
 
516
    function test_MailSend() {
 
517
        $this->Mail->Body = "Sending via mail()";
 
518
        $this->BuildBody();
 
519
        $subject = $this->Mail->Subject;
 
520
 
 
521
        $this->Mail->Subject = $subject . ": mail()";
 
522
  $this->Mail->IsMail();
 
523
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
524
    }
 
525
 
 
526
    function test_SmtpKeepAlive() {
 
527
        $this->Mail->Body = "This was done using the SMTP keep-alive.";
 
528
        $this->BuildBody();
 
529
        $subject = $this->Mail->Subject;
 
530
 
 
531
        $this->Mail->SMTPKeepAlive = true;
 
532
        $this->Mail->Subject = $subject . ": SMTP keep-alive 1";
 
533
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
534
 
 
535
        $this->Mail->Subject = $subject . ": SMTP keep-alive 2";
 
536
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
537
        $this->Mail->SmtpClose();
 
538
    }
 
539
 
 
540
    /**
 
541
     * Tests this denial of service attack:
 
542
     *    http://www.cybsec.com/vuln/PHPMailer-DOS.pdf
 
543
     */
 
544
    function test_DenialOfServiceAttack() {
 
545
        $this->Mail->Body = "This should no longer cause a denial of service.";
 
546
        $this->BuildBody();
 
547
 
 
548
        $this->Mail->Subject = str_repeat("A", 998);
 
549
        $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
 
550
    }
 
551
 
 
552
  function test_Error() {
 
553
    $this->Mail->Subject .= ": This should be sent";
 
554
    $this->BuildBody();
 
555
    $this->Mail->ClearAllRecipients(); // no addresses should cause an error
 
556
    $this->assertTrue($this->Mail->IsError() == false, "Error found");
 
557
    $this->assertTrue($this->Mail->Send() == false, "Send succeeded");
 
558
    $this->assertTrue($this->Mail->IsError(), "No error found");
 
559
    $this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
 
560
    $this->Mail->AddAddress($_REQUEST['mail_to']);
 
561
    $this->assertTrue($this->Mail->Send(), "Send failed");
 
562
  }
 
563
 
 
564
  function test_Addressing() {
 
565
    $this->assertFalse($this->Mail->AddAddress('a@example..com'), 'Invalid address accepted');
 
566
    $this->assertTrue($this->Mail->AddAddress('a@example.com'), 'Addressing failed');
 
567
    $this->assertFalse($this->Mail->AddAddress('a@example.com'), 'Duplicate addressing failed');
 
568
    $this->assertTrue($this->Mail->AddCC('b@example.com'), 'CC addressing failed');
 
569
    $this->assertFalse($this->Mail->AddCC('b@example.com'), 'CC duplicate addressing failed');
 
570
    $this->assertFalse($this->Mail->AddCC('a@example.com'), 'CC duplicate addressing failed (2)');
 
571
    $this->assertTrue($this->Mail->AddBCC('c@example.com'), 'BCC addressing failed');
 
572
    $this->assertFalse($this->Mail->AddBCC('c@example.com'), 'BCC duplicate addressing failed');
 
573
    $this->assertFalse($this->Mail->AddBCC('a@example.com'), 'BCC duplicate addressing failed (2)');
 
574
    $this->assertTrue($this->Mail->AddReplyTo('a@example.com'), 'Replyto Addressing failed');
 
575
    $this->assertFalse($this->Mail->AddReplyTo('a@example..com'), 'Invalid Replyto address accepted');
 
576
    $this->Mail->ClearAddresses();
 
577
    $this->Mail->ClearCCs();
 
578
    $this->Mail->ClearBCCs();
 
579
    $this->Mail->ClearReplyTos();
 
580
  }
 
581
 
 
582
  /**
 
583
  * Test language files for missing and excess translations
 
584
  * All languages are compared with English
 
585
  */
 
586
  function test_Translations() {
 
587
    $this->Mail->SetLanguage('en');
 
588
    $definedStrings = $this->Mail->GetTranslations();
 
589
    foreach (new DirectoryIterator('../language') as $fileInfo) {
 
590
      if($fileInfo->isDot()) continue;
 
591
      $matches = array();
 
592
      //Only look at language files, ignore anything else in there
 
593
      if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
 
594
        $lang = $matches[1]; //Extract language code
 
595
        $PHPMAILER_LANG = array(); //Language strings get put in here
 
596
        include $fileInfo->getPathname(); //Get language strings
 
597
        $missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
 
598
        $extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));
 
599
        $this->assertTrue(empty($missing), "Missing translations in $lang: ". implode(', ', $missing));
 
600
        $this->assertTrue(empty($extra), "Extra translations in $lang: ". implode(', ', $extra));
 
601
      }
 
602
    }
 
603
  }
 
604
 
 
605
  /**
 
606
  * Encoding tests
 
607
  */
 
608
  function test_Encodings() {
 
609
      $this->Mail->Charset = 'iso-8859-1';
 
610
      $this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('�Hola! Se�or!', 'text'), 'Q Encoding (text) failed');
 
611
      $this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('�Hola! Se�or!', 'comment'), 'Q Encoding (comment) failed');
 
612
      $this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('�Hola! Se�or!', 'phrase'), 'Q Encoding (phrase) failed');
 
613
  }
 
614
 
 
615
  /**
 
616
  * Signing tests
 
617
  */
 
618
  function test_Signing() {
 
619
      $this->Mail->Sign('certfile.txt', 'keyfile.txt', 'password'); //TODO this is not really testing signing, but at least helps coverage
 
620
  }
 
621
 
 
622
  /**
 
623
  * Miscellaneous calls to improve test coverage and some small tests
 
624
  */
 
625
  function test_Miscellaneous() {
 
626
      $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf') , 'MIME TYPE lookup failed');
 
627
      $this->Mail->AddCustomHeader('SomeHeader: Some Value');
 
628
      $this->Mail->ClearCustomHeaders();
 
629
      $this->Mail->ClearAttachments();
 
630
      $this->Mail->IsHTML(false);
 
631
      $this->Mail->IsSMTP();
 
632
      $this->Mail->IsMail();
 
633
      $this->Mail->IsSendMail();
 
634
        $this->Mail->IsQmail();
 
635
      $this->Mail->SetLanguage('fr');
 
636
      $this->Mail->Sender = '';
 
637
      $this->Mail->CreateHeader();
 
638
      $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
 
639
      $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
 
640
      $this->Mail->getFile(__FILE__);
 
641
  }
 
642
}
 
643
 
 
644
/**
 
645
* This is a sample form for setting appropriate test values through a browser
 
646
* These values can also be set using a file called testbootstrap.php (not in svn) in the same folder as this script
 
647
* which is probably more useful if you run these tests a lot
 
648
<html>
 
649
<body>
 
650
<h3>phpmailer Unit Test</h3>
 
651
By entering a SMTP hostname it will automatically perform tests with SMTP.
 
652
 
 
653
<form name="phpmailer_unit" action=__FILE__ method="get">
 
654
<input type="hidden" name="submitted" value="1"/>
 
655
From Address: <input type="text" size="50" name="mail_from" value="<?php echo get("mail_from"); ?>"/>
 
656
<br/>
 
657
To Address: <input type="text" size="50" name="mail_to" value="<?php echo get("mail_to"); ?>"/>
 
658
<br/>
 
659
Cc Address: <input type="text" size="50" name="mail_cc" value="<?php echo get("mail_cc"); ?>"/>
 
660
<br/>
 
661
SMTP Hostname: <input type="text" size="50" name="mail_host" value="<?php echo get("mail_host"); ?>"/>
 
662
<p/>
 
663
<input type="submit" value="Run Test"/>
 
664
 
 
665
</form>
 
666
</body>
 
667
</html>
 
668
 */
 
669
 
 
670
?>
 
 
b'\\ No newline at end of file'