yii2-netdisk/tests/unit/models/UserTest.php

45 lines
1.2 KiB
PHP
Raw Normal View History

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