diff --git a/.env b/.env index 3778f55..4195f17 100644 --- a/.env +++ b/.env @@ -12,6 +12,8 @@ migrations.enabled = true +aauth.dbProfile = 'tests' + #-------------------------------------------------------------------- # APP #-------------------------------------------------------------------- diff --git a/application/Libraries/Aauth.php b/application/Libraries/Aauth.php index 9f5f437..8a3947b 100644 --- a/application/Libraries/Aauth.php +++ b/application/Libraries/Aauth.php @@ -17,10 +17,10 @@ namespace App\Libraries; -use \App\Models\Aauth\UserModel as UserModel; -use \App\Models\Aauth\LoginAttemptModel as LoginAttemptModel; -use \App\Models\Aauth\LoginTokenModel as LoginTokenModel; -use \App\Models\Aauth\UserVariableModel as UserVariableModel; +use \App\Models\Aauth\UserModel; +use \App\Models\Aauth\LoginAttemptModel; +use \App\Models\Aauth\LoginTokenModel; +use \App\Models\Aauth\UserVariableModel; /** * Aauth Library diff --git a/application/Models/Aauth/UserVariableModel.php b/application/Models/Aauth/UserVariableModel.php index 92dae69..7defd88 100644 --- a/application/Models/Aauth/UserVariableModel.php +++ b/application/Models/Aauth/UserVariableModel.php @@ -260,7 +260,7 @@ class UserVariableModel */ public function asArray() { - $this->tempReturnType = 'array'; + $this->tempReturnType = $this->returnType = 'array'; return $this; } @@ -277,7 +277,7 @@ class UserVariableModel */ public function asObject(string $class = 'object') { - $this->tempReturnType = $class; + $this->tempReturnType = $this->returnType = $class; return $this; } @@ -316,11 +316,6 @@ class UserVariableModel $table = empty($table) ? $this->table : $table; - if (! $this->db instanceof BaseConnection) - { - $this->db = Database::connect($this->DBGroup); - } - $this->builder = $this->db->table($table); return $this->builder; diff --git a/tests/Aauth/Database/UserVariableModelTest.php b/tests/Aauth/Database/UserVariableModelTest.php new file mode 100644 index 0000000..ec94da5 --- /dev/null +++ b/tests/Aauth/Database/UserVariableModelTest.php @@ -0,0 +1,92 @@ +model = new UserVariableModel($this->db); + } + + //-------------------------------------------------------------------- + + public function testFindFalse() + { + $userVariable = $this->model->find(1, 'test'); + $this->assertFalse($userVariable); + } + + public function testFindReturn() + { + $this->model->save(1, 'test', 'TRUE'); + $userVariable = $this->model->find(1, 'test'); + $this->assertEquals('TRUE', $userVariable); + } + + public function testFindAll() + { + $this->model->save(1, 'test', 'TRUE'); + $userVariables = $this->model->findAll(1); + $this->assertCount(1, $userVariables); + } + + public function testSaveUpdate() + { + $this->model->save(1, 'test', 'TRUE'); + $this->model->save(1, 'test', 'TRUE2'); + $userVariable = $this->model->find(1, 'test'); + $this->assertEquals('TRUE2', $userVariable); + } + + public function testDelete() + { + $this->model->save(1, 'test', 'TRUE'); + $this->model->delete(1, 'test'); + $userVariables = $this->model->findAll(1); + $this->assertCount(0, $userVariables); + } + + public function testAsArrayFirst() + { + $this->model->save(1, 'test', 'TRUE'); + $userVariable = $this->model->asArray()->where(['data_key'=>'test', 'data_value'=>'TRUE'])->first(); + $this->assertInternalType('array', $userVariable); + } + + public function testAsObjectFirst() + { + $this->model->save(1, 'test', 'TRUE'); + $userVariable = $this->model->asObject()->where(['data_key'=>'test', 'data_value'=>'TRUE'])->first(); + $this->assertInternalType('object', $userVariable); + } + + public function testConfigDBGroup() + { + $this->model = new UserVariableModel(); + $this->model->save(1, 'test', 'TRUE'); + $userVariable = $this->model->asObject()->where(['data_key'=>'test', 'data_value'=>'TRUE'])->first(); + $this->assertInternalType('object', $userVariable); + } + + public function testDBCallEmpty() + { + $this->assertEquals(0, $this->model->insertID()); + } + + public function testDBCall() + { + $this->model->save(1, 'test', 'TRUE'); + $this->assertEquals(1, $this->model->insertID()); + } + +}