MailTransportTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * MailTransportTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  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://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  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. * Setup
  28. *
  29. * @return void
  30. */
  31. public function setUp() {
  32. parent::setUp();
  33. $this->MailTransport = $this->getMock('Cake\Network\Email\MailTransport', array('_mail'));
  34. $this->MailTransport->config(array('additionalParameters' => '-f'));
  35. }
  36. /**
  37. * testSend method
  38. *
  39. * @return void
  40. */
  41. public function testSendData() {
  42. $email = $this->getMock('Cake\Network\Email\Email', array('message'), array());
  43. $email->from('noreply@cakephp.org', 'CakePHP Test');
  44. $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
  45. $email->to('cake@cakephp.org', 'CakePHP');
  46. $email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
  47. $email->bcc('phpnut@cakephp.org');
  48. $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
  49. $longNonAscii = 'Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz';
  50. $email->subject($longNonAscii);
  51. $date = date(DATE_RFC2822);
  52. $email->setHeaders(array(
  53. 'X-Mailer' => 'CakePHP Email',
  54. 'Date' => $date,
  55. 'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'),
  56. ));
  57. $email->expects($this->any())->method('message')
  58. ->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
  59. $encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
  60. $encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';
  61. $data = "From: CakePHP Test <noreply@cakephp.org>" . PHP_EOL;
  62. $data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>" . PHP_EOL;
  63. $data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>" . PHP_EOL;
  64. $data .= "Bcc: phpnut@cakephp.org" . PHP_EOL;
  65. $data .= "X-Mailer: CakePHP Email" . PHP_EOL;
  66. $data .= "Date: " . $date . PHP_EOL;
  67. $data .= "X-add: " . $encoded . PHP_EOL;
  68. $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL;
  69. $data .= "MIME-Version: 1.0" . PHP_EOL;
  70. $data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL;
  71. $data .= "Content-Transfer-Encoding: 8bit";
  72. $this->MailTransport->expects($this->once())->method('_mail')
  73. ->with(
  74. 'CakePHP <cake@cakephp.org>',
  75. $encoded,
  76. implode(PHP_EOL, array('First Line', 'Second Line', '.Third Line', '')),
  77. $data,
  78. '-f'
  79. );
  80. $this->MailTransport->send($email);
  81. }
  82. }