|
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\GotoResetPasswordController; |
|
13
|
|
|
use Auth\Service\Exception; |
|
14
|
|
|
use Test\Bootstrap; |
|
15
|
|
|
use Core\Controller\Plugin\Notification; |
|
16
|
|
|
use CoreTest\Controller\AbstractControllerTestCase; |
|
17
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject; |
|
18
|
|
|
use Zend\Http\PhpEnvironment\Request; |
|
19
|
|
|
use Zend\Http\PhpEnvironment\Response; |
|
20
|
|
|
use Zend\Mvc\Controller\PluginManager; |
|
21
|
|
|
|
|
22
|
|
|
class GotoResetPasswordControllerTest extends AbstractControllerTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var MockObject |
|
26
|
|
|
*/ |
|
27
|
|
|
private $serviceMock; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->init('goto-reset-password'); |
|
32
|
|
|
|
|
33
|
|
|
$this->serviceMock = $this->getMockBuilder('Auth\Service\GotoResetPassword') |
|
34
|
|
|
->disableOriginalConstructor() |
|
35
|
|
|
->getMock(); |
|
36
|
|
|
|
|
37
|
|
|
$loggerMock = $this->getMock('Zend\Log\LoggerInterface'); |
|
38
|
|
|
|
|
39
|
|
|
$this->controller = new GotoResetPasswordController($this->serviceMock, $loggerMock); |
|
40
|
|
|
$this->controller->setEvent($this->event); |
|
41
|
|
|
|
|
42
|
|
|
/** @var PluginManager $controllerPluginManager */ |
|
43
|
|
|
$controllerPluginManager = clone Bootstrap::getServiceManager()->get('ControllerPluginManager'); |
|
44
|
|
|
$this->controller->setPluginManager($controllerPluginManager); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testIndexAction_WithGetRequest() |
|
48
|
|
|
{ |
|
49
|
|
|
$userId = uniqid('user'); |
|
50
|
|
|
$token = uniqid('token'); |
|
51
|
|
|
|
|
52
|
|
|
$request = new Request(); |
|
53
|
|
|
$request->setMethod(Request::METHOD_GET); |
|
54
|
|
|
|
|
55
|
|
|
$this->routeMatch->setParam('userId', $userId) |
|
56
|
|
|
->setParam('token', $token); |
|
57
|
|
|
|
|
58
|
|
|
$this->serviceMock->expects($this->once()) |
|
59
|
|
|
->method('proceed') |
|
60
|
|
|
->with($userId, $token); |
|
61
|
|
|
|
|
62
|
|
|
$this->controller->dispatch($request); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_302); |
|
65
|
|
|
$this->assertRedirectTo('/en/my/password'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testIndexAction_WithGetRequest_WhenTokenExpired() |
|
69
|
|
|
{ |
|
70
|
|
|
$userId = uniqid('user'); |
|
71
|
|
|
$token = uniqid('token'); |
|
72
|
|
|
|
|
73
|
|
|
$request = new Request(); |
|
74
|
|
|
$request->setMethod(Request::METHOD_GET); |
|
75
|
|
|
|
|
76
|
|
|
$this->routeMatch->setParam('userId', $userId) |
|
77
|
|
|
->setParam('token', $token); |
|
78
|
|
|
|
|
79
|
|
|
$this->serviceMock->expects($this->once()) |
|
80
|
|
|
->method('proceed') |
|
81
|
|
|
->with($userId, $token) |
|
82
|
|
|
->willThrowException(new Exception\TokenExpirationDateExpiredException()); |
|
83
|
|
|
|
|
84
|
|
|
$this->controller->dispatch($request); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_302); |
|
87
|
|
|
$this->assertRedirectTo('/en/auth/forgot-password'); |
|
88
|
|
|
|
|
89
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
90
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_DANGER); |
|
91
|
|
|
//$expectedMessages = array( |
|
92
|
|
|
// 'Cannot proceed, token expired' |
|
93
|
|
|
//); |
|
94
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testIndexAction_WithGetRequest_WhenCannotFoundUserBySpecifiedToken() |
|
98
|
|
|
{ |
|
99
|
|
|
$userId = uniqid('user'); |
|
100
|
|
|
$token = uniqid('token'); |
|
101
|
|
|
|
|
102
|
|
|
$request = new Request(); |
|
103
|
|
|
$request->setMethod(Request::METHOD_GET); |
|
104
|
|
|
|
|
105
|
|
|
$this->routeMatch->setParam('userId', $userId) |
|
106
|
|
|
->setParam('token', $token); |
|
107
|
|
|
|
|
108
|
|
|
$this->serviceMock->expects($this->once()) |
|
109
|
|
|
->method('proceed') |
|
110
|
|
|
->with($userId, $token) |
|
111
|
|
|
->willThrowException(new Exception\UserNotFoundException()); |
|
112
|
|
|
|
|
113
|
|
|
$this->controller->dispatch($request); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_302); |
|
116
|
|
|
$this->assertRedirectTo('/en/auth/forgot-password'); |
|
117
|
|
|
|
|
118
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
119
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_DANGER); |
|
120
|
|
|
//$expectedMessages = array( |
|
121
|
|
|
// 'User cannot be found for specified token' |
|
122
|
|
|
//); |
|
123
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function testIndexAction_WithGetRequest_WhenUnexpectedExceptionOccurred() |
|
127
|
|
|
{ |
|
128
|
|
|
$userId = uniqid('user'); |
|
129
|
|
|
$token = uniqid('token'); |
|
130
|
|
|
|
|
131
|
|
|
$request = new Request(); |
|
132
|
|
|
$request->setMethod(Request::METHOD_GET); |
|
133
|
|
|
|
|
134
|
|
|
$this->routeMatch->setParam('userId', $userId) |
|
135
|
|
|
->setParam('token', $token); |
|
136
|
|
|
|
|
137
|
|
|
$this->serviceMock->expects($this->once()) |
|
138
|
|
|
->method('proceed') |
|
139
|
|
|
->with($userId, $token) |
|
140
|
|
|
->willThrowException(new \LogicException()); |
|
141
|
|
|
|
|
142
|
|
|
$this->controller->dispatch($request); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertResponseStatusCode(Response::STATUS_CODE_302); |
|
145
|
|
|
$this->assertRedirectTo('/en/auth/forgot-password'); |
|
146
|
|
|
|
|
147
|
|
|
//$fm = $this->controller->flashMessenger(); |
|
148
|
|
|
//$fm->setNamespace(Notification::NAMESPACE_DANGER); |
|
149
|
|
|
//$expectedMessages = array( |
|
150
|
|
|
// 'An unexpected error has occurred, please contact your system administrator' |
|
151
|
|
|
//); |
|
152
|
|
|
//$this->assertSame($expectedMessages, $fm->getCurrentMessages()); |
|
153
|
|
|
} |
|
154
|
|
|
} |