forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersChangeRoleCommandTest.php
More file actions
107 lines (96 loc) · 3.9 KB
/
UsersChangeRoleCommandTest.php
File metadata and controls
107 lines (96 loc) · 3.9 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
<?php
declare(strict_types=1);
namespace CakeDC\Users\Test\TestCase\Command;
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Model\Table\UsersTable;
/**
* CakeDC\Users\Command\UsersChangeRoleCommand Test Case
*
* @uses \CakeDC\Users\Command\UsersChangeRoleCommand
*/
class UsersChangeRoleCommandTest 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\UsersChangeRoleCommand::execute()
*/
public function testExecute(): void
{
$UsersTable = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$userIdTarget = '00000000-0000-0000-0000-000000000004';
$userId006 = '00000000-0000-0000-0000-000000000006';
$roleBefore = 'Lorem ipsum dolor sit amet';
$userId001 = '00000000-0000-0000-0000-000000000001';
$role001 = UsersTable::ROLE_ADMIN;
$role006 = UsersTable::ROLE_USER;
$this->assertTrue($UsersTable->exists(['id' => $userIdTarget, 'role' => $roleBefore]));
$this->assertTrue($UsersTable->exists(['id' => $userId001, 'role' => $role001]));
$this->assertTrue($UsersTable->exists(['id' => $userId006, 'role' => $role006]));
$this->exec('cake_d_c/users.users change_role user-4 test-execute-001');
$this->assertExitSuccess();
$this->assertOutputRegExp('/Role changed for user: user-4/');
$this->assertOutputRegExp('/New role: test-execute-001/');
//$userId 1 and 2 should not have change the password
$this->assertTrue($UsersTable->exists(['id' => $userId001, 'role' => $role001]));
$this->assertTrue($UsersTable->exists(['id' => $userId006, 'role' => $role006]));
//Target must have changed
$this->assertTrue($UsersTable->exists(['id' => $userIdTarget, 'role' => 'test-execute-001']));
}
/**
* Test execute method
*
* @param string $command
* @param string $expectedMessage
* @return void
* @dataProvider dataProviderExecuteMissingInfo
* @uses \CakeDC\Users\Command\UsersChangeRoleCommand::execute()
*/
public function testExecuteMissingInfo(string $command, $expectedMessage): void
{
$UsersTable = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$userIdTarget = '00000000-0000-0000-0000-000000000004';
$userId006 = '00000000-0000-0000-0000-000000000006';
$roleBefore = 'Lorem ipsum dolor sit amet';
$userId001 = '00000000-0000-0000-0000-000000000001';
$role001 = UsersTable::ROLE_ADMIN;
$role006 = UsersTable::ROLE_USER;
$this->assertTrue($UsersTable->exists(['id' => $userIdTarget, 'role' => $roleBefore]));
$this->assertTrue($UsersTable->exists(['id' => $userId001, 'role' => $role001]));
$this->assertTrue($UsersTable->exists(['id' => $userId006, 'role' => $role006]));
$this->exec($command);
$this->assertExitError();
$this->assertErrorContains($expectedMessage);
//should not have change the password
$this->assertTrue($UsersTable->exists(['id' => $userId001, 'role' => $role001]));
$this->assertTrue($UsersTable->exists(['id' => $userId006, 'role' => $role006]));
$this->assertTrue($UsersTable->exists(['id' => $userIdTarget, 'role' => $roleBefore]));
}
/**
* @return array
*/
public static function dataProviderExecuteMissingInfo(): array
{
return [
[
'cake_d_c/users.users change_role user-4',
'Please enter a role.',
],
[
'cake_d_c/users.users change_role',
'Please enter a username.',
],
];
}
}