diff --git a/application/Libraries/Aauth.php b/application/Libraries/Aauth.php index 63dc31c..66b2e6d 100644 --- a/application/Libraries/Aauth.php +++ b/application/Libraries/Aauth.php @@ -139,7 +139,7 @@ class Aauth if (! $userId = $userModel->insert($data)) { - $this->error($userModel->errors()); + $this->error(array_values($userModel->errors())); return false; } diff --git a/tests/Aauth/Libraries/Aauth/ErrorsTest.php b/tests/Aauth/Libraries/Aauth/ErrorsTest.php index 26a9aed..a7a58fa 100644 --- a/tests/Aauth/Libraries/Aauth/ErrorsTest.php +++ b/tests/Aauth/Libraries/Aauth/ErrorsTest.php @@ -111,6 +111,10 @@ class ErrorsTest extends \CIUnitTestCase $this->assertNull($session->getFlashdata('errors')); $this->library->error('test message 1 Flash', true); $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->error('test message 1 NonFlash'); $this->library->keepErrors(true); diff --git a/tests/Aauth/Libraries/Aauth/InfosTest.php b/tests/Aauth/Libraries/Aauth/InfosTest.php index 2994b4b..e03f571 100644 --- a/tests/Aauth/Libraries/Aauth/InfosTest.php +++ b/tests/Aauth/Libraries/Aauth/InfosTest.php @@ -111,6 +111,10 @@ class InfosTest extends \CIUnitTestCase $this->assertNull($session->getFlashdata('infos')); $this->library->info('test message 1 Flash', true); $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->info('test message 1 NonFlash'); $this->library->keepInfos(true); diff --git a/tests/Aauth/Libraries/Aauth/UserTest.php b/tests/Aauth/Libraries/Aauth/UserTest.php index eca9253..5a019e1 100644 --- a/tests/Aauth/Libraries/Aauth/UserTest.php +++ b/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->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, [ 'id' => 2, 'email' => 'user@example.com', @@ -222,6 +256,7 @@ class UserTest extends CIDatabaseTestCase 'id' => 1, 'banned' => 0, ]); + $this->assertFalse($this->library->isBanned()); } public function testIsBanned()