Browse Source

updated UserModel and UserModelTest & added GroupModelTest and PermModelTest

v3-dev
REJack 6 years ago
parent
commit
edb5a57d49
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 5
      application/Models/Aauth/UserModel.php
  2. 28
      tests/Aauth/Database/GroupModelTest.php
  3. 28
      tests/Aauth/Database/PermModelTest.php
  4. 31
      tests/Aauth/Database/UserModelTest.php

5
application/Models/Aauth/UserModel.php

@ -85,10 +85,11 @@ class UserModel extends Model
/** /**
* Constructor * Constructor
*/ */
public function __construct() public function __construct($db = NULL, $validation = NULL, $config = NULL)
{ {
parent::__construct(); parent::__construct();
$this->config = new AauthConfig();
$this->config = (object) array_merge((array) new AauthConfig(), (array) $config);
$this->table = $this->config->dbTableUsers; $this->table = $this->config->dbTableUsers;
$this->DBGroup = $this->config->dbProfile; $this->DBGroup = $this->config->dbProfile;

28
tests/Aauth/Database/GroupModelTest.php

@ -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);
}
}

28
tests/Aauth/Database/PermModelTest.php

@ -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);
}
}

31
tests/Aauth/Database/UserModelTest.php

@ -1,13 +1,10 @@
<?php namespace Tests\Aauth\Database; <?php namespace Tests\Aauth\Database;
use CodeIgniter\Test\CIDatabaseTestCase; use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\ReflectionHelper;
use App\Models\Aauth\UserModel as UserModel; use App\Models\Aauth\UserModel as UserModel;
class UserModelTest extends CIDatabaseTestCase class UserModelTest extends CIDatabaseTestCase
{ {
use ReflectionHelper;
protected $refresh = true; protected $refresh = true;
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; protected $basePath = TESTPATH . '../application' . 'Database/Migrations';
@ -32,14 +29,14 @@ class UserModelTest extends CIDatabaseTestCase
public function testUpdateLastLogin() public function testUpdateLastLogin()
{ {
$this->model->updateLastLogin(1); $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'])); $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() public function testUpdateLastActivity()
{ {
$this->model->updateLastActivity(1); $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'])); $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("")); $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']); $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'); $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…
Cancel
Save