From edb5a57d4967b4e03cfcbf3fd794bb3ead95fb32 Mon Sep 17 00:00:00 2001 From: REJack Date: Tue, 4 Dec 2018 11:15:40 +0100 Subject: [PATCH] updated UserModel and UserModelTest & added GroupModelTest and PermModelTest --- application/Models/Aauth/UserModel.php | 5 ++-- tests/Aauth/Database/GroupModelTest.php | 28 ++++++++++++++++++++++ tests/Aauth/Database/PermModelTest.php | 28 ++++++++++++++++++++++ tests/Aauth/Database/UserModelTest.php | 31 ++++++++++++++++++------- 4 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 tests/Aauth/Database/GroupModelTest.php create mode 100644 tests/Aauth/Database/PermModelTest.php diff --git a/application/Models/Aauth/UserModel.php b/application/Models/Aauth/UserModel.php index 24a3767..ecc980e 100644 --- a/application/Models/Aauth/UserModel.php +++ b/application/Models/Aauth/UserModel.php @@ -85,10 +85,11 @@ class UserModel extends Model /** * Constructor */ - public function __construct() + public function __construct($db = NULL, $validation = NULL, $config = NULL) { parent::__construct(); - $this->config = new AauthConfig(); + + $this->config = (object) array_merge((array) new AauthConfig(), (array) $config); $this->table = $this->config->dbTableUsers; $this->DBGroup = $this->config->dbProfile; diff --git a/tests/Aauth/Database/GroupModelTest.php b/tests/Aauth/Database/GroupModelTest.php new file mode 100644 index 0000000..f0c3772 --- /dev/null +++ b/tests/Aauth/Database/GroupModelTest.php @@ -0,0 +1,28 @@ +model = new GroupModel($this->db); + } + + //-------------------------------------------------------------------- + + public function testDummy() + { + $groups = $this->model->findAll(); + $this->assertCount(3, $groups); + } +} diff --git a/tests/Aauth/Database/PermModelTest.php b/tests/Aauth/Database/PermModelTest.php new file mode 100644 index 0000000..811b290 --- /dev/null +++ b/tests/Aauth/Database/PermModelTest.php @@ -0,0 +1,28 @@ +model = new PermModel($this->db); + } + + //-------------------------------------------------------------------- + + public function testDummy() + { + $perms = $this->model->findAll(); + $this->assertCount(0, $perms); + } +} diff --git a/tests/Aauth/Database/UserModelTest.php b/tests/Aauth/Database/UserModelTest.php index bb0f082..fb5388b 100644 --- a/tests/Aauth/Database/UserModelTest.php +++ b/tests/Aauth/Database/UserModelTest.php @@ -1,13 +1,10 @@ model->updateLastLogin(1); - $user = $this->model->find(1); + $user = $this->model->asArray()->find(1); $this->assertTrue((strtotime("-5 seconds") < strtotime($user['last_login']) && strtotime("+5 seconds") > strtotime($user['last_login'])) && strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity'])); } public function testUpdateLastActivity() { $this->model->updateLastActivity(1); - $user = $this->model->find(1); + $user = $this->model->asArray()->find(1); $this->assertTrue(strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity'])); } @@ -85,11 +82,29 @@ class UserModelTest extends CIDatabaseTestCase $this->assertFalse($this->model->existsByUsername("")); } - public function testHashPassword() + public function testHashPasswordFilled() { - $userOld = $this->model->find(1); + $userOld = $this->model->asArray()->find(1); $this->model->update(1, ['id' => 1, 'password' => 'password123456']); - $userNew = $this->model->find(1); + $userNew = $this->model->asArray()->find(1); $this->assertTrue($userOld['password'] != $userNew['password'] && $userNew['password'] != 'password123456'); } + + public function testHashPasswordNotSet() + { + $userOld = $this->model->asArray()->find(1); + $this->model->update(1, ['id' => 1, 'username' => 'admin']); + $userNew = $this->model->asArray()->find(1); + $this->assertEquals($userOld['password'], $userNew['password']); + } + + public function testLoginUseUsernameDummy() + { + $config = new \Config\Aauth(); + $config->loginUseUsername = TRUE; + + $this->model = new UserModel($this->db, null, $config); + $newUser = $this->model->insert(['email' => 'test@test.local', 'password' => 'password123456']); + $this->assertFalse($newUser); + } }