PMCORE-561

This commit is contained in:
Andrea Adamczyk
2020-09-08 16:20:28 -04:00
parent d60dbe1e37
commit fe49792fc0
11 changed files with 355 additions and 13 deletions

View File

@@ -0,0 +1,147 @@
<?php
namespace Tests\unit\workflow\engine\methods\users;
use ProcessMaker\Model\Configuration;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\RbacUsers;
use ProcessMaker\Model\User;
use RBAC;
use Tests\TestCase;
class Users_AjaxTest extends TestCase
{
/**
* Set up the deprecated errors
*/
public function setUp()
{
parent::setUp();
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
}
/**
* Tests the users_ajax file with the privateProcesses action
* @test
*/
public function it_tests_the_users_ajax_file_private_processes_action()
{
$_POST = [];
//Declare the global variable
global $RBAC;
//Creates the user factory
$user = factory(User::class)->create();
$usrUid = $user['USR_UID'];
factory(Process::class)->create([
'PRO_CREATE_USER' => $usrUid,
'PRO_STATUS' => 'ACTIVE',
'PRO_TYPE_PROCESS' => 'PRIVATE',
]);
//Creates the configuration factory
factory(Configuration::class)->create([
'CFG_UID' => 'USER_PREFERENCES',
'OBJ_UID' => '',
'CFG_VALUE' => 'a:3:{s:12:"DEFAULT_LANG";s:0:"";s:12:"DEFAULT_MENU";s:8:"PM_SETUP";s:18:"DEFAULT_CASES_MENU";s:0:"";}',
'PRO_UID' => '',
'USR_UID' => $usrUid,
'APP_UID' => '',
]);
//Sets the needed variables
$_SESSION['USER_LOGGED'] = '00000000000000000000000000000001';
$_POST['action'] = 'privateProcesses';
$_POST['USR_UID'] = $usrUid;
$_REQUEST['function'] = 'privateProcesses';
$_GET['function'] = 'privateProcesses';
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->initRBAC();
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
//Turn on output buffering
ob_start();
//Call the tested file
require_once PATH_TRUNK . 'workflow/engine/methods/users/users_Ajax.php';
//Return the contents of the output buffer
$outputBuffer = ob_get_contents();
//Clean the output buffer and turn off output buffering
ob_end_clean();
//Removing the BOM (Byte Order Mark)
if (0 === strpos(bin2hex($outputBuffer), 'efbbbf')) {
//Decode the JSON string
$res = json_decode(substr($outputBuffer, 3));
} else {
//Decode the JSON string
$res = json_decode($outputBuffer);
}
//Assert the response contains a row
$this->assertNotEmpty($res);
}
/**
* Tests the users_ajax file with the deleteUser action
* @test
*/
public function it_tests_the_users_ajax_file_delete_user_action()
{
//Declare the global variable
global $RBAC;
//Creates the user factory
$user = factory(User::class)->create();
factory(RbacUsers::class)->create([
'USR_UID' => $user['USR_UID'],
'USR_USERNAME' => $user->USR_USERNAME,
'USR_FIRSTNAME' => $user->USR_FIRSTNAME,
'USR_LASTNAME' => $user->USR_LASTNAME
]);
$usrUid = $user['USR_UID'];
$process = factory(Process::class)->create([
'PRO_CREATE_USER' => $usrUid,
'PRO_STATUS' => 'ACTIVE',
'PRO_TYPE_PROCESS' => 'PRIVATE',
]);
//Sets the needed variables
$_SESSION['USER_LOGGED'] = '00000000000000000000000000000001';
$_POST['action'] = 'userData';
$_POST['USR_UID'] = $usrUid;
$_REQUEST['function'] = 'deleteUser';
$_GET['function'] = 'deleteUser';
$_POST['private_processes'] = Process::where('PRO_ID', $process->PRO_ID)->get();
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->initRBAC();
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
//Turn on output buffering
ob_start();
//Call the tested file
require_once PATH_TRUNK . 'workflow/engine/methods/users/users_Ajax.php';
//Return the contents of the output buffer
$outputBuffer = ob_get_contents();
//Clean the output buffer and turn off output buffering
ob_end_clean();
//Removing the BOM (Byte Order Mark)
if (0 === strpos(bin2hex($outputBuffer), 'efbbbf')) {
//Decode the JSON string
$res = json_decode(substr($outputBuffer, 3));
} else {
//Decode the JSON string
$res = json_decode($outputBuffer);
}
//Asserts the result is null
$this->assertNull($res);
}
}

View File

@@ -183,4 +183,63 @@ class ProcessTest extends TestCase
$this->assertNotEquals($process2['PRO_UID'], $res[0]['PRO_UID']);
$this->assertNotEquals($process3['PRO_UID'], $res[0]['PRO_UID']);
}
/**
* It tests the getProcessPrivateListByUser method
*
* @covers \ProcessMaker\Model\Process::getProcessPrivateListByUser()
* @test
*/
public function it_should_test_the_get_process_private_list_by_user_method()
{
//Create user
$user = factory(User::class)->create();
//Create process
factory(Process::class)->create([
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'ACTIVE',
'PRO_TYPE_PROCESS' => 'PRIVATE',
]);
//Create a Process object
$process = new Process();
//Call the getProcessPrivateListByUser() method
$res = $process->getProcessPrivateListByUser($user['USR_UID']);
// This asserts the result contains one row
$this->assertCount(1, $res);
}
/**
* It tests the convertPrivateProcessesToPublic method
*
* @covers \ProcessMaker\Model\Process::convertPrivateProcessesToPublic()
* @test
*/
public function it_should_test_the_convert_private_processes_to_public_method()
{
//Create user
$user = factory(User::class)->create();
//Create process
$pro = factory(Process::class)->create([
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'ACTIVE',
'PRO_TYPE_PROCESS' => 'PRIVATE',
]);
$p = Process::where('PRO_UID', $pro->PRO_UID)->get()->values()->toArray();
//Create a Process object
$process = new Process();
//Call the convertPrivateProcessesToPublic() method
$process->convertPrivateProcessesToPublic($p);
$p = Process::where('PRO_UID', $pro->PRO_UID)->get()->values();
// This asserts the process was converted from private to public
$this->assertEquals('PUBLIC', $p[0]->PRO_TYPE_PROCESS);
}
}

View File

@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Services\Api;
use Faker\Factory;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ProcessMaker\Model\RbacUsers;
use ProcessMaker\Importer\XmlImporter;
use ProcessMaker\Services\Api\Project;
use Tests\TestCase;
@@ -40,4 +41,52 @@ class ProjectTest extends TestCase
$this->assertNotEmpty($result);
}
/**
* Tests the doGetProcess method
*
* @test
* @covers \ProcessMaker\Services\Api\Project::doGetProcess()
*/
public function it_should_test_the_do_get_process_method()
{
//Create user
$user = factory(User::class)->create();
factory(RbacUsers::class)->create([
'USR_UID' => $user->USR_UID,
'USR_USERNAME' => $user->USR_USERNAME,
'USR_FIRSTNAME' => $user->USR_FIRSTNAME,
'USR_LASTNAME' => $user->USR_LASTNAME
]);
//Create process
$process = factory(Process::class)->create([
'PRO_CREATE_USER' => $user->USR_UID,
'PRO_STATUS' => 'ACTIVE',
'PRO_TYPE_PROCESS' => 'PRIVATE',
]);
$project = new Project();
$res = $project->doGetProcess($process->PRO_UID);
//Asserts the response has the user information
$this->assertArrayHasKey('pro_create_username', $res);
$this->assertArrayHasKey('pro_create_firstname', $res);
$this->assertArrayHasKey('pro_create_lastname', $res);
}
/**
* Tests the doGetProcess with exception
*
* @test
* @covers \ProcessMaker\Services\Api\Project::doGetProcess()
*/
public function it_should_test_the_do_get_process_method_with_exception()
{
$project = new Project();
//This asserts the expected exception
$this->expectExceptionMessage("**ID_PROJECT_DOES_NOT_EXIST**");
$project->doGetProcess('');
}
}