PMCORE-2887
This commit is contained in:
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\classes\PmFunctions;
|
||||
|
||||
use ProcessMaker\Model\GroupUser;
|
||||
use ProcessMaker\Model\Groupwf;
|
||||
use ProcessMaker\Model\RbacUsers;
|
||||
use ProcessMaker\Model\User;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PMFNewUserTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Creates the setUp method
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
if (!defined('PPP_NUMERICAL_CHARACTER_REQUIRED')) {
|
||||
define('PPP_NUMERICAL_CHARACTER_REQUIRED', 1);
|
||||
}
|
||||
if (!defined('PPP_UPPERCASE_CHARACTER_REQUIRED')) {
|
||||
define('PPP_UPPERCASE_CHARACTER_REQUIRED', 1);
|
||||
}
|
||||
if (!defined('PPP_SPECIAL_CHARACTER_REQUIRED')) {
|
||||
define('PPP_SPECIAL_CHARACTER_REQUIRED', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_pmfnewuser_function()
|
||||
{
|
||||
global $RBAC;
|
||||
$user = User::where('USR_ID', '=', 1)->get()->first();
|
||||
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$RBAC->initRBAC();
|
||||
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
|
||||
|
||||
$group = factory(Groupwf::class)->create();
|
||||
|
||||
$result = PMFNewUser("test", "Test123*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, $group['GRP_UID']);
|
||||
|
||||
$query = GroupUser::select();
|
||||
$r = $query->get()->values()->toArray();
|
||||
|
||||
$this->assertEquals($r[0]['GRP_UID'], $result['groupUid']);
|
||||
$this->assertEquals($r[0]['USR_UID'], $result['userUid']);
|
||||
|
||||
$query = RbacUsers::select()->where('USR_UID', $result['userUid']);
|
||||
$r = $query->get()->values()->toArray();
|
||||
|
||||
$this->assertNotEmpty($r);
|
||||
$this->assertEquals($result['userUid'], $r[0]['USR_UID']);
|
||||
$this->assertEquals($result['username'], $r[0]['USR_USERNAME']);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the exception user is required in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_exception_user_required()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_USERNAME_REQUIRED**');
|
||||
PMFNewUser("", "test123", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the exception lastname is required in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_exception_lastname_required()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_MSG_ERROR_USR_LASTNAME**');
|
||||
PMFNewUser("test", "test123", "test", "", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the exception firstname is required in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_exception_firstname_required()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_MSG_ERROR_USR_FIRSTNAME**');
|
||||
PMFNewUser("test", "test123", "", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the exception password is required in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_exception_password_required()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_PASSWD_REQUIRED**');
|
||||
PMFNewUser("test", "", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the exception email is required in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_exception_email_required()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_EMAIL_IS_REQUIRED**');
|
||||
PMFNewUser("test", "test123", "test", "test", "", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the email format exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_email_format_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_EMAIL_INVALID**');
|
||||
PMFNewUser("test2", "Test123*", "test", "test", "test@test", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the due date format exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_duedate_format_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_INVALID_DATA**');
|
||||
PMFNewUser("test2", "test123", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", '121212', null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the status exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_status_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_INVALID_DATA**');
|
||||
PMFNewUser("test2", "test123", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, 'ACTI', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the rol exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_rol_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_INVALID_ROLE**');
|
||||
PMFNewUser("test2", "test13", "test", "test", "test@test.com", "PROCESSMAKER_ADM", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the password surprases exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_password_surprases_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_PASSWORD_SURPRASES**');
|
||||
PMFNewUser("test2", "123456789012345678901234567890", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the password numerical character required exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_password_numerical_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_PPP_NUMERICAL_CHARACTER_REQUIRED**');
|
||||
PMFNewUser("test2", "TestA*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the password uppercase character required exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_password_uppercase_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_PPP_UPPERCASE_CHARACTER_REQUIRED**');
|
||||
PMFNewUser("test2", "test1*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the password special character required exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_password_special_character_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_PPP_SPECIAL_CHARACTER_REQUIRED**');
|
||||
PMFNewUser("test2", "Test1", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the password below exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_password_below_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_PASSWORD_BELOW**');
|
||||
PMFNewUser("test2", "test", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the username exists exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_username_exists_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_USERNAME_ALREADY_EXISTS**');
|
||||
PMFNewUser("test", "Test12345*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the email is invalid exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_email_invalid_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_EMAIL_INVALID**');
|
||||
PMFNewUser("test3", "Test12345*", "test", "test", "test@test", "PROCESSMAKER_ADMIN", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the group does not exists exception in the PMFNewUser() function
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_group_doesnot_exists_exception()
|
||||
{
|
||||
$this->expectExceptionMessage('**ID_GROUP_DOESNT_EXIST**');
|
||||
PMFNewUser("test3", "Test12345*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, '1234');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\GroupUser;
|
||||
use ProcessMaker\Model\Groupwf;
|
||||
use ProcessMaker\Model\RbacUsers;
|
||||
use ProcessMaker\Model\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ProcessTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\GroupUser
|
||||
*/
|
||||
class GroupUserTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* It tests the assignUserToGroup() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_assign_user_to_group_method()
|
||||
{
|
||||
$rbacUser = factory(RbacUsers::class)->create();
|
||||
$user = factory(User::class)->create([
|
||||
'USR_UID' => $rbacUser['USR_UID'],
|
||||
'USR_USERNAME' => $rbacUser['USR_USERNAME'],
|
||||
'USR_PASSWORD' => $rbacUser['USR_PASSWORD'],
|
||||
'USR_FIRSTNAME' => $rbacUser['USR_FIRSTNAME'],
|
||||
'USR_LASTNAME' => $rbacUser['USR_LASTNAME'],
|
||||
'USR_EMAIL' => $rbacUser['USR_EMAIL'],
|
||||
]);
|
||||
$group = factory(Groupwf::class)->create();
|
||||
|
||||
GroupUser::assignUserToGroup($rbacUser['USR_UID'], $user['USR_ID'], $group['GRP_UID'], $group['GRP_ID']);
|
||||
|
||||
$query = GroupUser::select()->where('GRP_ID', $group['GRP_ID'])->where('USR_ID', $user['USR_ID']);
|
||||
$res = $query->get()->values()->toArray();
|
||||
$this->assertNotEmpty($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the verifyUserIsInGroup() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_verify_user_is_in_group_method()
|
||||
{
|
||||
$rbacUser = factory(RbacUsers::class)->create();
|
||||
$user = factory(User::class)->create([
|
||||
'USR_UID' => $rbacUser['USR_UID'],
|
||||
'USR_USERNAME' => $rbacUser['USR_USERNAME'],
|
||||
'USR_PASSWORD' => $rbacUser['USR_PASSWORD'],
|
||||
'USR_FIRSTNAME' => $rbacUser['USR_FIRSTNAME'],
|
||||
'USR_LASTNAME' => $rbacUser['USR_LASTNAME'],
|
||||
'USR_EMAIL' => $rbacUser['USR_EMAIL'],
|
||||
]);
|
||||
$group = factory(Groupwf::class)->create();
|
||||
|
||||
$res = GroupUser::verifyUserIsInGroup($user['USR_ID'], $group['GRP_ID']);
|
||||
$this->assertFalse($res);
|
||||
|
||||
GroupUser::assignUserToGroup($rbacUser['USR_UID'], $user['USR_ID'], $group['GRP_UID'], $group['GRP_ID']);
|
||||
|
||||
$res = GroupUser::verifyUserIsInGroup($user['USR_ID'], $group['GRP_ID']);
|
||||
$this->assertTrue($res);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\Groupwf;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ProcessTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\Groupwf
|
||||
*/
|
||||
class GroupwfTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* It tests the verifyGroupExists() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_verify_group_exists_method()
|
||||
{
|
||||
$groupWf = factory(Groupwf::class)->create();
|
||||
|
||||
$res = Groupwf::verifyGroupExists($groupWf['GRP_UID']);
|
||||
$this->assertTrue($res);
|
||||
|
||||
$res = Groupwf::verifyGroupExists('12345');
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getGroupId() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_get_group_id_method()
|
||||
{
|
||||
$groupWf = factory(Groupwf::class)->create();
|
||||
|
||||
$res = Groupwf::getGroupId($groupWf['GRP_UID']);
|
||||
$this->assertNotEmpty($res);
|
||||
$this->assertEquals($res['GRP_ID'], $groupWf['GRP_ID']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\RbacRoles;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ProcessTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\RbacRoles
|
||||
*/
|
||||
class RbacRolesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* It tests the getRolUidByCode() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_get_rol_uid_by_code_method()
|
||||
{
|
||||
$rol1 = factory(RbacRoles::class)->create([
|
||||
'ROL_CODE' => 'TEST_ROLE'
|
||||
]);
|
||||
|
||||
$rolUid = RbacRoles::getRolUidByCode('TEST_ROLE');
|
||||
$this->assertEquals($rolUid['ROL_UID'], $rol1->ROL_UID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||
|
||||
use G;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\RbacRoles;
|
||||
use ProcessMaker\Model\RbacUsers;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ProcessTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\SubProcess
|
||||
*/
|
||||
class RbacUsersTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* It tests the verifyUsernameExists() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_verify_username_exists_method()
|
||||
{
|
||||
$rbacUser = factory(RbacUsers::class)->create([
|
||||
'USR_USERNAME' => 'test'
|
||||
]);
|
||||
|
||||
$res = RbacUsers::verifyUsernameExists('test');
|
||||
$this->assertTrue($res);
|
||||
|
||||
$res = RbacUsers::verifyUsernameExists('test2');
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the createUser() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_create_user_method()
|
||||
{
|
||||
$roles = factory(RbacRoles::class)->create();
|
||||
$data = [
|
||||
'USR_UID' => G::generateUniqueID(),
|
||||
'USR_USERNAME' => 'test',
|
||||
'USR_PASSWORD' => 'sample',
|
||||
'USR_FIRSTNAME' => 'test',
|
||||
'USR_LASTNAME' => 'test',
|
||||
'USR_EMAIL' => 'test@test.com',
|
||||
'USR_DUE_DATE' => '2021-01-01',
|
||||
'USR_CREATE_DATE' => '2021-01-01',
|
||||
'USR_UPDATE_DATE' => '2021-01-01',
|
||||
'USR_STATUS_ID' => 1,
|
||||
'USR_AUTH_TYPE' => '',
|
||||
'UID_AUTH_SOURCE' => '',
|
||||
'USR_AUTH_USER_DN' => '',
|
||||
'USR_AUTH_SUPERVISOR_DN' => '',
|
||||
'ROL_UID' => $roles['ROL_UID']
|
||||
];
|
||||
$res = RbacUsers::createUser($data);
|
||||
$this->assertNotEmpty($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the verifyUserExists() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_verify_user_exists_method()
|
||||
{
|
||||
$rbacUser = factory(RbacUsers::class)->create();
|
||||
|
||||
$res = RbacUsers::verifyUserExists($rbacUser['USR_UID']);
|
||||
$this->assertTrue($res);
|
||||
|
||||
$res = RbacUsers::verifyUserExists('12345');
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
}
|
||||
@@ -189,4 +189,39 @@ class UserTest extends TestCase
|
||||
$results = User::getAllInformation($user->USR_ID);
|
||||
$this->assertNotEmpty($results);
|
||||
}
|
||||
/**
|
||||
* It test get the createUser() method
|
||||
*
|
||||
* @covers \ProcessMaker\Model\User::createUser()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_create_user_method()
|
||||
{
|
||||
$usrData = [
|
||||
'USR_UID' => G::generateUniqueID(),
|
||||
'USR_USERNAME' => 'test',
|
||||
'USR_PASSWORD' => 'sample',
|
||||
'USR_FIRSTNAME' => 'test',
|
||||
'USR_LASTNAME' => 'test',
|
||||
'USR_EMAIL' => 'test@sample.com',
|
||||
'USR_DUE_DATE' => '2021-12-12',
|
||||
'USR_CREATE_DATE' => '2021-12-12',
|
||||
'USR_UPDATE_DATE' => '2021-12-12',
|
||||
'USR_STATUS' => 'ACTIVE',
|
||||
'USR_STATUS_ID' => 1,
|
||||
'USR_COUNTRY' => '',
|
||||
'USR_CITY' => '',
|
||||
'USR_LOCATION' => '',
|
||||
'USR_ADDRESS' => '',
|
||||
'USR_PHONE' => '',
|
||||
'USR_FAX' => '',
|
||||
'USR_CELLULAR' => '',
|
||||
'USR_ZIP_CODE' => '',
|
||||
'DEP_UID' => '',
|
||||
'USR_POSITION' => '',
|
||||
'USR_RESUME' => ''
|
||||
];
|
||||
$res = User::createUser($usrData);
|
||||
$this->assertInternalType('integer', $res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user