Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Unit/UserTest.php
<?php | <?php | ||||
namespace Tests\Unit; | namespace Tests\Unit; | ||||
use App\User; | use App\User; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class UserTest extends TestCase | class UserTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* Test User password mutator | |||||
*/ | |||||
public function testSetPasswordAttribute(): void | |||||
{ | |||||
$user = new User(['email' => 'user@email.com']); | |||||
$user->password = 'test'; | |||||
$ssh512 = "{SSHA512}7iaw3Ur350mqGo7jwQrpkj9hiYB3Lkc/iBml1JQODbJ" | |||||
. "6wYX4oOHV+E+IvIh/1nsUNzLDBMxfqa2Ob1f1ACio/w=="; | |||||
$this->assertRegExp('/^\$2y\$12\$[0-9a-zA-Z\/.]{53}$/', $user->password); | |||||
$this->assertSame($ssh512, $user->password_ldap); | |||||
} | |||||
/** | |||||
* Test User password mutator | |||||
*/ | |||||
public function testSetPasswordLdapAttribute(): void | |||||
{ | |||||
$user = new User(['email' => 'user@email.com']); | |||||
$user->password_ldap = 'test'; | |||||
$ssh512 = "{SSHA512}7iaw3Ur350mqGo7jwQrpkj9hiYB3Lkc/iBml1JQODbJ" | |||||
. "6wYX4oOHV+E+IvIh/1nsUNzLDBMxfqa2Ob1f1ACio/w=="; | |||||
$this->assertRegExp('/^\$2y\$12\$[0-9a-zA-Z\/.]{53}$/', $user->password); | |||||
$this->assertSame($ssh512, $user->password_ldap); | |||||
} | |||||
/** | |||||
* Test basic User funtionality | * Test basic User funtionality | ||||
*/ | */ | ||||
public function testUserStatus() | public function testStatus(): void | ||||
{ | { | ||||
$statuses = [ | $statuses = [ | ||||
User::STATUS_NEW, | User::STATUS_NEW, | ||||
User::STATUS_ACTIVE, | User::STATUS_ACTIVE, | ||||
User::STATUS_SUSPENDED, | User::STATUS_SUSPENDED, | ||||
User::STATUS_DELETED, | User::STATUS_DELETED, | ||||
User::STATUS_IMAP_READY, | User::STATUS_IMAP_READY, | ||||
User::STATUS_LDAP_READY, | User::STATUS_LDAP_READY, | ||||
Show All 16 Lines | public function testStatus(): void | ||||
$this->assertTrue($user->isLdapReady() === in_array(User::STATUS_LDAP_READY, $user_statuses)); | $this->assertTrue($user->isLdapReady() === in_array(User::STATUS_LDAP_READY, $user_statuses)); | ||||
$this->assertTrue($user->isImapReady() === in_array(User::STATUS_IMAP_READY, $user_statuses)); | $this->assertTrue($user->isImapReady() === in_array(User::STATUS_IMAP_READY, $user_statuses)); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Test setStatusAttribute exception | * Test setStatusAttribute exception | ||||
*/ | */ | ||||
public function testUserStatusInvalid(): void | public function testStatusInvalid(): void | ||||
{ | { | ||||
$this->expectException(\Exception::class); | $this->expectException(\Exception::class); | ||||
$user = new User( | $user = new User( | ||||
[ | [ | ||||
'email' => 'user@email.com', | 'email' => 'user@email.com', | ||||
'status' => 1234567, | 'status' => 1234567, | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
} | } |