45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace tests\unit\models;
|
||
|
|
||
|
use app\models\User;
|
||
|
|
||
|
class UserTest extends \Codeception\Test\Unit
|
||
|
{
|
||
|
public function testFindUserById()
|
||
|
{
|
||
|
verify($user = User::findIdentity(100))->notEmpty();
|
||
|
verify($user->username)->equals('admin');
|
||
|
|
||
|
verify(User::findIdentity(999))->empty();
|
||
|
}
|
||
|
|
||
|
public function testFindUserByAccessToken()
|
||
|
{
|
||
|
verify($user = User::findIdentityByAccessToken('100-token'))->notEmpty();
|
||
|
verify($user->username)->equals('admin');
|
||
|
|
||
|
verify(User::findIdentityByAccessToken('non-existing'))->empty();
|
||
|
}
|
||
|
|
||
|
public function testFindUserByUsername()
|
||
|
{
|
||
|
verify($user = User::findByUsername('admin'))->notEmpty();
|
||
|
verify(User::findByUsername('not-admin'))->empty();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @depends testFindUserByUsername
|
||
|
*/
|
||
|
public function testValidateUser()
|
||
|
{
|
||
|
$user = User::findByUsername('admin');
|
||
|
verify($user->validateAuthKey('test100key'))->notEmpty();
|
||
|
verify($user->validateAuthKey('test102key'))->empty();
|
||
|
|
||
|
verify($user->validatePassword('admin'))->notEmpty();
|
||
|
verify($user->validatePassword('123456'))->empty();
|
||
|
}
|
||
|
|
||
|
}
|