1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace yii2mod\user\tests\actions; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\web\Response; |
7
|
|
|
use yii2mod\user\actions\PasswordResetAction; |
8
|
|
|
use yii2mod\user\actions\RequestPasswordResetAction; |
9
|
|
|
use yii2mod\user\models\UserModel; |
10
|
|
|
use yii2mod\user\tests\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class RequestPasswordResetActionTest |
14
|
|
|
* |
15
|
|
|
* @package yii2mod\user\tests\actions |
16
|
|
|
*/ |
17
|
|
|
class RequestPasswordResetActionTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Runs the action. |
21
|
|
|
* |
22
|
|
|
* @param array $config |
23
|
|
|
* |
24
|
|
|
* @return array|\yii\web\Response response |
25
|
|
|
*/ |
26
|
|
|
protected function runAction(array $config = []) |
27
|
|
|
{ |
28
|
|
|
$action = new RequestPasswordResetAction('request-reset-password', $this->createController(), $config); |
29
|
|
|
|
30
|
|
|
return $action->run($config); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// Tests: |
34
|
|
|
|
35
|
|
|
public function testViewRequestResetPassword() |
36
|
|
|
{ |
37
|
|
|
$response = $this->runAction(); |
38
|
|
|
$this->assertEquals('@vendor/yii2mod/yii2-user/views/requestPasswordResetToken', $response['view']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testSuccessRequestResetPassword() |
42
|
|
|
{ |
43
|
|
|
// send request |
44
|
|
|
$email = '[email protected]'; |
45
|
|
|
Yii::$app->request->bodyParams = [ |
46
|
|
|
'PasswordResetRequestForm' => [ |
47
|
|
|
'email' => $email, |
48
|
|
|
], |
49
|
|
|
]; |
50
|
|
|
$this->runAction(); |
51
|
|
|
$this->assertTrue(file_exists($this->getMessageFile())); |
52
|
|
|
|
53
|
|
|
$emailMessage = file_get_contents($this->getMessageFile()); |
54
|
|
|
$this->assertContains($email, $emailMessage); |
55
|
|
|
|
56
|
|
|
// try to reset password |
57
|
|
|
$user = UserModel::find()->one(); |
58
|
|
|
Yii::$app->request->bodyParams = [ |
59
|
|
|
'ResetPasswordForm' => [ |
60
|
|
|
'password' => 'new-password', |
61
|
|
|
'confirmPassword' => 'new-password', |
62
|
|
|
], |
63
|
|
|
]; |
64
|
|
|
$passwordResetResponse = (new PasswordResetAction('reset-password', $this->createController()))->run($user->password_reset_token); |
65
|
|
|
|
66
|
|
|
$this->assertInstanceOf(Response::class, $passwordResetResponse); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get message file |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
private function getMessageFile() |
75
|
|
|
{ |
76
|
|
|
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml'; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.