|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace AuthTest\Controller; |
|
11
|
|
|
|
|
12
|
|
|
use Auth\Controller\ForgotPasswordController; |
|
13
|
|
|
use Auth\Form\ForgotPasswordInputFilter; |
|
14
|
|
|
use Auth\Service\Exception; |
|
15
|
|
|
use Test\Bootstrap; |
|
16
|
|
|
use Core\Controller\Plugin\Notification; |
|
17
|
|
|
use CoreTest\Controller\AbstractControllerTestCase; |
|
18
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject; |
|
19
|
|
|
use Zend\Mvc\MvcEvent; |
|
20
|
|
|
use Zend\Http\PhpEnvironment\Request; |
|
21
|
|
|
use Zend\Http\PhpEnvironment\Response; |
|
22
|
|
|
use Zend\Mvc\Controller\PluginManager; |
|
23
|
|
|
use Zend\Stdlib\Parameters; |
|
24
|
|
|
|
|
25
|
|
|
class ForgotPasswordControllerTest extends AbstractControllerTestCase |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var MockObject |
|
29
|
|
|
*/ |
|
30
|
|
|
private $formMock; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var MockObject |
|
34
|
|
|
*/ |
|
35
|
|
|
private $serviceMock; |
|
36
|
|
|
|
|
37
|
|
|
public function setUp() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->init('forgot-password'); |
|
40
|
|
|
|
|
41
|
|
|
$this->formMock = $this->getMock('Auth\Form\ForgotPassword'); |
|
42
|
|
|
|
|
43
|
|
|
$this->serviceMock = $this->getMockBuilder('Auth\Service\ForgotPassword') |
|
44
|
|
|
->disableOriginalConstructor() |
|
45
|
|
|
->getMock(); |
|
46
|
|
|
|
|
47
|
|
|
$loggerMock = $this->getMock('Zend\Log\LoggerInterface'); |
|
48
|
|
|
|
|
49
|
|
|
$this->controller = new ForgotPasswordController($this->formMock, $this->serviceMock, $loggerMock); |
|
50
|
|
|
$this->controller->setEvent($this->event); |
|
51
|
|
|
|
|
52
|
|
|
/** @var PluginManager $controllerPluginManager */ |
|
53
|
|
|
$servicemanager = clone Bootstrap::getServiceManager(); |
|
54
|
|
|
$controllerPluginManager = $servicemanager->get('ControllerPluginManager'); |
|
55
|
|
|
$this->controller->setServiceLocator($servicemanager); |
|
56
|
|
|
$this->controller->setPluginManager($controllerPluginManager); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testIndexAction_WithGetRequest() |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$request = new Request(); |
|
62
|
|
|
$request->setMethod(Request::METHOD_GET); |
|
63
|
|
|
|
|
64
|
|
|
$result = $this->controller->dispatch($request); |
|
65
|
|
|
|
|
66
|
|
|
$expected = array( |
|
67
|
|
|
'form' => $this->formMock |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_200); |
|
71
|
|
|
$this->assertSame($expected, $result); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testIndexAction_WithPostRequest_WhenDataIsInvalid() |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$postData = array(); |
|
77
|
|
|
|
|
78
|
|
|
$request = new Request(); |
|
79
|
|
|
$request->setMethod(Request::METHOD_POST); |
|
80
|
|
|
$request->setPost(new Parameters($postData)); |
|
81
|
|
|
|
|
82
|
|
|
$this->formMock->expects($this->once()) |
|
83
|
|
|
->method('setData') |
|
84
|
|
|
->with($postData); |
|
85
|
|
|
|
|
86
|
|
|
$this->formMock->expects($this->once()) |
|
87
|
|
|
->method('isValid') |
|
88
|
|
|
->willReturn(false); |
|
89
|
|
|
|
|
90
|
|
|
$result = $this->controller->dispatch($request); |
|
91
|
|
|
|
|
92
|
|
|
$mvcEvent = new MvcEvent(); |
|
93
|
|
|
$notifications = $this->controller->getServiceLocator()->get('coreListenerNotification'); |
|
94
|
|
|
$notifications->reset()->renderHTML($mvcEvent); |
|
95
|
|
|
|
|
96
|
|
|
$expected = array( |
|
97
|
|
|
'form' => $this->formMock |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_200); |
|
101
|
|
|
$this->assertSame($expected, $result); |
|
102
|
|
|
|
|
103
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
|
|
|
|
|
104
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_DANGER); |
|
|
|
|
|
|
105
|
|
|
//$expectedMessages = array( |
|
|
|
|
|
|
106
|
|
|
// 'Please fill form correctly' |
|
107
|
|
|
//); |
|
108
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testIndexAction_WithPostRequest_WhenUserCannotBeFoundByUsernameOrEmail() |
|
|
|
|
|
|
112
|
|
|
{ |
|
113
|
|
|
$postData = array('identity' => uniqid('identity')); |
|
114
|
|
|
|
|
115
|
|
|
$request = new Request(); |
|
116
|
|
|
$request->setMethod(Request::METHOD_POST); |
|
117
|
|
|
$request->setPost(new Parameters($postData)); |
|
118
|
|
|
|
|
119
|
|
|
$this->formMock->expects($this->once()) |
|
120
|
|
|
->method('setData') |
|
121
|
|
|
->with($postData); |
|
122
|
|
|
|
|
123
|
|
|
$this->formMock->expects($this->once()) |
|
124
|
|
|
->method('isValid') |
|
125
|
|
|
->willReturn(true); |
|
126
|
|
|
|
|
127
|
|
|
$this->formMock->expects($this->once()) |
|
128
|
|
|
->method('getInputFilter') |
|
129
|
|
|
->willReturn(new ForgotPasswordInputFilter()); |
|
130
|
|
|
|
|
131
|
|
|
$this->serviceMock->expects($this->once()) |
|
132
|
|
|
->method('proceed') |
|
133
|
|
|
->willThrowException(new Exception\UserNotFoundException()); |
|
134
|
|
|
|
|
135
|
|
|
$result = $this->controller->dispatch($request); |
|
136
|
|
|
|
|
137
|
|
|
$expected = array( |
|
138
|
|
|
'form' => $this->formMock |
|
139
|
|
|
); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_200); |
|
142
|
|
|
$this->assertSame($expected, $result); |
|
143
|
|
|
|
|
144
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
|
|
|
|
|
145
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_DANGER); |
|
|
|
|
|
|
146
|
|
|
//$expectedMessages = array( |
|
|
|
|
|
|
147
|
|
|
// 'User cannot be found for specified username or email' |
|
148
|
|
|
//); |
|
149
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function testIndexAction_WithPostRequest_WhenUserDoesNotHaveAnEmail() |
|
|
|
|
|
|
153
|
|
|
{ |
|
154
|
|
|
$postData = array('identity' => uniqid('identity')); |
|
155
|
|
|
|
|
156
|
|
|
$request = new Request(); |
|
157
|
|
|
$request->setMethod(Request::METHOD_POST); |
|
158
|
|
|
$request->setPost(new Parameters($postData)); |
|
159
|
|
|
|
|
160
|
|
|
$this->formMock->expects($this->once()) |
|
161
|
|
|
->method('setData') |
|
162
|
|
|
->with($postData); |
|
163
|
|
|
|
|
164
|
|
|
$this->formMock->expects($this->once()) |
|
165
|
|
|
->method('isValid') |
|
166
|
|
|
->willReturn(true); |
|
167
|
|
|
|
|
168
|
|
|
$this->formMock->expects($this->once()) |
|
169
|
|
|
->method('getInputFilter') |
|
170
|
|
|
->willReturn(new ForgotPasswordInputFilter()); |
|
171
|
|
|
|
|
172
|
|
|
$this->serviceMock->expects($this->once()) |
|
173
|
|
|
->method('proceed') |
|
174
|
|
|
->willThrowException(new Exception\UserDoesNotHaveAnEmailException()); |
|
175
|
|
|
|
|
176
|
|
|
$result = $this->controller->dispatch($request); |
|
177
|
|
|
|
|
178
|
|
|
$mvcEvent = new MvcEvent(); |
|
179
|
|
|
$notifications = $this->controller->getServiceLocator()->get('coreListenerNotification'); |
|
180
|
|
|
$notifications->reset()->renderHTML($mvcEvent); |
|
181
|
|
|
|
|
182
|
|
|
$expected = array( |
|
183
|
|
|
'form' => $this->formMock |
|
184
|
|
|
); |
|
185
|
|
|
|
|
186
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_200); |
|
187
|
|
|
$this->assertSame($expected, $result); |
|
188
|
|
|
|
|
189
|
|
|
// @TODO: Fix this, the messages already have been transferred to somewhere |
|
190
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
|
|
|
|
|
191
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_DANGER); |
|
|
|
|
|
|
192
|
|
|
//$expectedMessages = array(); |
|
|
|
|
|
|
193
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
|
|
|
|
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
public function testIndexAction_WithPostRequest_WhenUnexpectedExceptionHasOccurred() |
|
|
|
|
|
|
197
|
|
|
{ |
|
198
|
|
|
$postData = array('identity' => uniqid('identity')); |
|
199
|
|
|
|
|
200
|
|
|
$request = new Request(); |
|
201
|
|
|
$request->setMethod(Request::METHOD_POST); |
|
202
|
|
|
$request->setPost(new Parameters($postData)); |
|
203
|
|
|
|
|
204
|
|
|
$this->formMock->expects($this->once()) |
|
205
|
|
|
->method('setData') |
|
206
|
|
|
->with($postData); |
|
207
|
|
|
|
|
208
|
|
|
$this->formMock->expects($this->once()) |
|
209
|
|
|
->method('isValid') |
|
210
|
|
|
->willReturn(true); |
|
211
|
|
|
|
|
212
|
|
|
$this->formMock->expects($this->once()) |
|
213
|
|
|
->method('getInputFilter') |
|
214
|
|
|
->willReturn(new ForgotPasswordInputFilter()); |
|
215
|
|
|
|
|
216
|
|
|
$this->serviceMock->expects($this->once()) |
|
217
|
|
|
->method('proceed') |
|
218
|
|
|
->willThrowException(new \LogicException()); |
|
219
|
|
|
|
|
220
|
|
|
$result = $this->controller->dispatch($request); |
|
221
|
|
|
|
|
222
|
|
|
$expected = array( |
|
223
|
|
|
'form' => $this->formMock |
|
224
|
|
|
); |
|
225
|
|
|
|
|
226
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_200); |
|
227
|
|
|
$this->assertSame($expected, $result); |
|
228
|
|
|
|
|
229
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
|
|
|
|
|
230
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_DANGER); |
|
|
|
|
|
|
231
|
|
|
//$expectedMessages = array( |
|
|
|
|
|
|
232
|
|
|
// 'An unexpected error has occurred, please contact your system administrator' |
|
233
|
|
|
//); |
|
234
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
|
|
|
|
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function testIndexAction_WithPostRequest() |
|
|
|
|
|
|
238
|
|
|
{ |
|
239
|
|
|
$postData = array('identity' => uniqid('identity')); |
|
240
|
|
|
|
|
241
|
|
|
$request = new Request(); |
|
242
|
|
|
$request->setMethod(Request::METHOD_POST); |
|
243
|
|
|
$request->setPost(new Parameters($postData)); |
|
244
|
|
|
|
|
245
|
|
|
$this->formMock->expects($this->once()) |
|
246
|
|
|
->method('setData') |
|
247
|
|
|
->with($postData); |
|
248
|
|
|
|
|
249
|
|
|
$this->formMock->expects($this->once()) |
|
250
|
|
|
->method('isValid') |
|
251
|
|
|
->willReturn(true); |
|
252
|
|
|
|
|
253
|
|
|
$this->formMock->expects($this->once()) |
|
254
|
|
|
->method('getInputFilter') |
|
255
|
|
|
->willReturn(new ForgotPasswordInputFilter()); |
|
256
|
|
|
|
|
257
|
|
|
$this->serviceMock->expects($this->once()) |
|
258
|
|
|
->method('proceed'); |
|
259
|
|
|
|
|
260
|
|
|
$result = $this->controller->dispatch($request); |
|
261
|
|
|
|
|
262
|
|
|
$expected = array( |
|
263
|
|
|
'form' => $this->formMock |
|
264
|
|
|
); |
|
265
|
|
|
|
|
266
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_200); |
|
267
|
|
|
$this->assertSame($expected, $result); |
|
268
|
|
|
|
|
269
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
|
|
|
|
|
270
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_SUCCESS); |
|
|
|
|
|
|
271
|
|
|
//$expectedMessages = array( |
|
|
|
|
|
|
272
|
|
|
// 'Mail with link for reset password has been sent, please try to check your email box' |
|
273
|
|
|
//); |
|
274
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
} |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.