forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersResetPasswordCommandTest.php
More file actions
105 lines (92 loc) · 4.01 KB
/
Copy pathUsersResetPasswordCommandTest.php
File metadata and controls
105 lines (92 loc) · 4.01 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
<?php
declare(strict_types=1);
namespace CakeDC\Users\Test\TestCase\Command;
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
/**
* CakeDC\Users\Command\UsersResetPasswordCommand Test Case
*
* @uses \CakeDC\Users\Command\UsersResetPasswordCommand
*/
class UsersResetPasswordCommandTest extends TestCase
{
use ConsoleIntegrationTestTrait;
/**
* @inheritDoc
*/
protected array $fixtures = [
'plugin.CakeDC/Users.Users',
'plugin.CakeDC/Users.SocialAccounts',
];
/**
* Test execute method
*
* @return void
* @uses \CakeDC\Users\Command\UsersResetPasswordCommand::execute()
*/
public function testExecute(): void
{
$UsersTable = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$userId004 = '00000000-0000-0000-0000-000000000004';
$userId006 = '00000000-0000-0000-0000-000000000006';
$passwordBefore = '$2y$10$Nvu7ipP.z8tiIl75OdUvt.86vuG6iKMoHIOc7O7mboFI85hSyTEde';
$userId001 = '00000000-0000-0000-0000-000000000001';
$password001 = '12345';
$password006 = '$2y$10$IPPgJNSfvATsMBLbv/2r8OtpyTBibyM1g5GDxD4PivW9qBRwRkRbC';
$this->assertTrue($UsersTable->exists(['id' => $userId004, 'password' => $passwordBefore]));
$this->assertTrue($UsersTable->exists(['id' => $userId001, 'password' => $password001]));
$this->assertTrue($UsersTable->exists(['id' => $userId006, 'password' => $password006]));
$this->exec('cake_d_c/users.users reset_password user-4 newPassTestOne234');
$this->assertExitSuccess();
$this->assertOutputRegExp('/Password changed for user: user-4/');
$this->assertOutputRegExp('/New password: newPassTestOne234/');
//$userId 1 and 2 should not have change the password
$this->assertTrue($UsersTable->exists(['id' => $userId001, 'password' => $password001]));
$this->assertTrue($UsersTable->exists(['id' => $userId006, 'password' => $password006]));
/**
* @var \CakeDC\Users\Model\Entity\User $user
*/
$user = $UsersTable->get($userId004);
$this->assertNotEquals($passwordBefore, $user->password);
//Correct password?
$passwordHasher = $user->getPasswordHasher();
$this->assertTrue($passwordHasher->check('newPassTestOne234', $user->get('password')));
}
/**
* Test execute method
*
* @return void
* @uses \CakeDC\Users\Command\UsersResetPasswordCommand::execute()
*/
public function testExecuteNotPassword(): void
{
$UsersTable = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$userId004 = '00000000-0000-0000-0000-000000000004';
$passwordBefore = '$2y$10$Nvu7ipP.z8tiIl75OdUvt.86vuG6iKMoHIOc7O7mboFI85hSyTEde';
$this->assertTrue($UsersTable->exists(['id' => $userId004, 'password' => $passwordBefore]));
$this->exec('cake_d_c/users.users reset_password user-4');
$this->assertExitError();
$this->assertErrorContains('Please enter a password.');
//Password not changed
$this->assertTrue($UsersTable->exists(['id' => $userId004, 'password' => $passwordBefore]));
}
/**
* Test execute method
*
* @return void
* @uses \CakeDC\Users\Command\UsersResetPasswordCommand::execute()
*/
public function testExecuteNotUserName(): void
{
$UsersTable = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$userId004 = '00000000-0000-0000-0000-000000000004';
$passwordBefore = '$2y$10$Nvu7ipP.z8tiIl75OdUvt.86vuG6iKMoHIOc7O7mboFI85hSyTEde';
$this->assertTrue($UsersTable->exists(['id' => $userId004, 'password' => $passwordBefore]));
$this->exec('cake_d_c/users.users reset_password');
$this->assertExitError();
$this->assertErrorContains('Please enter a username.');
//Password not changed
$this->assertTrue($UsersTable->exists(['id' => $userId004, 'password' => $passwordBefore]));
}
}