Browse Source
- updated GroupToGroupModel, GroupToUserModel, LoginAttemptModel, LoginTokenModel, PermToGroupModel & PermToUserModel - updated .env & phpunit.xml - updated Libraries/Aauth - added GroupToGroupModelTest,GroupToUserModelTest, LoginAttemptModelTest, LoginTokenModelTest, PermToGroupModelTest, PermToUserModelTest & AauthTestv3-dev
16 changed files with 595 additions and 51 deletions
@ -0,0 +1,92 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\GroupToGroupModel; |
||||
|
||||
class GroupToGroupModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new GroupToGroupModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testExistsFalse() |
||||
{ |
||||
$groupToGroup = $this->model->exists(99, 99); |
||||
$this->assertFalse($groupToGroup); |
||||
} |
||||
|
||||
public function testExistsTrue() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupToGroup = $this->model->exists(99, 99); |
||||
$this->assertTrue($groupToGroup); |
||||
} |
||||
|
||||
public function testFindAllBySubgroupId() |
||||
{ |
||||
$groupsToGroup = $this->model->findAllBySubgroupId(99); |
||||
$this->assertCount(0, $groupsToGroup); |
||||
$this->model->insert(99, 99); |
||||
$groupsToGroup = $this->model->findAllBySubgroupId(99); |
||||
$this->assertCount(1, $groupsToGroup); |
||||
} |
||||
|
||||
public function testFindAllByGroupId() |
||||
{ |
||||
$groupToGroups = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(0, $groupToGroups); |
||||
$this->model->insert(99, 99); |
||||
$groupToGroups = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(1, $groupToGroups); |
||||
} |
||||
|
||||
public function testDelete() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupToGroup = $this->model->exists(99, 99); |
||||
$this->assertTrue($groupToGroup); |
||||
$this->model->delete(99, 99); |
||||
$groupToGroup = $this->model->exists(99, 99); |
||||
$this->assertFalse($groupToGroup); |
||||
} |
||||
|
||||
public function testDeleteAllByGroupId() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupToGroups = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(1, $groupToGroups); |
||||
$this->model->deleteAllByGroupId(99); |
||||
$groupToGroups = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(0, $groupToGroups); |
||||
} |
||||
|
||||
public function testDeleteAllBySubgroupId() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupsToGroup = $this->model->findAllBySubgroupId(99); |
||||
$this->assertCount(1, $groupsToGroup); |
||||
$this->model->deleteAllBySubgroupId(99); |
||||
$groupsToGroup = $this->model->findAllBySubgroupId(99); |
||||
$this->assertCount(0, $groupsToGroup); |
||||
} |
||||
|
||||
public function testConfigDBGroup() |
||||
{ |
||||
$this->model = new GroupToGroupModel(); |
||||
$this->model->insert(99, 99); |
||||
$this->model->insert(98, 99); |
||||
$groupsToGroup = $this->model->findAllBySubgroupId(99); |
||||
$this->assertCount(2, $groupsToGroup); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\GroupToUserModel; |
||||
|
||||
class GroupToUserModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new GroupToUserModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testExistsFalse() |
||||
{ |
||||
$groupToUser = $this->model->exists(99, 99); |
||||
$this->assertFalse($groupToUser); |
||||
} |
||||
|
||||
public function testExistsTrue() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupToUser = $this->model->exists(99, 99); |
||||
$this->assertTrue($groupToUser); |
||||
} |
||||
|
||||
public function testFindAllByUserId() |
||||
{ |
||||
$groupToUsers = $this->model->findAllByUserId(99); |
||||
$this->assertCount(0, $groupToUsers); |
||||
$this->model->insert(99, 99); |
||||
$groupToUsers = $this->model->findAllByUserId(99); |
||||
$this->assertCount(1, $groupToUsers); |
||||
} |
||||
|
||||
public function testFindAllByGroupId() |
||||
{ |
||||
$groupToUsers = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(0, $groupToUsers); |
||||
$this->model->insert(99, 99); |
||||
$groupToUsers = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(1, $groupToUsers); |
||||
} |
||||
|
||||
public function testDelete() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupToUser = $this->model->exists(99, 99); |
||||
$this->assertTrue($groupToUser); |
||||
$this->model->delete(99, 99); |
||||
$groupToUser = $this->model->exists(99, 99); |
||||
$this->assertFalse($groupToUser); |
||||
} |
||||
|
||||
public function testDeleteAllByGroupId() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupToUsers = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(1, $groupToUsers); |
||||
$this->model->deleteAllByGroupId(99); |
||||
$groupToUsers = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(0, $groupToUsers); |
||||
} |
||||
|
||||
public function testDeleteAllByUserId() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$groupToUsers = $this->model->findAllByUserId(99); |
||||
$this->assertCount(1, $groupToUsers); |
||||
$this->model->deleteAllByUserId(99); |
||||
$groupToUsers = $this->model->findAllByUserId(99); |
||||
$this->assertCount(0, $groupToUsers); |
||||
} |
||||
|
||||
public function testConfigDBGroup() |
||||
{ |
||||
$this->model = new GroupToUserModel(); |
||||
$this->model->insert(99, 99); |
||||
$this->model->insert(98, 99); |
||||
$groupToUsers = $this->model->findAllByUserId(99); |
||||
$this->assertCount(2, $groupToUsers); |
||||
} |
||||
} |
@ -0,0 +1,76 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\LoginAttemptModel; |
||||
|
||||
class LoginAttemptModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new LoginAttemptModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testFind() |
||||
{ |
||||
$loginAttempt = $this->model->find(); |
||||
$this->assertEquals(0, $loginAttempt); |
||||
} |
||||
|
||||
public function testSaveInsert() |
||||
{ |
||||
$this->model->save(); |
||||
$loginAttempt = $this->model->find(); |
||||
$this->assertEquals(1, $loginAttempt); |
||||
} |
||||
|
||||
public function testSaveUpdate() |
||||
{ |
||||
$this->model->save(); |
||||
$this->assertTrue($this->model->save()); |
||||
$loginAttempt = $this->model->find(); |
||||
$this->assertEquals(2, $loginAttempt); |
||||
} |
||||
|
||||
public function testSaveUpdateFalse() |
||||
{ |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->model->save(); |
||||
$this->assertFalse($this->model->save()); |
||||
} |
||||
|
||||
public function testDelete() |
||||
{ |
||||
$this->model->save(); |
||||
$loginAttempt = $this->model->find(); |
||||
$this->assertEquals(1, $loginAttempt); |
||||
$this->model->delete(); |
||||
$loginAttempt = $this->model->find(); |
||||
$this->assertEquals(0, $loginAttempt); |
||||
} |
||||
|
||||
public function testConfigDBGroup() |
||||
{ |
||||
$this->model = new LoginAttemptModel(); |
||||
$this->model->save(); |
||||
$groupsToGroup = $this->model->find(); |
||||
$this->assertEquals(1, $groupsToGroup); |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\LoginTokenModel; |
||||
|
||||
class LoginTokenModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new LoginTokenModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testInsert() |
||||
{ |
||||
$this->model->insert(['user_id' => 99, 'random_hash' => 'random_hash9999']); |
||||
$loginTokens = $this->model->findAllByUserId(99); |
||||
$this->assertCount(1, $loginTokens); |
||||
} |
||||
|
||||
public function testUpdate() |
||||
{ |
||||
$this->model->insert(['user_id' => 99, 'random_hash' => 'random_hash9999']); |
||||
$oldLoginTokens = $this->model->findAllByUserId(99); |
||||
$oldLoginToken = $oldLoginTokens[0]; |
||||
sleep(5); |
||||
$this->model->update($oldLoginToken['id']); |
||||
$loginTokens = $this->model->findAllByUserId(99); |
||||
$loginToken = $loginTokens[0]; |
||||
$this->assertNotEquals($oldLoginToken['expires_at'], $loginToken['expires_at']); |
||||
} |
||||
|
||||
public function testDeleteExpired() |
||||
{ |
||||
$this->model->insert(['user_id' => 99, 'random_hash' => 'random_hash9999']); |
||||
sleep(5); |
||||
$this->model->deleteExpired(99); |
||||
$loginTokens = $this->model->findAllByUserId(99); |
||||
$this->assertCount(0, $loginTokens); |
||||
} |
||||
|
||||
public function testConfigDBGroup() |
||||
{ |
||||
$this->model = new LoginTokenModel(); |
||||
$this->model->insert(['user_id' => 99, 'random_hash' => 'random_hash9999']); |
||||
$loginTokens = $this->model->findAllByUserId(99); |
||||
$this->assertCount(1, $loginTokens); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\PermToGroupModel; |
||||
|
||||
class PermToGroupModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new PermToGroupModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testExistsFalse() |
||||
{ |
||||
$permToGroup = $this->model->exists(99, 99); |
||||
$this->assertFalse($permToGroup); |
||||
} |
||||
|
||||
public function testExistsTrue() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$permToGroup = $this->model->exists(99, 99); |
||||
$this->assertTrue($permToGroup); |
||||
} |
||||
|
||||
public function testFindAllByGroupId() |
||||
{ |
||||
$permsToGroup = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(0, $permsToGroup); |
||||
$this->model->insert(99, 99); |
||||
$permsToGroup = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(1, $permsToGroup); |
||||
} |
||||
|
||||
public function testFindAllByPermId() |
||||
{ |
||||
$permToGroups = $this->model->findAllByPermId(99); |
||||
$this->assertCount(0, $permToGroups); |
||||
$this->model->insert(99, 99); |
||||
$permToGroups = $this->model->findAllByPermId(99); |
||||
$this->assertCount(1, $permToGroups); |
||||
} |
||||
|
||||
public function testDelete() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$permToGroup = $this->model->exists(99, 99); |
||||
$this->assertTrue($permToGroup); |
||||
$this->model->delete(99, 99); |
||||
$permToGroup = $this->model->exists(99, 99); |
||||
$this->assertFalse($permToGroup); |
||||
} |
||||
|
||||
public function testDeleteAllByPermId() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$permToGroups = $this->model->findAllByPermId(99); |
||||
$this->assertCount(1, $permToGroups); |
||||
$this->model->deleteAllByPermId(99); |
||||
$permToGroups = $this->model->findAllByPermId(99); |
||||
$this->assertCount(0, $permToGroups); |
||||
} |
||||
|
||||
public function testDeleteAllByGroupId() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$permsToGroup = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(1, $permsToGroup); |
||||
$this->model->deleteAllByGroupId(99); |
||||
$permsToGroup = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(0, $permsToGroup); |
||||
} |
||||
|
||||
public function testConfigDBPerm() |
||||
{ |
||||
$this->model = new PermToGroupModel(); |
||||
$this->model->insert(99, 99); |
||||
$this->model->insert(98, 99); |
||||
$permsToGroup = $this->model->findAllByGroupId(99); |
||||
$this->assertCount(2, $permsToGroup); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
<?php namespace Tests\Aauth\Database; |
||||
|
||||
use CodeIgniter\Test\CIDatabaseTestCase; |
||||
use App\Models\Aauth\PermToUserModel; |
||||
|
||||
class PermToUserModelTest extends CIDatabaseTestCase |
||||
{ |
||||
protected $refresh = true; |
||||
|
||||
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$this->model = new PermToUserModel($this->db); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testExistsFalse() |
||||
{ |
||||
$permToUser = $this->model->exists(99, 99); |
||||
$this->assertFalse($permToUser); |
||||
} |
||||
|
||||
public function testExistsTrue() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$permToUser = $this->model->exists(99, 99); |
||||
$this->assertTrue($permToUser); |
||||
} |
||||
|
||||
public function testFindAllByUserId() |
||||
{ |
||||
$permsToUser = $this->model->findAllByUserId(99); |
||||
$this->assertCount(0, $permsToUser); |
||||
$this->model->insert(99, 99); |
||||
$permsToUser = $this->model->findAllByUserId(99); |
||||
$this->assertCount(1, $permsToUser); |
||||
} |
||||
|
||||
public function testFindAllByPermId() |
||||
{ |
||||
$permToUsers = $this->model->findAllByPermId(99); |
||||
$this->assertCount(0, $permToUsers); |
||||
$this->model->insert(99, 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->model->delete(99, 99); |
||||
$permToUser = $this->model->exists(99, 99); |
||||
$this->assertFalse($permToUser); |
||||
} |
||||
|
||||
public function testDeleteAllByPermId() |
||||
{ |
||||
$this->model->insert(99, 99); |
||||
$permToUsers = $this->model->findAllByPermId(99); |
||||
$this->assertCount(1, $permToUsers); |
||||
$this->model->deleteAllByPermId(99); |
||||
$permToUsers = $this->model->findAllByPermId(99); |
||||
$this->assertCount(0, $permToUsers); |
||||
} |
||||
|
||||
public function testDeleteAllByUserId() |
||||
{ |
||||
$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); |
||||
} |
||||
|
||||
public function testConfigDBPerm() |
||||
{ |
||||
$this->model = new PermToUserModel(); |
||||
$this->model->insert(99, 99); |
||||
$this->model->insert(98, 99); |
||||
$permsToUser = $this->model->findAllByUserId(99); |
||||
$this->assertCount(2, $permsToUser); |
||||
} |
||||
} |
@ -0,0 +1,77 @@
|
||||
<?php namespace Tests\Aauth\Libraries; |
||||
|
||||
use Config\Logger; |
||||
use Config\Services; |
||||
use Tests\Support\Log\TestLogger; |
||||
use Tests\Support\Session\MockSession; |
||||
use CodeIgniter\Session\Handlers\FileHandler; |
||||
use App\Libraries\Aauth; |
||||
|
||||
/** |
||||
* @runTestsInSeparateProcesses |
||||
* @preserveGlobalState disabled |
||||
*/ |
||||
class AauthTest extends \CIUnitTestCase |
||||
{ |
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
$_COOKIE = []; |
||||
$_SESSION = []; |
||||
} |
||||
|
||||
public function tearDown() |
||||
{ |
||||
|
||||
} |
||||
|
||||
protected function getInstance($options=[]) |
||||
{ |
||||
$defaults = [ |
||||
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', |
||||
'sessionCookieName' => 'ci_session', |
||||
'sessionExpiration' => 7200, |
||||
'sessionSavePath' => 'null', |
||||
'sessionMatchIP' => false, |
||||
'sessionTimeToUpdate' => 300, |
||||
'sessionRegenerateDestroy' => false, |
||||
'cookieDomain' => '', |
||||
'cookiePrefix' => '', |
||||
'cookiePath' => '/', |
||||
'cookieSecure' => false, |
||||
]; |
||||
|
||||
$config = (object)$defaults; |
||||
|
||||
$session = new MockSession(new FileHandler($config, Services::request()->getIPAddress()), $config); |
||||
$session->setLogger(new TestLogger(new Logger())); |
||||
$session->start(); |
||||
|
||||
var_dump($_SESSION); |
||||
|
||||
return $session; |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testIsLoggedIn() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
|
||||
// $this->library = new Aauth(NULL, $session); |
||||
|
||||
// var_dump(session()); |
||||
// $this->assertFalse($this->library->isLoggedIn()); |
||||
} |
||||
|
||||
public function testTest() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$session->start(); |
||||
|
||||
$session->set('foo', 'bar'); |
||||
|
||||
$this->assertEquals('bar', $_SESSION['foo']); |
||||
} |
||||
} |
Loading…
Reference in new issue