Browse Source

updated UserModel, UserModelTest & UserTest

v3-dev
REJack 6 years ago
parent
commit
ee445cf1a3
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 13
      application/Models/Aauth/UserModel.php
  2. 7
      tests/Aauth/Database/UserModelTest.php
  3. 1
      tests/Aauth/Libraries/Aauth/UserTest.php

13
application/Models/Aauth/UserModel.php

@ -89,13 +89,18 @@ class UserModel extends Model
{ {
parent::__construct(); parent::__construct();
$this->config = (object) array_merge((array) new AauthConfig(), (array) $config); if (is_null($config))
{
$config = new \Config\Aauth();
}
$this->config = $config;
$this->table = $this->config->dbTableUsers; $this->table = $this->config->dbTableUsers;
$this->DBGroup = $this->config->dbProfile; $this->DBGroup = $this->config->dbProfile;
$this->validationRules['email'] = 'required|if_exist|valid_email|is_unique[' . $this->table . '.email,id,{id}]'; $this->validationRules['email'] = 'required|if_exist|valid_email|is_unique[' . $this->table . '.email,id,{$id}]';
$this->validationRules['password'] = 'required|if_exist|min_length[' . $this->config->passwordMin . ']|max_length[' . $this->config->passwordMax . ']'; $this->validationRules['password'] = 'required|if_exist|min_length[' . $this->config->passwordMin . ']|max_length[' . $this->config->passwordMax . ']';
$this->validationRules['username'] = 'if_exist|is_unique[' . $this->table . '.username,id,{id}]|min_length[3]|regex_match[/' . $this->config->userRegexPattern . '/]'; $this->validationRules['username'] = 'if_exist|is_unique[' . $this->table . '.username,id,{$id}]|min_length[3]|regex_match[/' . $this->config->userRegexPattern . '/]';
$this->validationMessages = [ $this->validationMessages = [
'email' => [ 'email' => [
@ -117,7 +122,7 @@ class UserModel extends Model
if ($this->config->loginUseUsername) if ($this->config->loginUseUsername)
{ {
$this->validationRules['username'] = 'required|if_exist|is_unique[' . $this->table . '.username,id,{id}]|min_length[3]|regex_match[/' . $this->config->userRegexPattern . '/]'; $this->validationRules['username'] = 'required|if_exist|is_unique[' . $this->table . '.username,id,{$id}]|min_length[3]|regex_match[/' . $this->config->userRegexPattern . '/]';
$this->validationMessages['username']['required'] = lang('Aauth.requiredUsername'); $this->validationMessages['username']['required'] = lang('Aauth.requiredUsername');
} }

7
tests/Aauth/Database/UserModelTest.php

@ -1,7 +1,8 @@
<?php namespace Tests\Aauth\Database; <?php namespace Tests\Aauth\Database;
use Config\Aauth as AauthConfig;
use CodeIgniter\Test\CIDatabaseTestCase; use CodeIgniter\Test\CIDatabaseTestCase;
use App\Models\Aauth\UserModel as UserModel; use App\Models\Aauth\UserModel;
class UserModelTest extends CIDatabaseTestCase class UserModelTest extends CIDatabaseTestCase
{ {
@ -84,8 +85,8 @@ class UserModelTest extends CIDatabaseTestCase
public function testLoginUseUsernameDummy() public function testLoginUseUsernameDummy()
{ {
$config = new \Config\Aauth(); $config = new AauthConfig();
$config->loginUseUsername = TRUE; $config->loginUseUsername = true;
$this->model = new UserModel($this->db, null, $config); $this->model = new UserModel($this->db, null, $config);
$newUser = $this->model->insert(['email' => 'test@test.local', 'password' => 'password123456']); $newUser = $this->model->insert(['email' => 'test@test.local', 'password' => 'password123456']);

1
tests/Aauth/Libraries/Aauth/UserTest.php

@ -83,7 +83,6 @@ class UserTest extends CIDatabaseTestCase
$this->library->clearInfos(); $this->library->clearInfos();
$this->assertFalse($this->library->updateUser(2, 'admin@example.com', null, null)); $this->assertFalse($this->library->updateUser(2, 'admin@example.com', null, null));
print_r($this->library->getUser(2));
$this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]); $this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors(); $this->library->clearErrors();

Loading…
Cancel
Save