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()
|
|
|
|
{
|
|
|
|
expect_that($user = User::findIdentity(100));
|
|
|
|
expect($user->username)->equals('admin');
|
|
|
|
|
|
|
|
expect_not(User::findIdentity(999));
|
|
|
|
}
|
2013-12-02 15:25:21 +04:00
|
|
|
|
2016-07-16 04:13:51 +03:00
|
|
|
public function testFindUserByAccessToken()
|
|
|
|
{
|
|
|
|
expect_that($user = User::findIdentityByAccessToken('100-token'));
|
|
|
|
expect($user->username)->equals('admin');
|
2013-12-02 15:25:21 +04:00
|
|
|
|
2016-07-16 04:13:51 +03:00
|
|
|
expect_not(User::findIdentityByAccessToken('non-existing'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindUserByUsername()
|
|
|
|
{
|
|
|
|
expect_that($user = User::findByUsername('admin'));
|
|
|
|
expect_not(User::findByUsername('not-admin'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testFindUserByUsername
|
|
|
|
*/
|
|
|
|
public function testValidateUser($user)
|
2014-03-16 10:46:16 +06:00
|
|
|
{
|
2016-07-16 04:13:51 +03:00
|
|
|
$user = User::findByUsername('admin');
|
|
|
|
expect_that($user->validateAuthKey('test100key'));
|
|
|
|
expect_not($user->validateAuthKey('test102key'));
|
|
|
|
|
|
|
|
expect_that($user->validatePassword('admin'));
|
2016-07-18 20:33:45 +03:00
|
|
|
expect_not($user->validatePassword('123456'));
|
2014-03-16 10:46:16 +06:00
|
|
|
}
|
2013-12-02 15:25:21 +04:00
|
|
|
|
|
|
|
}
|