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