45 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2013-12-02 15:25:21 +04:00
<?php
2019-01-27 21:30:35 +01:00
namespace tests\unit\models;
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()
{
verify($user = User::findIdentity(100))->notEmpty();
verify($user->username)->equals('admin');
2016-07-16 04:13:51 +03: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()
{
verify($user = User::findIdentityByAccessToken('100-token'))->notEmpty();
verify($user->username)->equals('admin');
2013-12-02 15:25:21 +04:00
verify(User::findIdentityByAccessToken('non-existing'))->empty();
2016-07-16 04:13:51 +03:00
}
public function testFindUserByUsername()
{
verify($user = User::findByUsername('admin'))->notEmpty();
verify(User::findByUsername('not-admin'))->empty();
2016-07-16 04:13:51 +03:00
}
/**
* @depends testFindUserByUsername
*/
public function testValidateUser()
2014-03-16 10:46:16 +06:00
{
2016-07-16 04:13:51 +03:00
$user = User::findByUsername('admin');
verify($user->validateAuthKey('test100key'))->notEmpty();
verify($user->validateAuthKey('test102key'))->empty();
2016-07-16 04:13:51 +03: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
}