forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersAddSuperuserCommandTest.php
More file actions
73 lines (67 loc) · 2.57 KB
/
UsersAddSuperuserCommandTest.php
File metadata and controls
73 lines (67 loc) · 2.57 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
<?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\UsersAddSuperuserCommand Test Case
*
* @uses \CakeDC\Users\Command\UsersAddSuperuserCommand
*/
class UsersAddSuperuserCommandTest 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\UsersAddUserCommand::execute()
*/
public function testExecuteWithArgs(): void
{
$username = 'yeliparra.admin';
$UsersTable = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$this->assertFalse($UsersTable->exists(['username' => $username]));
$this->exec('cake_d_c/users.users add_superuser --username=yeliparra.admin --password=123456 --email=yeli.parra.testing01@testing.com --role=admin-tester');
$this->_out->messages();
$this->assertOutputRegExp('/Superuser added:/');
$this->assertOutputRegExp('/Username: yeliparra.admin/');
$this->assertOutputRegExp('/Email: yeli.parra.testing01@testing.com/');
$this->assertOutputRegExp('/Role: admin-tester/');
$this->assertOutputRegExp('/Password: 123456$/');
/**
* @var \CakeDC\Users\Model\Entity\User $user
*/
$user = $UsersTable->find()->where(['username' => $username])->firstOrFail();
$this->assertSame('yeli.parra.testing01@testing.com', $user->email);
$this->assertSame('admin-tester', $user->role);
$this->assertTrue($user->is_superuser);
//Correct password?
$passwordHasher = $user->getPasswordHasher();
$this->assertTrue($passwordHasher->check('123456', $user->get('password')));
}
/**
* Test execute method
*
* @return void
* @uses \CakeDC\Users\Command\UsersAddUserCommand::execute()
*/
public function testExecuteWithNoParams(): void
{
$this->exec('cake_d_c/users.users add_superuser');
$this->assertOutputRegExp('/^Superuser added:/');
$this->assertOutputRegExp('/Username: superadmin/');
$this->assertOutputRegExp('/Email: superadmin@example.com/');
$this->assertOutputRegExp('/Role: ' . UsersTable::ROLE_ADMIN . '/');
$this->assertOutputRegExp('/Password: [a-z0-9]{32}$/');
}
}