|
|
@ -1,5 +1,6 @@ |
|
|
|
<?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\PermToGroupModel; |
|
|
|
use App\Models\Aauth\PermToGroupModel; |
|
|
|
|
|
|
|
|
|
|
@ -16,19 +17,36 @@ class PermToGroupModelTest extends CIDatabaseTestCase |
|
|
|
parent::setUp(); |
|
|
|
parent::setUp(); |
|
|
|
|
|
|
|
|
|
|
|
$this->model = new PermToGroupModel($this->db); |
|
|
|
$this->model = new PermToGroupModel($this->db); |
|
|
|
|
|
|
|
$this->config = new AauthConfig(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------- |
|
|
|
//-------------------------------------------------------------------- |
|
|
|
|
|
|
|
public function testInsert() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$permToGroup = $this->model->insert(99, 99); |
|
|
|
|
|
|
|
$this->assertTrue($permToGroup); |
|
|
|
|
|
|
|
$this->seeInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
|
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testExistsFalse() |
|
|
|
public function testExistsFalse() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
|
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
$permToGroup = $this->model->exists(99, 99); |
|
|
|
$permToGroup = $this->model->exists(99, 99); |
|
|
|
$this->assertFalse($permToGroup); |
|
|
|
$this->assertFalse($permToGroup); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testExistsTrue() |
|
|
|
public function testExistsTrue() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->model->insert(99, 99); |
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
|
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
$permToGroup = $this->model->exists(99, 99); |
|
|
|
$permToGroup = $this->model->exists(99, 99); |
|
|
|
$this->assertTrue($permToGroup); |
|
|
|
$this->assertTrue($permToGroup); |
|
|
|
} |
|
|
|
} |
|
|
@ -37,7 +55,10 @@ class PermToGroupModelTest extends CIDatabaseTestCase |
|
|
|
{ |
|
|
|
{ |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
$this->assertCount(0, $permsToGroup); |
|
|
|
$this->assertCount(0, $permsToGroup); |
|
|
|
$this->model->insert(99, 99); |
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
|
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
$this->assertCount(1, $permsToGroup); |
|
|
|
$this->assertCount(1, $permsToGroup); |
|
|
|
} |
|
|
|
} |
|
|
@ -46,46 +67,68 @@ class PermToGroupModelTest extends CIDatabaseTestCase |
|
|
|
{ |
|
|
|
{ |
|
|
|
$permToGroups = $this->model->findAllByPermId(99); |
|
|
|
$permToGroups = $this->model->findAllByPermId(99); |
|
|
|
$this->assertCount(0, $permToGroups); |
|
|
|
$this->assertCount(0, $permToGroups); |
|
|
|
$this->model->insert(99, 99); |
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
|
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
$permToGroups = $this->model->findAllByPermId(99); |
|
|
|
$permToGroups = $this->model->findAllByPermId(99); |
|
|
|
$this->assertCount(1, $permToGroups); |
|
|
|
$this->assertCount(1, $permToGroups); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testDelete() |
|
|
|
public function testDelete() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->model->insert(99, 99); |
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
$permToGroup = $this->model->exists(99, 99); |
|
|
|
'perm_id' => 99, |
|
|
|
$this->assertTrue($permToGroup); |
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
$criteria = [ |
|
|
|
|
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->seeNumRecords(1, $this->config->dbTablePermToGroup, $criteria); |
|
|
|
$this->model->delete(99, 99); |
|
|
|
$this->model->delete(99, 99); |
|
|
|
$permToGroup = $this->model->exists(99, 99); |
|
|
|
$this->seeNumRecords(0, $this->config->dbTablePermToGroup, $criteria); |
|
|
|
$this->assertFalse($permToGroup); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testDeleteAllByPermId() |
|
|
|
public function testDeleteAllByPermId() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->model->insert(99, 99); |
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
$permToGroups = $this->model->findAllByPermId(99); |
|
|
|
'perm_id' => 99, |
|
|
|
$this->assertCount(1, $permToGroups); |
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
$criteria = [ |
|
|
|
|
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->seeNumRecords(1, $this->config->dbTablePermToGroup, $criteria); |
|
|
|
$this->model->deleteAllByPermId(99); |
|
|
|
$this->model->deleteAllByPermId(99); |
|
|
|
$permToGroups = $this->model->findAllByPermId(99); |
|
|
|
$this->seeNumRecords(0, $this->config->dbTablePermToGroup, $criteria); |
|
|
|
$this->assertCount(0, $permToGroups); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testDeleteAllByGroupId() |
|
|
|
public function testDeleteAllByGroupId() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->model->insert(99, 99); |
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
'perm_id' => 99, |
|
|
|
$this->assertCount(1, $permsToGroup); |
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
$criteria = [ |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->seeNumRecords(1, $this->config->dbTablePermToGroup, $criteria); |
|
|
|
$this->model->deleteAllByGroupId(99); |
|
|
|
$this->model->deleteAllByGroupId(99); |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
$this->seeNumRecords(0, $this->config->dbTablePermToGroup, $criteria); |
|
|
|
$this->assertCount(0, $permsToGroup); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testConfigDBPerm() |
|
|
|
public function testConfigDBPerm() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->model = new PermToGroupModel(); |
|
|
|
$this->model = new PermToGroupModel(); |
|
|
|
$this->model->insert(99, 99); |
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
$this->model->insert(98, 99); |
|
|
|
'perm_id' => 99, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToGroup, [ |
|
|
|
|
|
|
|
'perm_id' => 98, |
|
|
|
|
|
|
|
'group_id' => 99, |
|
|
|
|
|
|
|
]); |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
$permsToGroup = $this->model->findAllByGroupId(99); |
|
|
|
$this->assertCount(2, $permsToGroup); |
|
|
|
$this->assertCount(2, $permsToGroup); |
|
|
|
} |
|
|
|
} |
|
|
|