phpmailerTest.php 23 KB

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