MailTransportTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * MailTransportTest file
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP(tm) Project
  14. * @since 2.0.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\Network\Email;
  18. use Cake\Network\Email\Email;
  19. use Cake\Network\Email\MailTransport;
  20. use Cake\TestSuite\TestCase;
  21. /**
  22. * Test case
  23. *
  24. */
  25. class MailTransportTest extends TestCase
  26. {
  27. /**
  28. * Setup
  29. *
  30. * @return void
  31. */
  32. public function setUp()
  33. {
  34. parent::setUp();
  35. $this->MailTransport = $this->getMock('Cake\Network\Email\MailTransport', ['_mail']);
  36. $this->MailTransport->config(['additionalParameters' => '-f']);
  37. }
  38. /**
  39. * testSend method
  40. *
  41. * @return void
  42. */
  43. public function testSendData()
  44. {
  45. $email = $this->getMock('Cake\Network\Email\Email', ['message'], []);
  46. $email->from('noreply@cakephp.org', 'CakePHP Test');
  47. $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
  48. $email->to('cake@cakephp.org', 'CakePHP');
  49. $email->cc(['mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso']);
  50. $email->bcc('phpnut@cakephp.org');
  51. $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
  52. $longNonAscii = 'Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz';
  53. $email->subject($longNonAscii);
  54. $date = date(DATE_RFC2822);
  55. $email->setHeaders([
  56. 'X-Mailer' => 'CakePHP Email',
  57. 'Date' => $date,
  58. 'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'),
  59. ]);
  60. $email->expects($this->any())->method('message')
  61. ->will($this->returnValue(['First Line', 'Second Line', '.Third Line', '']));
  62. $encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
  63. $encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';
  64. $data = "From: CakePHP Test <noreply@cakephp.org>" . PHP_EOL;
  65. $data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>" . PHP_EOL;
  66. $data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>" . PHP_EOL;
  67. $data .= "Bcc: phpnut@cakephp.org" . PHP_EOL;
  68. $data .= "X-Mailer: CakePHP Email" . PHP_EOL;
  69. $data .= "Date: " . $date . PHP_EOL;
  70. $data .= "X-add: " . $encoded . PHP_EOL;
  71. $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL;
  72. $data .= "MIME-Version: 1.0" . PHP_EOL;
  73. $data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL;
  74. $data .= "Content-Transfer-Encoding: 8bit";
  75. $this->MailTransport->expects($this->once())->method('_mail')
  76. ->with(
  77. 'CakePHP <cake@cakephp.org>',
  78. $encoded,
  79. implode(PHP_EOL, ['First Line', 'Second Line', '.Third Line', '']),
  80. $data,
  81. '-f'
  82. );
  83. $this->MailTransport->send($email);
  84. }
  85. }