Browse Source

update Libraries/Aauth, ErrorsTest, InfosTest & UserTest

v3-dev
REJack 6 years ago
parent
commit
2352caf190
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 2
      application/Libraries/Aauth.php
  2. 4
      tests/Aauth/Libraries/Aauth/ErrorsTest.php
  3. 4
      tests/Aauth/Libraries/Aauth/InfosTest.php
  4. 37
      tests/Aauth/Libraries/Aauth/UserTest.php

2
application/Libraries/Aauth.php

@ -139,7 +139,7 @@ class Aauth
if (! $userId = $userModel->insert($data)) if (! $userId = $userModel->insert($data))
{ {
$this->error($userModel->errors()); $this->error(array_values($userModel->errors()));
return false; return false;
} }

4
tests/Aauth/Libraries/Aauth/ErrorsTest.php

@ -111,6 +111,10 @@ class ErrorsTest extends \CIUnitTestCase
$this->assertNull($session->getFlashdata('errors')); $this->assertNull($session->getFlashdata('errors'));
$this->library->error('test message 1 Flash', true); $this->library->error('test message 1 Flash', true);
$session->start(); $session->start();
$this->library->keepErrors();
$session->start();
$this->assertEquals(['test message 1 Flash'], $session->getFlashdata('errors'));
$session->start();
$this->library = new Aauth(null, $session); $this->library = new Aauth(null, $session);
$this->library->error('test message 1 NonFlash'); $this->library->error('test message 1 NonFlash');
$this->library->keepErrors(true); $this->library->keepErrors(true);

4
tests/Aauth/Libraries/Aauth/InfosTest.php

@ -111,6 +111,10 @@ class InfosTest extends \CIUnitTestCase
$this->assertNull($session->getFlashdata('infos')); $this->assertNull($session->getFlashdata('infos'));
$this->library->info('test message 1 Flash', true); $this->library->info('test message 1 Flash', true);
$session->start(); $session->start();
$this->library->keepInfos();
$session->start();
$this->assertEquals(['test message 1 Flash'], $session->getFlashdata('infos'));
$session->start();
$this->library = new Aauth(null, $session); $this->library = new Aauth(null, $session);
$this->library->info('test message 1 NonFlash'); $this->library->info('test message 1 NonFlash');
$this->library->keepInfos(true); $this->library->keepInfos(true);

37
tests/Aauth/Libraries/Aauth/UserTest.php

@ -62,9 +62,43 @@ class UserTest extends CIDatabaseTestCase
//-------------------------------------------------------------------- //--------------------------------------------------------------------
public function testUpdateUser() public function testCreateUser()
{ {
$this->library->createUser('usertest@example.com', 'password987654', 'usertest');
$this->seeInDatabase($this->config->dbTableUsers, [
'email' => 'usertest@example.com',
'username' => 'usertest',
]);
$this->assertEquals(lang('Aauth.infoCreateSuccess'), $this->library->getInfosArray()[0]);
$this->library = new Aauth(null, true); $this->library = new Aauth(null, true);
$this->assertFalse($this->library->createUser('admin@example.com', 'password123456', null));
print_r($this->library->getErrorsArray());
$this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]);
$this->library = new Aauth(null, true);
$this->assertFalse($this->library->createUser('adminexample.com', 'password123456', null));
$this->assertEquals(lang('Aauth.invalidEmail'), $this->library->getErrorsArray()[0]);
$this->library = new Aauth(null, true);
$this->assertFalse($this->library->createUser('test@example.com', 'pass', null));
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]);
$this->library = new Aauth(null, true);
$this->assertFalse($this->library->createUser('test@example.com', 'password12345678901011121314151617', null));
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]);
$this->library = new Aauth(null, true);
$this->assertFalse($this->library->createUser('test@example.com', 'password123456', 'admin'));
$this->assertEquals(lang('Aauth.existsAlreadyUsername'), $this->library->getErrorsArray()[0]);
$this->library = new Aauth(null, true);
$this->assertFalse($this->library->createUser('test@example.com', 'password123456', 'user+'));
$this->assertEquals(lang('Aauth.invalidUsername'), $this->library->getErrorsArray()[0]);
}
public function testUpdateUser()
{
$this->seeInDatabase($this->config->dbTableUsers, [ $this->seeInDatabase($this->config->dbTableUsers, [
'id' => 2, 'id' => 2,
'email' => 'user@example.com', 'email' => 'user@example.com',
@ -222,6 +256,7 @@ class UserTest extends CIDatabaseTestCase
'id' => 1, 'id' => 1,
'banned' => 0, 'banned' => 0,
]); ]);
$this->assertFalse($this->library->isBanned());
} }
public function testIsBanned() public function testIsBanned()

Loading…
Cancel
Save