2013-12-02 19:25:21 +08:00
|
|
|
<?php
|
2017-09-12 17:29:58 +08:00
|
|
|
|
2019-01-28 04:30:35 +08:00
|
|
|
namespace tests\unit\models;
|
2017-09-12 17:29:58 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
use app\models\User;
|
2013-12-02 19:25:21 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
class UserTest extends \Codeception\Test\Unit
|
|
|
|
{
|
|
|
|
public function testFindUserById()
|
|
|
|
{
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($user = User::findIdentity(100))->notEmpty();
|
|
|
|
verify($user->username)->equals('admin');
|
2016-07-16 09:13:51 +08:00
|
|
|
|
2022-02-25 22:58:50 +08:00
|
|
|
verify(User::findIdentity(999))->empty();
|
2016-07-16 09:13:51 +08:00
|
|
|
}
|
2013-12-02 19:25:21 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
public function testFindUserByAccessToken()
|
|
|
|
{
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($user = User::findIdentityByAccessToken('100-token'))->notEmpty();
|
|
|
|
verify($user->username)->equals('admin');
|
2013-12-02 19:25:21 +08:00
|
|
|
|
2022-02-25 22:58:50 +08:00
|
|
|
verify(User::findIdentityByAccessToken('non-existing'))->empty();
|
2016-07-16 09:13:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindUserByUsername()
|
|
|
|
{
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($user = User::findByUsername('admin'))->notEmpty();
|
|
|
|
verify(User::findByUsername('not-admin'))->empty();
|
2016-07-16 09:13:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testFindUserByUsername
|
|
|
|
*/
|
2022-06-18 00:15:52 +08:00
|
|
|
public function testValidateUser()
|
2014-03-16 12:46:16 +08:00
|
|
|
{
|
2016-07-16 09:13:51 +08:00
|
|
|
$user = User::findByUsername('admin');
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($user->validateAuthKey('test100key'))->notEmpty();
|
|
|
|
verify($user->validateAuthKey('test102key'))->empty();
|
2016-07-16 09:13:51 +08:00
|
|
|
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($user->validatePassword('admin'))->notEmpty();
|
|
|
|
verify($user->validatePassword('123456'))->empty();
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
2013-12-02 19:25:21 +08:00
|
|
|
|
|
|
|
}
|