|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
<?php namespace Tests\Aauth\Database; |
|
|
|
|
|
|
|
|
|
use Config\Aauth as AauthConfig; |
|
|
|
|
use CodeIgniter\Test\CIDatabaseTestCase; |
|
|
|
|
use App\Models\Aauth\PermToUserModel; |
|
|
|
|
|
|
|
|
@ -16,29 +17,49 @@ class PermToUserModelTest extends CIDatabaseTestCase
|
|
|
|
|
parent::setUp(); |
|
|
|
|
|
|
|
|
|
$this->model = new PermToUserModel($this->db); |
|
|
|
|
$this->config = new AauthConfig(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------- |
|
|
|
|
public function testInsert() |
|
|
|
|
{ |
|
|
|
|
$permToUser = $this->model->insert(99, 99); |
|
|
|
|
$this->assertTrue($permToUser); |
|
|
|
|
$this->seeInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testExistsFalse() |
|
|
|
|
{ |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$permToUser = $this->model->exists(99, 99); |
|
|
|
|
$this->assertFalse($permToUser); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testExistsTrue() |
|
|
|
|
{ |
|
|
|
|
$this->model->insert(99, 99); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$permToUser = $this->model->exists(99, 99); |
|
|
|
|
$this->assertTrue($permToUser); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testFindAllByUserId() |
|
|
|
|
public function testFindAllByGroupId() |
|
|
|
|
{ |
|
|
|
|
$permsToUser = $this->model->findAllByUserId(99); |
|
|
|
|
$permsToUser = $this->model->findAllByGroupId(99); |
|
|
|
|
$this->assertCount(0, $permsToUser); |
|
|
|
|
$this->model->insert(99, 99); |
|
|
|
|
$permsToUser = $this->model->findAllByUserId(99); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$permsToUser = $this->model->findAllByGroupId(99); |
|
|
|
|
$this->assertCount(1, $permsToUser); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -46,47 +67,69 @@ class PermToUserModelTest extends CIDatabaseTestCase
|
|
|
|
|
{ |
|
|
|
|
$permToUsers = $this->model->findAllByPermId(99); |
|
|
|
|
$this->assertCount(0, $permToUsers); |
|
|
|
|
$this->model->insert(99, 99); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$permToUsers = $this->model->findAllByPermId(99); |
|
|
|
|
$this->assertCount(1, $permToUsers); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testDelete() |
|
|
|
|
{ |
|
|
|
|
$this->model->insert(99, 99); |
|
|
|
|
$permToUser = $this->model->exists(99, 99); |
|
|
|
|
$this->assertTrue($permToUser); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$criteria = [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]; |
|
|
|
|
$this->seeNumRecords(1, $this->config->dbTablePermToUser, $criteria); |
|
|
|
|
$this->model->delete(99, 99); |
|
|
|
|
$permToUser = $this->model->exists(99, 99); |
|
|
|
|
$this->assertFalse($permToUser); |
|
|
|
|
$this->seeNumRecords(0, $this->config->dbTablePermToUser, $criteria); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testDeleteAllByPermId() |
|
|
|
|
{ |
|
|
|
|
$this->model->insert(99, 99); |
|
|
|
|
$permToUsers = $this->model->findAllByPermId(99); |
|
|
|
|
$this->assertCount(1, $permToUsers); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$criteria = [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
]; |
|
|
|
|
$this->seeNumRecords(1, $this->config->dbTablePermToUser, $criteria); |
|
|
|
|
$this->model->deleteAllByPermId(99); |
|
|
|
|
$permToUsers = $this->model->findAllByPermId(99); |
|
|
|
|
$this->assertCount(0, $permToUsers); |
|
|
|
|
$this->seeNumRecords(0, $this->config->dbTablePermToUser, $criteria); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testDeleteAllByUserId() |
|
|
|
|
public function testDeleteAllByGroupId() |
|
|
|
|
{ |
|
|
|
|
$this->model->insert(99, 99); |
|
|
|
|
$permsToUser = $this->model->findAllByUserId(99); |
|
|
|
|
$this->assertCount(1, $permsToUser); |
|
|
|
|
$this->model->deleteAllByUserId(99); |
|
|
|
|
$permsToUser = $this->model->findAllByUserId(99); |
|
|
|
|
$this->assertCount(0, $permsToUser); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$criteria = [ |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]; |
|
|
|
|
$this->seeNumRecords(1, $this->config->dbTablePermToUser, $criteria); |
|
|
|
|
$this->model->deleteAllByGroupId(99); |
|
|
|
|
$this->seeNumRecords(0, $this->config->dbTablePermToUser, $criteria); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testConfigDBPerm() |
|
|
|
|
{ |
|
|
|
|
$this->model = new PermToUserModel(); |
|
|
|
|
$this->model->insert(99, 99); |
|
|
|
|
$this->model->insert(98, 99); |
|
|
|
|
$permsToUser = $this->model->findAllByUserId(99); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 99, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$this->hasInDatabase($this->config->dbTablePermToUser, [ |
|
|
|
|
'perm_id' => 98, |
|
|
|
|
'user_id' => 99, |
|
|
|
|
]); |
|
|
|
|
$permsToUser = $this->model->findAllByGroupId(99); |
|
|
|
|
$this->assertCount(2, $permsToUser); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|