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.
107 lines
2.8 KiB
107 lines
2.8 KiB
<?php namespace Tests\Aauth\Libraries\Aauth; |
|
|
|
use Config\Aauth as AauthConfig; |
|
use Config\Logger; |
|
use Config\Services; |
|
use Tests\Support\Log\TestLogger; |
|
use Tests\Support\Session\MockSession; |
|
use CodeIgniter\Session\Handlers\FileHandler; |
|
use CodeIgniter\Test\CIDatabaseTestCase; |
|
use App\Libraries\Aauth; |
|
use App\Models\Aauth\GroupVariableModel; |
|
|
|
class GroupVariablesTest extends CIDatabaseTestCase |
|
{ |
|
protected $refresh = true; |
|
|
|
protected $basePath = FCPATH . '../app/Database/Migrations'; |
|
|
|
protected $namespace = 'App'; |
|
|
|
public function setUp() |
|
{ |
|
parent::setUp(); |
|
|
|
$this->library = new Aauth(null, true); |
|
$this->config = new AauthConfig(); |
|
} |
|
|
|
//-------------------------------------------------------------------- |
|
|
|
public function testSetGroupVar() |
|
{ |
|
$this->assertTrue($this->library->setGroupVar('test_var', 'test', 1)); |
|
$this->seeInDatabase($this->config->dbTableGroupVariables, [ |
|
'group_id' => 1, |
|
'data_key' => 'test_var', |
|
'data_value' => 'test', |
|
]); |
|
|
|
$this->assertFalse($this->library->setGroupVar('test_var', 'test', 99)); |
|
} |
|
|
|
public function testUnsetGroupVar() |
|
{ |
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [ |
|
'group_id' => 1, |
|
'data_key' => 'test_var', |
|
'data_value' => 'test', |
|
]); |
|
|
|
$this->assertTrue($this->library->unsetGroupVar('test_var', 1)); |
|
|
|
$this->assertFalse($this->library->unsetGroupVar('test_var', 99)); |
|
} |
|
|
|
public function testGetGroupVar() |
|
{ |
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [ |
|
'group_id' => 1, |
|
'data_key' => 'test_var', |
|
'data_value' => 'test', |
|
]); |
|
|
|
$this->assertEquals('test', $this->library->getGroupVar('test_var', 1)); |
|
|
|
$this->assertFalse($this->library->getGroupVar('test_var_99', 1)); |
|
|
|
$this->assertFalse($this->library->getGroupVar('test_var', 99)); |
|
} |
|
|
|
public function testGetGroupVars() |
|
{ |
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [ |
|
'group_id' => 1, |
|
'data_key' => 'test_var', |
|
'data_value' => 'test', |
|
]); |
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [ |
|
'group_id' => 1, |
|
'data_key' => 'test_var2', |
|
'data_value' => 'test2', |
|
]); |
|
|
|
$this->assertCount(2, $this->library->getGroupVars(1)); |
|
|
|
$this->assertFalse($this->library->getGroupVars(99)); |
|
} |
|
|
|
public function testListGroupVarKeys() |
|
{ |
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [ |
|
'group_id' => 1, |
|
'data_key' => 'test_var', |
|
'data_value' => 'test', |
|
]); |
|
$this->hasInDatabase($this->config->dbTableGroupVariables, [ |
|
'group_id' => 1, |
|
'data_key' => 'test_var2', |
|
'data_value' => 'test2', |
|
]); |
|
|
|
$this->assertCount(2, $this->library->listGroupVarKeys(1)); |
|
$this->assertEquals([['key' => 'test_var'], ['key' => 'test_var2']], $this->library->listGroupVarKeys(1)); |
|
|
|
$this->assertFalse($this->library->listGroupVarKeys(99)); |
|
} |
|
}
|
|
|