forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEmailSenderTest.php
More file actions
161 lines (140 loc) · 4.33 KB
/
Copy pathEmailSenderTest.php
File metadata and controls
161 lines (140 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Test\TestCase\Email;
use Cake\Mailer\Email;
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
/**
* Test Case
*/
class EmailSenderTest extends TestCase
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'plugin.CakeDC/Users.social_accounts',
'plugin.CakeDC/Users.users',
];
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->EmailSender = $this->getMockBuilder('CakeDC\Users\Email\EmailSender')
->setMethods(['_getEmailInstance', 'getMailer'])
->getMock();
$this->UserMailer = $this->getMockBuilder('CakeDC\Users\Mailer\UserMailer')
->setMethods(['send'])
->getMock();
$this->fullBaseBackup = Router::fullBaseUrl();
Router::fullBaseUrl('http://users.test');
Email::configTransport('test', [
'className' => 'Debug'
]);
}
/**
* tearDown
*
* @return void
*/
public function tearDown()
{
Email::drop('default');
Email::dropTransport('test');
parent::tearDown();
}
/**
* test sendValidationEmail
*
* @return void
*/
public function testSendEmailValidation()
{
$table = TableRegistry::get('CakeDC/Users.Users');
$user = $table->newEntity([
'first_name' => 'FirstName',
'email' => 'test@example.com',
'token' => '12345'
]);
$email = new Email([
'from' => 'test@example.com',
'transport' => 'test',
'emailFormat' => 'both',
]);
$this->EmailSender->expects($this->once())
->method('getMailer')
->with('CakeDC/Users.Users')
->will($this->returnValue($this->UserMailer));
$this->UserMailer->expects($this->once())
->method('send')
->with('validation', [$user, 'Your account validation link']);
$this->EmailSender->sendValidationEmail($user, $email);
}
/**
* test sendResetPasswordEmail
*
* @return void
*/
public function testSendResetPasswordEmailMailer()
{
$table = TableRegistry::get('CakeDC/Users.Users');
$user = $table->newEntity([
'first_name' => 'FirstName',
'email' => 'test@example.com',
'token' => '12345'
]);
$email = new Email([
'from' => 'test@example.com',
'transport' => 'test',
'template' => 'CakeDC/Users.reset_password',
'emailFormat' => 'both',
]);
$this->EmailSender->expects($this->once())
->method('getMailer')
->with('CakeDC/Users.Users')
->will($this->returnValue($this->UserMailer));
$this->UserMailer->expects($this->once())
->method('send')
->with('resetPassword', [$user, 'CakeDC/Users.reset_password']);
$this->EmailSender->sendResetPasswordEmail($user, $email);
}
/**
* test sendSocialValidationEmail
*
* @return void
*/
public function testSendSocialValidationEmailMailer()
{
$this->Table = TableRegistry::get('CakeDC/Users.SocialAccounts');
$user = $this->Table->find()->contain('Users')->first();
$email = new Email([
'from' => 'test@example.com',
'transport' => 'test',
'template' => 'CakeDC/Users.my_template',
'emailFormat' => 'both',
]);
$this->EmailSender->expects($this->once())
->method('getMailer')
->with('CakeDC/Users.Users')
->will($this->returnValue($this->UserMailer));
$this->UserMailer->expects($this->once())
->method('send')
->with('socialAccountValidation', [$user->user, $user, 'CakeDC/Users.my_template']);
$this->EmailSender->sendSocialValidationEmail($user, $user->user, $email);
}
}