Browse Source

updated phpunit.xml and Libraries/Aauth & added Aauth/UserTest.php

v3-dev
REJack 6 years ago
parent
commit
32357f11e2
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 30
      application/Libraries/Aauth.php
  2. 6
      phpunit.xml
  3. 103
      tests/Aauth/Libraries/Aauth/UserTest.php

30
application/Libraries/Aauth.php

@ -250,6 +250,8 @@ class Aauth
{ {
$userModel = new UserModel(); $userModel = new UserModel();
$user = $userModel->limit($limit, $offset); $user = $userModel->limit($limit, $offset);
$userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login');
// eanbool $group_par = null, // eanbool $group_par = null,
if (is_null($includeBanneds)) if (is_null($includeBanneds))
@ -343,6 +345,8 @@ class Aauth
$userModel = new UserModel(); $userModel = new UserModel();
$userVariableModel = new UserVariableModel(); $userVariableModel = new UserVariableModel();
$userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login');
if (! $userId) if (! $userId)
{ {
$userId = $this->session->id; $userId = $this->session->id;
@ -396,6 +400,32 @@ class Aauth
return false; return false;
} }
/**
* Is banned
*
* @param integer $userId User id
*
* @return boolean
*/
public function isBanned(int $userId)
{
$userModel = new UserModel();
if (! $userId)
{
$userId = $this->session->id;
}
if (! $userModel->existsById($userId))
{
$this->error(lang('Aauth.notFoundUser'));
return false;
}
return $userModel->isBanned($userId);
}
/** /**
* Ban User * Ban User
* *

6
phpunit.xml

@ -21,9 +21,11 @@
<filter> <filter>
<whitelist processUncoveredFilesFromWhitelist="true"> <whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./application/Libraries</directory> <directory suffix=".php">./application/Models/Aauth</directory>
<directory suffix=".php">./application/Models</directory> <directory suffix=".php">./application/Language/*/Aauth</directory>
<file>./application/Config/Aauth.php</file> <file>./application/Config/Aauth.php</file>
<file>./application/Config/Aauth.php</file>
<file>./application/Libraries/Aauth.php</file>
</whitelist> </whitelist>
</filter> </filter>

103
tests/Aauth/Libraries/Aauth/UserTest.php

@ -0,0 +1,103 @@
<?php namespace Tests\Aauth\Libraries\Aauth;
use CodeIgniter\Test\CIDatabaseTestCase;
use App\Libraries\Aauth;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class UserTest extends CIDatabaseTestCase
{
protected $refresh = true;
protected $basePath = TESTPATH . '../application' . 'Database/Migrations';
protected $namespace = 'App';
public function setUp()
{
parent::setUp();
}
public function tearDown()
{
}
//--------------------------------------------------------------------
public function testUpdateUser()
{
$this->library = new Aauth(null, true);
$userPre = $this->library->getUser(2);
$this->library->updateUser(2, '[email protected]', 'password987654', 'user1');
$user = $this->library->getUser(2);
$this->assertNotEquals($userPre['email'], $user['email']);
$this->assertNotEquals($userPre['username'], $user['username']);
$this->library->updateUser(2, null, null, 'user1');
$userAfter = $this->library->getUser(2);
$this->assertEquals($user['username'], $userAfter['username']);
}
public function testDeleteUser()
{
$this->library = new Aauth(null, true);
$users = $this->library->listUsers();
$this->assertCount(2, $users);
$this->library->deleteUser(2);
$users = $this->library->listUsers();
$this->assertCount(1, $users);
$this->assertFalse($this->library->deleteUser(99));
}
public function testListUsers()
{
$this->library = new Aauth(null, true);
$users = $this->library->listUsers();
$this->assertCount(2, $users);
}
public function testGetUser()
{
$this->library = new Aauth(null, true);
$user = $this->library->getUser(1);
$this->assertEquals('1', $user['id']);
$this->assertEquals('admin', $user['username']);
$this->assertEquals('[email protected]', $user['email']);
}
public function testGetUserUserVars()
{
$this->library = new Aauth(null, true);
$user = $this->library->getUser(1, true);
$this->assertInternalType('array', $user['variables']);
}
public function testGetUserId()
{
$this->library = new Aauth(null, true);
$userIdEmail = $this->library->getUserId('[email protected]');
$this->assertEquals('1', $userIdEmail);
// $userIdNone = $this->library->getUserId();
// $this->assertEquals('1', $userIdNone);
}
public function testBanUser()
{
$this->library = new Aauth(null, true);
$this->assertFalse($this->library->isBanned(1));
$this->library->banUser(1);
$this->assertTrue($this->library->isBanned(1));
}
public function testUnbanUser()
{
$this->library = new Aauth(null, true);
$this->library->banUser(1);
$this->assertTrue($this->library->isBanned(1));
$this->library->unbanUser(1);
$this->assertFalse($this->library->isBanned(1));
}
}
Loading…
Cancel
Save