Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 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
 * @package       Cake.Test.Case.Network.Email
15
 * @since         CakePHP(tm) v 2.0.0
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
App::uses('CakeEmail', 'Network/Email');
20
App::uses('AbstractTransport', 'Network/Email');
21
App::uses('MailTransport', 'Network/Email');
22
 
23
/**
24
 * Test case
25
 *
26
 */
27
class MailTransportTest extends CakeTestCase {
28
 
29
/**
30
 * Setup
31
 *
32
 * @return void
33
 */
34
	public function setUp() {
35
		parent::setUp();
36
		$this->MailTransport = $this->getMock('MailTransport', array('_mail'));
37
		$this->MailTransport->config(array('additionalParameters' => '-f'));
38
	}
39
 
40
/**
41
 * testSend method
42
 *
43
 * @return void
44
 */
45
	public function testSendData() {
46
		$email = $this->getMock('CakeEmail', array('message'), array());
47
		$email->from('noreply@cakephp.org', 'CakePHP Test');
48
		$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
49
		$email->to('cake@cakephp.org', 'CakePHP');
50
		$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
51
		$email->bcc('phpnut@cakephp.org');
52
		$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
53
		$longNonAscii = 'Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz';
54
		$email->subject($longNonAscii);
55
		$date = date(DATE_RFC2822);
56
		$email->setHeaders(array(
57
			'X-Mailer' => 'CakePHP Email',
58
			'Date' => $date,
59
			'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'),
60
		));
61
		$email->expects($this->any())->method('message')
62
			->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
63
 
64
		$encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
65
		$encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';
66
 
67
		$data = "From: CakePHP Test <noreply@cakephp.org>" . PHP_EOL;
68
		$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>" . PHP_EOL;
69
		$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>" . PHP_EOL;
70
		$data .= "Bcc: phpnut@cakephp.org" . PHP_EOL;
71
		$data .= "X-Mailer: CakePHP Email" . PHP_EOL;
72
		$data .= "Date: " . $date . PHP_EOL;
73
		$data .= "X-add: " . $encoded . PHP_EOL;
74
		$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL;
75
		$data .= "MIME-Version: 1.0" . PHP_EOL;
76
		$data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL;
77
		$data .= "Content-Transfer-Encoding: 8bit";
78
 
79
		$this->MailTransport->expects($this->once())->method('_mail')
80
			->with(
81
				'CakePHP <cake@cakephp.org>',
82
				$encoded,
83
				implode(PHP_EOL, array('First Line', 'Second Line', '.Third Line', '')),
84
				$data,
85
				'-f'
86
			);
87
 
88
		$this->MailTransport->send($email);
89
	}
90
 
91
}