-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,35 @@ public function testCreate(): void | |
]); | ||
} | ||
|
||
public function testCreateNotUniqueName(): void | ||
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 7.4 - Postgre - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 8.0 - SQLite3 - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 8.0 - MySQLi - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 7.4 - MySQLi - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 8.2 - SQLite3 - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 8.2 - MySQLi - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 7.4 - SQLSRV - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 7.4 - SQLite3 - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 7.4 - MySQLi - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 8.1 - MySQLi - highest
Check warning on line 66 in tests/Commands/UserTest.php GitHub Actions / phpunit / PHP 8.1 - SQLite3 - highest
|
||
{ | ||
$user = $this->createUser([ | ||
'username' => 'user1', | ||
'email' => '[email protected]', | ||
'password' => 'secret123', | ||
]); | ||
|
||
$this->setMockIo([ | ||
'Secret Passw0rd!', | ||
'Secret Passw0rd!', | ||
]); | ||
|
||
command('shield:user create -n user1 -e [email protected]'); | ||
|
||
$this->assertStringContainsString( | ||
'The Username field must contain a unique value.', | ||
$this->io->getOutputs() | ||
); | ||
$this->assertStringContainsString( | ||
'User creation aborted', | ||
$this->io->getOutputs() | ||
); | ||
|
||
$users = model(UserModel::class); | ||
$user = $users->findByCredentials(['email' => '[email protected]']); | ||
$this->assertNull($user); | ||
} | ||
|
||
/** | ||
* Create an active user. | ||
*/ | ||
|
@@ -156,6 +185,35 @@ public function testChangename(): void | |
]); | ||
} | ||
|
||
public function testChangenameInvalidName(): void | ||
{ | ||
$this->createUser([ | ||
'username' => 'user4', | ||
'email' => '[email protected]', | ||
'password' => 'secret123', | ||
]); | ||
|
||
$this->setMockIo(['y']); | ||
|
||
command('shield:user changename -n user4 --new-name 1'); | ||
|
||
$this->assertStringContainsString( | ||
'The Username field must be at least 3 characters in length.', | ||
$this->io->getOutputs() | ||
); | ||
$this->assertStringContainsString( | ||
'User name change aborted', | ||
$this->io->getOutputs() | ||
); | ||
|
||
$users = model(UserModel::class); | ||
$user = $users->findByCredentials(['email' => '[email protected]']); | ||
$this->seeInDatabase($this->tables['users'], [ | ||
'id' => $user->id, | ||
'username' => 'user4', | ||
]); | ||
} | ||
|
||
public function testChangeemail(): void | ||
{ | ||
$this->createUser([ | ||
|
@@ -181,6 +239,32 @@ public function testChangeemail(): void | |
]); | ||
} | ||
|
||
public function testChangeemailInvalidEmail(): void | ||
{ | ||
$this->createUser([ | ||
'username' => 'user5', | ||
'email' => '[email protected]', | ||
'password' => 'secret123', | ||
]); | ||
|
||
$this->setMockIo(['y']); | ||
|
||
command('shield:user changeemail -n user5 --new-email invalid'); | ||
|
||
$this->assertStringContainsString( | ||
'The Email Address field must contain a valid email address.', | ||
$this->io->getOutputs() | ||
); | ||
$this->assertStringContainsString( | ||
'User email change aborted', | ||
$this->io->getOutputs() | ||
); | ||
|
||
$users = model(UserModel::class); | ||
$user = $users->findByCredentials(['email' => 'invalid']); | ||
$this->assertNull($user); | ||
} | ||
|
||
public function testDelete(): void | ||
{ | ||
$this->createUser([ | ||
|
@@ -203,6 +287,28 @@ public function testDelete(): void | |
$this->assertNull($user); | ||
} | ||
|
||
public function testDeleteById(): void | ||
{ | ||
$user = $this->createUser([ | ||
'username' => 'user6', | ||
'email' => '[email protected]', | ||
'password' => 'secret123', | ||
]); | ||
|
||
$this->setMockIo(['y']); | ||
|
||
command('shield:user delete -i ' . $user->id); | ||
|
||
$this->assertStringContainsString( | ||
'User "user6" deleted', | ||
$this->io->getLastOutput() | ||
); | ||
|
||
$users = model(UserModel::class); | ||
$user = $users->findByCredentials(['email' => '[email protected]']); | ||
$this->assertNull($user); | ||
} | ||
|
||
public function testPassword(): void | ||
{ | ||
$this->createUser([ | ||
|