Browse Source

added UserVariableModelTest and updated .env, Libraries/Aauth & UserVariableModel

v3-dev
REJack 6 years ago
parent
commit
2544e44424
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 2
      .env
  2. 8
      application/Libraries/Aauth.php
  3. 9
      application/Models/Aauth/UserVariableModel.php
  4. 92
      tests/Aauth/Database/UserVariableModelTest.php

2
.env

@ -12,6 +12,8 @@
migrations.enabled = true
aauth.dbProfile = 'tests'
#--------------------------------------------------------------------
# APP
#--------------------------------------------------------------------

8
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

9
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;

92
tests/Aauth/Database/UserVariableModelTest.php

@ -0,0 +1,92 @@
<?php namespace Tests\Aauth\Database;
use CodeIgniter\Test\CIDatabaseTestCase;
use App\Models\Aauth\UserVariableModel;
class UserVariableModelTest extends CIDatabaseTestCase
{
protected $refresh = true;
protected $basePath = TESTPATH . '../application' . 'Database/Migrations';
protected $namespace = 'App';
public function setUp()
{
parent::setUp();
$this->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());
}
}
Loading…
Cancel
Save