2012-09-09 13:32:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2012-09-10 07:17:29 +00:00
|
|
|
* MailTransportTest file
|
2012-09-09 13:32:50 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2012-09-09 13:32:50 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2012-09-09 13:32:50 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2012-09-09 13:32:50 +00:00
|
|
|
* @package Cake.Test.Case.Network.Email
|
|
|
|
* @since CakePHP(tm) v 2.0.0
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2012-09-09 13:32:50 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2012-09-09 13:32:50 +00:00
|
|
|
App::uses('CakeEmail', 'Network/Email');
|
|
|
|
App::uses('AbstractTransport', 'Network/Email');
|
|
|
|
App::uses('MailTransport', 'Network/Email');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case
|
|
|
|
*/
|
|
|
|
class MailTransportTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2013-07-28 23:22:52 +00:00
|
|
|
parent::setUp();
|
2012-09-09 13:32:50 +00:00
|
|
|
$this->MailTransport = $this->getMock('MailTransport', array('_mail'));
|
|
|
|
$this->MailTransport->config(array('additionalParameters' => '-f'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSend method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSendData() {
|
|
|
|
$email = $this->getMock('CakeEmail', array('message'), array());
|
|
|
|
$email->from('noreply@cakephp.org', 'CakePHP Test');
|
|
|
|
$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
|
|
|
|
$email->to('cake@cakephp.org', 'CakePHP');
|
|
|
|
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
|
|
|
|
$email->bcc('phpnut@cakephp.org');
|
|
|
|
$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
|
2013-11-05 03:17:21 +00:00
|
|
|
$longNonAscii = 'Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz';
|
|
|
|
$email->subject($longNonAscii);
|
2012-09-09 13:32:50 +00:00
|
|
|
$date = date(DATE_RFC2822);
|
2013-11-05 03:17:21 +00:00
|
|
|
$email->setHeaders(array(
|
|
|
|
'X-Mailer' => 'CakePHP Email',
|
|
|
|
'Date' => $date,
|
|
|
|
'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'),
|
|
|
|
));
|
|
|
|
$email->expects($this->any())->method('message')
|
|
|
|
->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
|
|
|
|
|
|
|
|
$encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
|
|
|
|
$encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';
|
2012-09-09 13:32:50 +00:00
|
|
|
|
|
|
|
$data = "From: CakePHP Test <noreply@cakephp.org>" . PHP_EOL;
|
|
|
|
$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>" . PHP_EOL;
|
|
|
|
$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>" . PHP_EOL;
|
|
|
|
$data .= "Bcc: phpnut@cakephp.org" . PHP_EOL;
|
|
|
|
$data .= "X-Mailer: CakePHP Email" . PHP_EOL;
|
2012-09-18 18:50:03 +00:00
|
|
|
$data .= "Date: " . $date . PHP_EOL;
|
2013-11-05 03:17:21 +00:00
|
|
|
$data .= "X-add: " . $encoded . PHP_EOL;
|
2012-09-09 13:32:50 +00:00
|
|
|
$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL;
|
|
|
|
$data .= "MIME-Version: 1.0" . PHP_EOL;
|
|
|
|
$data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL;
|
|
|
|
$data .= "Content-Transfer-Encoding: 8bit";
|
|
|
|
|
|
|
|
$this->MailTransport->expects($this->once())->method('_mail')
|
|
|
|
->with(
|
|
|
|
'CakePHP <cake@cakephp.org>',
|
2013-11-05 03:17:21 +00:00
|
|
|
$encoded,
|
2012-09-09 13:32:50 +00:00
|
|
|
implode(PHP_EOL, array('First Line', 'Second Line', '.Third Line', '')),
|
|
|
|
$data,
|
|
|
|
'-f'
|
|
|
|
);
|
|
|
|
|
2016-03-01 20:21:14 +00:00
|
|
|
$result = $this->MailTransport->send($email);
|
|
|
|
|
|
|
|
$this->assertContains('Subject: ', $result['headers']);
|
|
|
|
$this->assertContains('To: ', $result['headers']);
|
2012-09-09 13:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|