1 changed files with 71 additions and 0 deletions
@ -0,0 +1,71 @@ |
|||||||
|
<?php namespace Tests\Aauth\Libraries\Aauth; |
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
|
/** |
||||||
|
* @runTestsInSeparateProcesses |
||||||
|
* @preserveGlobalState disabled |
||||||
|
*/ |
||||||
|
class LoginTest extends CIDatabaseTestCase |
||||||
|
{ |
||||||
|
protected $refresh = true; |
||||||
|
|
||||||
|
protected $basePath = TESTPATH . '../application' . 'Database/Migrations'; |
||||||
|
|
||||||
|
protected $namespace = 'App'; |
||||||
|
|
||||||
|
public function setUp() |
||||||
|
{ |
||||||
|
parent::setUp(); |
||||||
|
|
||||||
|
$this->library = new Aauth(null, true); |
||||||
|
$_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(); |
||||||
|
|
||||||
|
return $session; |
||||||
|
} |
||||||
|
|
||||||
|
//-------------------------------------------------------------------- |
||||||
|
|
||||||
|
public function testIsLoggedIn() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(NULL, $session); |
||||||
|
$this->assertTrue($this->library->login('admin@example.com', 'password123456')); |
||||||
|
$this->assertTrue($this->library->isLoggedIn()); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue