4 changed files with 82 additions and 10 deletions
@ -0,0 +1,28 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\GroupModel; |
||||
|
||||
class GroupModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new GroupModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testDummy() |
||||
{ |
||||
$groups = $this->model->findAll(); |
||||
$this->assertCount(3, $groups); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\PermModel; |
||||
|
||||
class PermModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new PermModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testDummy() |
||||
{ |
||||
$perms = $this->model->findAll(); |
||||
$this->assertCount(0, $perms); |
||||
} |
||||
} |
@ -1,13 +1,10 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use CodeIgniter\Test\ReflectionHelper; |
||||
use App\Models\Aauth\UserModel as UserModel; |
||||
|
||||
class UserModelTest extends CIDatabaseTestCase |
||||
{ |
||||
use ReflectionHelper; |
||||
|
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
@ -32,14 +29,14 @@ class UserModelTest extends CIDatabaseTestCase
|
||||
public function testUpdateLastLogin() |
||||
{ |
||||
$this->model->updateLastLogin(1); |
||||
$user = $this->model->find(1); |
||||
$user = $this->model->asArray()->find(1); |
||||
$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); |
||||
$user = $this->model->find(1); |
||||
$user = $this->model->asArray()->find(1); |
||||
$this->assertTrue(strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity'])); |
||||
} |
||||
|
||||
@ -85,11 +82,29 @@ class UserModelTest extends CIDatabaseTestCase
|
||||
$this->assertFalse($this->model->existsByUsername("")); |
||||
} |
||||
|
||||
public function testHashPassword() |
||||
public function testHashPasswordFilled() |
||||
{ |
||||
$userOld = $this->model->find(1); |
||||
$userOld = $this->model->asArray()->find(1); |
||||
$this->model->update(1, ['id' => 1, 'password' => 'password123456']); |
||||
$userNew = $this->model->find(1); |
||||
$userNew = $this->model->asArray()->find(1); |
||||
$this->assertTrue($userOld['password'] != $userNew['password'] && $userNew['password'] != 'password123456'); |
||||
} |
||||
|
||||
public function testHashPasswordNotSet() |
||||
{ |
||||
$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); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue