Browse Source

updated Libraries/Aauth and Libraries/AauthTest & Libraries/Aauth/ErrorsTest

v3-dev
REJack 6 years ago
parent
commit
2afed200c3
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 2
      application/Libraries/Aauth.php
  2. 73
      tests/Aauth/Libraries/Aauth/ErrorsTest.php
  3. 21
      tests/Aauth/Libraries/AauthTest.php

2
application/Libraries/Aauth.php

@ -94,7 +94,7 @@ class Aauth
*
* Prepares config & session variable.
*/
public function __construct($config = NULL, $session = NULL)
public function __construct($config = null, $session = null)
{
if (is_null($config))
{

73
tests/Aauth/Libraries/Aauth/ErrorsTest.php

@ -0,0 +1,73 @@
<?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 App\Libraries\Aauth;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class ErrorsTest 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();
return $session;
}
//--------------------------------------------------------------------
public function testErrors()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->assertCount(0, $this->library->getErrorsArray());
$this->library->error('test message 1');
$this->assertCount(1, $this->library->getErrorsArray());
}
public function testErrorsFlash()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->assertCount(0, $this->library->errors);
$this->library->error('test message 1', true);
$this->assertCount(1, $this->session->errors);
}
}

21
tests/Aauth/Libraries/AauthTest.php

@ -48,29 +48,8 @@ class AauthTest extends \CIUnitTestCase
$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);
$this->assertFalse($this->library->isLoggedIn());
}
public function testTest()
{
$session = $this->getInstance();
$session->start();
$session->set('foo', 'bar');
$this->assertEquals('bar', $_SESSION['foo']);
}
}

Loading…
Cancel
Save