You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.7 KiB
95 lines
2.7 KiB
6 years ago
|
<?php namespace Tests\Aauth\Database;
|
||
|
|
||
|
use CodeIgniter\Test\CIDatabaseTestCase;
|
||
6 years ago
|
use App\Models\Aauth\UserModel as UserModel;
|
||
6 years ago
|
|
||
|
class UserModelTest extends CIDatabaseTestCase
|
||
|
{
|
||
|
protected $refresh = true;
|
||
|
|
||
6 years ago
|
protected $basePath = TESTPATH . '../application' . 'Database/Migrations';
|
||
6 years ago
|
|
||
|
protected $namespace = 'App';
|
||
|
|
||
|
public function setUp()
|
||
|
{
|
||
|
parent::setUp();
|
||
|
|
||
6 years ago
|
$this->model = new UserModel($this->db);
|
||
6 years ago
|
}
|
||
|
|
||
|
//--------------------------------------------------------------------
|
||
|
|
||
|
public function testFindReturnsRow()
|
||
|
{
|
||
|
$user = $this->model->find(1);
|
||
|
$this->assertEquals('admin', $user['username']);
|
||
|
}
|
||
|
|
||
6 years ago
|
public function testUpdateLastLogin()
|
||
|
{
|
||
|
$this->model->updateLastLogin(1);
|
||
6 years ago
|
$user = $this->model->asArray()->find(1);
|
||
6 years ago
|
$this->assertTrue((strtotime("-5 seconds") < strtotime($user['last_login']) && strtotime("+5 seconds") > strtotime($user['last_login'])) && strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity']));
|
||
|
}
|
||
|
|
||
|
public function testUpdateLastActivity()
|
||
|
{
|
||
|
$this->model->updateLastActivity(1);
|
||
6 years ago
|
$user = $this->model->asArray()->find(1);
|
||
6 years ago
|
$this->assertTrue(strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity']));
|
||
|
}
|
||
|
|
||
6 years ago
|
public function testUpdateBanned()
|
||
6 years ago
|
{
|
||
6 years ago
|
$this->assertFalse($this->model->isBanned(1));
|
||
|
|
||
6 years ago
|
$this->model->updateBanned(1, TRUE);
|
||
|
$this->assertTrue($this->model->isBanned(1));
|
||
|
}
|
||
|
|
||
6 years ago
|
public function testExistsById()
|
||
6 years ago
|
{
|
||
|
$this->assertTrue($this->model->existsById(1));
|
||
|
|
||
|
$this->assertFalse($this->model->existsById(0));
|
||
|
}
|
||
|
|
||
6 years ago
|
public function testExistsByEmail()
|
||
6 years ago
|
{
|
||
|
$this->assertTrue($this->model->existsByEmail("[email protected]"));
|
||
|
|
||
|
$this->assertFalse($this->model->existsByEmail(""));
|
||
|
}
|
||
|
|
||
6 years ago
|
public function testExistsByUsername()
|
||
6 years ago
|
{
|
||
|
$this->assertTrue($this->model->existsByUsername("admin"));
|
||
|
|
||
|
$this->assertFalse($this->model->existsByUsername(""));
|
||
|
}
|
||
|
|
||
6 years ago
|
public function testHashPasswordFilled()
|
||
6 years ago
|
{
|
||
6 years ago
|
$userOld = $this->model->asArray()->find(1);
|
||
6 years ago
|
$this->model->update(1, ['id' => 1, 'password' => 'password123456']);
|
||
6 years ago
|
$userNew = $this->model->asArray()->find(1);
|
||
6 years ago
|
$this->assertTrue($userOld['password'] != $userNew['password'] && $userNew['password'] != 'password123456');
|
||
6 years ago
|
|
||
|
$userOld = $this->model->asArray()->find(1);
|
||
|
$this->model->update(1, ['id' => 1, 'username' => 'admin']);
|
||
|
$userNew = $this->model->asArray()->find(1);
|
||
|
$this->assertEquals($userOld['password'], $userNew['password']);
|
||
|
}
|
||
|
|
||
|
public function testLoginUseUsernameDummy()
|
||
|
{
|
||
|
$config = new \Config\Aauth();
|
||
|
$config->loginUseUsername = TRUE;
|
||
|
|
||
|
$this->model = new UserModel($this->db, null, $config);
|
||
|
$newUser = $this->model->insert(['email' => '[email protected]', 'password' => 'password123456']);
|
||
|
$this->assertFalse($newUser);
|
||
|
}
|
||
6 years ago
|
}
|