You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.7 KiB
143 lines
3.7 KiB
6 years ago
|
<?php namespace Tests\Aauth\Database;
|
||
|
|
||
|
use Config\Aauth as AauthConfig;
|
||
|
use CodeIgniter\Test\CIDatabaseTestCase;
|
||
|
use App\Models\Aauth\GroupVariableModel;
|
||
|
|
||
|
class GroupVariableModelTest extends CIDatabaseTestCase
|
||
|
{
|
||
|
protected $refresh = true;
|
||
|
|
||
|
protected $basePath = TESTPATH . '../application' . 'Database/Migrations';
|
||
|
|
||
|
protected $namespace = 'App';
|
||
|
|
||
|
public function setUp()
|
||
|
{
|
||
|
parent::setUp();
|
||
|
|
||
|
$this->model = new GroupVariableModel($this->db);
|
||
|
$this->config = new AauthConfig();
|
||
|
}
|
||
|
|
||
|
//--------------------------------------------------------------------
|
||
|
|
||
|
public function testFind()
|
||
|
{
|
||
|
$groupVariable = $this->model->find(99, 'test');
|
||
|
$this->assertFalse($groupVariable);
|
||
|
|
||
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
$groupVariable = $this->model->find(99, 'test');
|
||
|
$this->assertEquals('TRUE', $groupVariable);
|
||
|
}
|
||
|
|
||
|
public function testFindAll()
|
||
|
{
|
||
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
$groupVariables = $this->model->findAll(99);
|
||
|
$this->assertCount(1, $groupVariables);
|
||
|
}
|
||
|
|
||
|
public function testSave()
|
||
|
{
|
||
|
$this->model->save(99, 'test', 'TRUE');
|
||
|
$this->seeInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
|
||
|
$this->model->save(99, 'test', 'TRUE2');
|
||
|
$this->seeInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE2',
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
public function testDelete()
|
||
|
{
|
||
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
$criteria = [
|
||
|
'group_id' => 99,
|
||
|
];
|
||
|
$this->seeNumRecords(1, $this->config->dbTableGroupVariables, $criteria);
|
||
|
$this->model->delete(99, 'test');
|
||
|
$this->seeNumRecords(0, $this->config->dbTableGroupVariables, $criteria);
|
||
|
}
|
||
|
|
||
|
public function testDeleteAllByGroupId()
|
||
|
{
|
||
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
$criteria = [
|
||
|
'group_id' => 99,
|
||
|
];
|
||
|
$this->seeNumRecords(1, $this->config->dbTableGroupVariables, $criteria);
|
||
|
$this->model->deleteAllByGroupId(99);
|
||
|
$this->seeNumRecords(0, $this->config->dbTableGroupVariables, $criteria);
|
||
|
}
|
||
|
|
||
|
public function testAsArrayFirst()
|
||
|
{
|
||
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
$groupVariable = $this->model->asArray()->where(['data_key' => 'test', 'data_value' => 'TRUE'])->first();
|
||
|
$this->assertInternalType('array', $groupVariable);
|
||
|
}
|
||
|
|
||
|
public function testAsObjectFirst()
|
||
|
{
|
||
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
$groupVariable = $this->model->asObject()->where(['data_key' => 'test', 'data_value' => 'TRUE'])->first();
|
||
|
$this->assertInternalType('object', $groupVariable);
|
||
|
}
|
||
|
|
||
|
public function testConfigDBGroup()
|
||
|
{
|
||
|
$this->model = new GroupVariableModel();
|
||
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [
|
||
|
'group_id' => 99,
|
||
|
'data_key' => 'test',
|
||
|
'data_value' => 'TRUE',
|
||
|
]);
|
||
|
$groupVariable = $this->model->asObject()->where(['data_key' => 'test', 'data_value' => 'TRUE'])->first();
|
||
|
$this->assertInternalType('object', $groupVariable);
|
||
|
}
|
||
|
|
||
|
public function testDBCallEmpty()
|
||
|
{
|
||
|
$this->assertEquals(0, $this->model->insertID());
|
||
|
}
|
||
|
|
||
|
public function testDBCall()
|
||
|
{
|
||
|
$this->model->save(99, 'test', 'TRUE');
|
||
|
$this->assertEquals(1, $this->model->insertID());
|
||
|
}
|
||
|
|
||
|
}
|