PMCORE-1217
This commit is contained in:
@@ -0,0 +1,719 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
|
||||
|
||||
use ProcessMaker\BusinessModel\Cases\Paused;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\AppDelay;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\Task;
|
||||
use ProcessMaker\Model\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class PausedTest
|
||||
*
|
||||
* @coversDefaultClass ProcessMaker\BusinessModel\Cases\Paused
|
||||
* @package Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases
|
||||
*/
|
||||
class PausedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* It tests the getData method without filters
|
||||
*
|
||||
* @covers ::getData()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_data_method_without_filters()
|
||||
{
|
||||
//Create process
|
||||
$process = factory(Process::class)->create();
|
||||
|
||||
//Create user
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
//Create a task
|
||||
$task = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'TAS_TYPE' => 'NORMAL'
|
||||
]);
|
||||
|
||||
$application = factory(Application::class)->create();
|
||||
//Create the register in delegation
|
||||
$delegation1 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process->PRO_ID,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
|
||||
$delegation2 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process->PRO_ID,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_NUMBER' => $delegation1->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation1->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_NUMBER' => $delegation2->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation2->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
|
||||
//Create new Paused object
|
||||
$paused = new Paused();
|
||||
|
||||
//Set the user UID
|
||||
$paused->setUserUid($user->USR_UID);
|
||||
|
||||
//Set the user ID
|
||||
$paused->setUserId($user->USR_ID);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This assert that the expected numbers of results are returned with no filters
|
||||
$this->assertEquals(10, count($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getData method with category filter
|
||||
*
|
||||
* @covers ::getData()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_data_method_with_category_filter()
|
||||
{
|
||||
//Create processes
|
||||
$process1 = factory(Process::class)->create(
|
||||
['PRO_CATEGORY' => '1']
|
||||
);
|
||||
$process2 = factory(Process::class)->create(
|
||||
['PRO_CATEGORY' => '2']
|
||||
);
|
||||
|
||||
//Create user
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
//Create a task
|
||||
$task = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'TAS_TYPE' => 'NORMAL'
|
||||
]);
|
||||
|
||||
$application = factory(Application::class)->create();
|
||||
//Create the register in delegation
|
||||
$delegation1 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
|
||||
$delegation2 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation1->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation1->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation2->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation2->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
|
||||
//Create new Paused object
|
||||
$paused = new Paused();
|
||||
|
||||
//Set the user UID
|
||||
$paused->setUserUid($user->USR_UID);
|
||||
|
||||
//Set the user ID
|
||||
$paused->setUserId($user->USR_ID);
|
||||
|
||||
//Set the Category Status
|
||||
$paused->setCategoryUid($process1->PRO_CATEGORY);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This assert the expected results for an specific category
|
||||
$this->assertCount(5, $res);
|
||||
|
||||
//This assert the expected value for the category
|
||||
$this->assertEquals(1, $res[0]['PRO_CATEGORY']);
|
||||
|
||||
//Set the Category Status
|
||||
$paused->setCategoryUid($process2->PRO_CATEGORY);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This assert the expected results for an specific category
|
||||
$this->assertCount(5, $res);
|
||||
|
||||
//This assert the expected value for the category
|
||||
$this->assertEquals(2, $res[0]['PRO_CATEGORY']);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getData method with app number filter
|
||||
*
|
||||
* @covers ::getData()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_data_method_with_app_number_filter()
|
||||
{
|
||||
//Create processes
|
||||
$process1 = factory(Process::class)->create(
|
||||
['PRO_CATEGORY' => '1']
|
||||
);
|
||||
$process2 = factory(Process::class)->create(
|
||||
['PRO_CATEGORY' => '2']
|
||||
);
|
||||
|
||||
//Create user
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
//Create a task
|
||||
$task = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'TAS_TYPE' => 'NORMAL'
|
||||
]);
|
||||
|
||||
$application1 = factory(Application::class)->create();
|
||||
$application2 = factory(Application::class)->create();
|
||||
|
||||
//Create the register in delegation
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation1 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation2 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation1->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation1->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation2->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation2->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
|
||||
//Create new Paused object
|
||||
$paused = new Paused();
|
||||
|
||||
//Set the user UID
|
||||
$paused->setUserUid($user->USR_UID);
|
||||
|
||||
//Set the user ID
|
||||
$paused->setUserId($user->USR_ID);
|
||||
|
||||
//Set app number
|
||||
$paused->setCaseNumber($delegation1->APP_NUMBER);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This asserts there are results for the filtered app number
|
||||
$this->assertCount(5, $res);
|
||||
|
||||
//This asserts the result corresponds to the app number filtered
|
||||
$this->assertEquals($delegation1->APP_NUMBER, $res[0]['APP_NUMBER']);
|
||||
|
||||
//Set app number
|
||||
$paused->setCaseNumber($delegation2->APP_NUMBER);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This asserts there are results for the filtered app number
|
||||
$this->assertCount(5, $res);
|
||||
|
||||
//This asserts the result corresponds to the app number filtered
|
||||
$this->assertEquals($delegation2->APP_NUMBER, $res[0]['APP_NUMBER']);;
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getData method with taskId filter
|
||||
*
|
||||
* @covers ::getData()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_data_method_with_task_id_filter()
|
||||
{
|
||||
//Create processes
|
||||
$process1 = factory(Process::class)->create();
|
||||
$process2 = factory(Process::class)->create();
|
||||
|
||||
//Create user
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
//Create a task
|
||||
$task1 = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
]);
|
||||
|
||||
$task2 = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
]);
|
||||
|
||||
$application1 = factory(Application::class)->create();
|
||||
$application2 = factory(Application::class)->create();
|
||||
|
||||
//Create the register in delegation
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task1->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation1 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task1->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task2->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation2 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task2->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation1->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation1->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation2->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation2->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
|
||||
//Create new Paused object
|
||||
$paused = new Paused();
|
||||
|
||||
//Set the user UID
|
||||
$paused->setUserUid($user->USR_UID);
|
||||
|
||||
//Set the user ID
|
||||
$paused->setUserId($user->USR_ID);
|
||||
|
||||
//Set taskId
|
||||
$paused->setTaskId($task1->TAS_ID);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This asserts there are results for the filtered task
|
||||
$this->assertCount(5, $res);
|
||||
|
||||
//This asserts the result corresponds to the task filtered
|
||||
$this->assertEquals($task1->TAS_ID, $res[0]['TAS_ID']);
|
||||
|
||||
//Set taskId
|
||||
$paused->setTaskId($task2->TAS_ID);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This asserts there are results for the filtered task
|
||||
$this->assertCount(5, $res);
|
||||
|
||||
//This asserts the result corresponds to the task filtered
|
||||
$this->assertEquals($task2->TAS_ID, $res[0]['TAS_ID']);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getData method using OrderBy Case Number
|
||||
*
|
||||
* @covers ::getData()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_return_inbox_sort_by_case_number()
|
||||
{
|
||||
//Create processes
|
||||
$process1 = factory(Process::class)->create();
|
||||
$process2 = factory(Process::class)->create();
|
||||
|
||||
//Create user
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
//Create a task
|
||||
$task1 = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
]);
|
||||
|
||||
$task2 = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
]);
|
||||
|
||||
$application1 = factory(Application::class)->create();
|
||||
$application2 = factory(Application::class)->create();
|
||||
|
||||
//Create the register in delegation
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task1->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation1 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task1->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task2->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation2 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task2->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation1->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation1->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation2->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation2->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
|
||||
//Create new Paused object
|
||||
$paused = new Paused();
|
||||
|
||||
//Set the user UID
|
||||
$paused->setUserUid($user->USR_UID);
|
||||
|
||||
//Set the user ID
|
||||
$paused->setUserId($user->USR_ID);
|
||||
|
||||
//Set OrderBYColumn value
|
||||
$paused->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||
|
||||
//Set Order Direction value
|
||||
$paused->setOrderDirection('DESC');
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//Asserts that the order is descending
|
||||
$this->assertGreaterThan($res[count($res) - 1]['APP_NUMBER'], $res[0]['APP_NUMBER']);
|
||||
|
||||
//Set Order Direction value
|
||||
$paused->setOrderDirection('ASC');
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//Asserts that the order is ascending
|
||||
$this->assertLessThan($res[count($res) - 1]['APP_NUMBER'], $res[0]['APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the limit
|
||||
*
|
||||
* @covers ::getData()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_data_method_with_limit()
|
||||
{
|
||||
//Create processes
|
||||
$process1 = factory(Process::class)->create();
|
||||
$process2 = factory(Process::class)->create();
|
||||
|
||||
//Create user
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
//Create a task
|
||||
$task1 = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
]);
|
||||
|
||||
$task2 = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => '',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
]);
|
||||
|
||||
$application1 = factory(Application::class)->create();
|
||||
$application2 = factory(Application::class)->create();
|
||||
|
||||
//Create the register in delegation
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task1->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation1 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application1->APP_NUMBER,
|
||||
'TAS_ID' => $task1->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process1->PRO_ID,
|
||||
'PRO_UID' => $process1->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task2->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 0,
|
||||
'DEL_INDEX' => 1
|
||||
]);
|
||||
$delegation2 = factory(Delegation::class)->create([
|
||||
'APP_NUMBER' => $application2->APP_NUMBER,
|
||||
'TAS_ID' => $task2->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_ID' => $user->USR_ID,
|
||||
'PRO_ID' => $process2->PRO_ID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2
|
||||
]);
|
||||
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation1->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation1->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
//Create the registers in AppDelay
|
||||
factory(AppDelay::class, 5)->create([
|
||||
'APP_DELEGATION_USER' => $user->USR_UID,
|
||||
'PRO_UID' => $process2->PRO_UID,
|
||||
'APP_NUMBER' => $delegation2->APP_NUMBER,
|
||||
'APP_DEL_INDEX' => $delegation2->DEL_INDEX,
|
||||
'APP_DISABLE_ACTION_USER' => 0,
|
||||
'APP_TYPE' => 'PAUSE'
|
||||
]);
|
||||
|
||||
//Create new Paused object
|
||||
$paused = new Paused();
|
||||
|
||||
//Set the user UID
|
||||
$paused->setUserUid($user->USR_UID);
|
||||
|
||||
//Set the user ID
|
||||
$paused->setUserId($user->USR_ID);
|
||||
|
||||
//Set OrderBYColumn value
|
||||
$paused->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||
|
||||
//Set offset and limit values
|
||||
$paused->setOffset(0);
|
||||
$paused->setLimit(2);
|
||||
|
||||
//Call to getData method
|
||||
$res = $paused->getData();
|
||||
|
||||
//This assert that there are results with read inbox status
|
||||
$this->assertCount(2, $res);
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,9 @@ class AbstractCases implements CasesInterface
|
||||
// Filter by specific cases using the case numbers
|
||||
private $casesNumbers = [];
|
||||
|
||||
// Filter by taskId
|
||||
private $taskId = '';
|
||||
|
||||
// Filter recent cases starting by a specific date, know as "newestthan" in the old lists classes
|
||||
private $newestThan = '';
|
||||
|
||||
@@ -425,6 +428,26 @@ class AbstractCases implements CasesInterface
|
||||
return $this->casesNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set taskId value
|
||||
*
|
||||
* @param int $taskId
|
||||
*/
|
||||
public function setTaskId($taskId)
|
||||
{
|
||||
$this->taskId = (int) $taskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get taskId value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTaskId()
|
||||
{
|
||||
return $this->taskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Newest Than value
|
||||
*
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel\Cases;
|
||||
|
||||
use ProcessMaker\Model\Delegation;
|
||||
|
||||
class Paused extends AbstractCases
|
||||
{
|
||||
/**
|
||||
* Gets the data for the paused cases list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
$query = Delegation::query()->select();
|
||||
$query->paused($this->getUserId(), $this->getCategoryUid(), $this->getTaskId(), $this->getCaseNumber());
|
||||
$query->joinPreviousIndex();
|
||||
$query->joinPreviousUser();
|
||||
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
|
||||
$query->offset($this->getOffset())->limit($this->getLimit());
|
||||
|
||||
$result = $query->get()->values()->toArray();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total for the paused cases list
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCounter()
|
||||
{
|
||||
$total = $this->getData();
|
||||
|
||||
return count($total);
|
||||
}
|
||||
}
|
||||
@@ -358,8 +358,6 @@ class Delegation extends Model
|
||||
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
|
||||
->whereNotIn('TASK.TAS_TYPE', $taskTypes);
|
||||
});
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -570,6 +568,118 @@ class Delegation extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope AppDelay and AppDelegation
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAppDelayPaused($query)
|
||||
{
|
||||
$query->leftJoin('APP_DELAY', function ($leftJoin) {
|
||||
$leftJoin->on('APP_DELAY.APP_NUMBER', '=', 'APP_DELEGATION.APP_NUMBER')
|
||||
->on('APP_DELEGATION.DEL_INDEX', '=', 'APP_DELAY.APP_DEL_INDEX');
|
||||
});
|
||||
|
||||
$query->where('APP_DELAY.APP_DISABLE_ACTION_USER', '=', '0');
|
||||
$query->where('APP_DELAY.APP_TYPE', '=', 'PAUSE');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope Users and AppDelay
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $userId
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAppDelayUserDel($query, $userId)
|
||||
{
|
||||
$query->leftJoin('USERS', function ($leftJoin) {
|
||||
$leftJoin->on('APP_DELAY.APP_DELEGATION_USER', '=', 'USERS.USR_UID');
|
||||
});
|
||||
|
||||
if ($userId) {
|
||||
$query->where('USERS.USR_ID', $userId);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope Application and AppDelegation
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeApplication($query)
|
||||
{
|
||||
$query->leftJoin('APPLICATION', function ($leftJoin) {
|
||||
$leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope paused cases list
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $userId
|
||||
* @param string $categoryUid
|
||||
* @param int $taskId
|
||||
* @param int $caseNumber
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopePaused($query, $userId, $categoryUid, $taskId, $caseNumber)
|
||||
{
|
||||
$query->appDelayPaused();
|
||||
$query->appDelayUserDel($userId);
|
||||
$query->application();
|
||||
$query->caseNumberFilter($caseNumber);
|
||||
$query->categoryProcess($categoryUid);
|
||||
$query->excludeTaskTypes(Task::DUMMY_TASKS);
|
||||
$query->taskIdFilter($taskId);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope taskId filter
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $taskId
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTaskIdFilter($query, $taskId)
|
||||
{
|
||||
if ($taskId) {
|
||||
$query->where('TASK.TAS_ID', $taskId);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope CaseNumber Filter
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $caseNumber
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCaseNumberFilter($query, $caseNumber)
|
||||
{
|
||||
if ($caseNumber) {
|
||||
$query->where('APP_DELEGATION.APP_NUMBER', $caseNumber);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific cases unassigned that the user can view
|
||||
*
|
||||
@@ -702,8 +812,11 @@ class Delegation extends Model
|
||||
$config = System::getSystemConfiguration();
|
||||
if ((int)$config['disable_advanced_search_case_title_fulltext'] === 0) {
|
||||
// Cleaning "fulltext" operators in order to avoid unexpected results
|
||||
$search = str_replace(['-', '+', '<', '>', '(', ')', '~', '*', '"'],
|
||||
['', '', '', '', '', '', '', '', ''], $search);
|
||||
$search = str_replace(
|
||||
['-', '+', '<', '>', '(', ')', '~', '*', '"'],
|
||||
['', '', '', '', '', '', '', '', ''],
|
||||
$search
|
||||
);
|
||||
|
||||
// Build the "fulltext" expression
|
||||
$search = '+"' . preg_replace('/\s+/', '" +"', addslashes($search)) . '"';
|
||||
@@ -966,9 +1079,16 @@ class Delegation extends Model
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public static function getSelfServiceQuery($usrUid, $count = false, $selectedColumns = ['APP_DELEGATION.APP_NUMBER', 'APP_DELEGATION.DEL_INDEX'],
|
||||
$categoryUid = null, $processUid = null, $textToSearch = null, $sort = null, $dir = null)
|
||||
{
|
||||
public static function getSelfServiceQuery(
|
||||
$usrUid,
|
||||
$count = false,
|
||||
$selectedColumns = ['APP_DELEGATION.APP_NUMBER', 'APP_DELEGATION.DEL_INDEX'],
|
||||
$categoryUid = null,
|
||||
$processUid = null,
|
||||
$textToSearch = null,
|
||||
$sort = null,
|
||||
$dir = null
|
||||
) {
|
||||
// Set the 'usrUid' property to preserve
|
||||
Delegation::$usrUid = $usrUid;
|
||||
|
||||
@@ -994,7 +1114,7 @@ class Delegation extends Model
|
||||
|
||||
// Add join clause with the previous APP_DELEGATION record if required
|
||||
if (array_search('APP_DELEGATION.DEL_PREVIOUS', $selectedColumns) !== false) {
|
||||
$query1->join('APP_DELEGATION AS ADP', function ($join) {
|
||||
$query1->join('APP_DELEGATION AS ADP', function ($join) {
|
||||
$join->on('APP_DELEGATION.APP_NUMBER', '=', 'ADP.APP_NUMBER');
|
||||
$join->on('APP_DELEGATION.DEL_PREVIOUS', '=', 'ADP.DEL_INDEX');
|
||||
});
|
||||
@@ -1026,8 +1146,7 @@ class Delegation extends Model
|
||||
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID');
|
||||
$join->on('TASK.TAS_ASSIGN_TYPE', '=', DB::raw("'SELF_SERVICE'"));
|
||||
$join->on('APP_DELEGATION.DEL_THREAD_STATUS', '=', DB::raw("'OPEN'"));
|
||||
$join->on('APP_DELEGATION.USR_ID', '=', DB::raw("'0'"))->
|
||||
whereRaw($complexJoin);
|
||||
$join->on('APP_DELEGATION.USR_ID', '=', DB::raw("'0'"))->whereRaw($complexJoin);
|
||||
});
|
||||
|
||||
// Add join clause with APPLICATION table if required
|
||||
@@ -1073,7 +1192,7 @@ class Delegation extends Model
|
||||
|
||||
// Add join clause with the previous APP_DELEGATION record if required
|
||||
if (array_search('APP_DELEGATION.DEL_PREVIOUS', $selectedColumns) !== false) {
|
||||
$query2->join('APP_DELEGATION AS ADP', function ($join) {
|
||||
$query2->join('APP_DELEGATION AS ADP', function ($join) {
|
||||
$join->on('APP_DELEGATION.APP_NUMBER', '=', 'ADP.APP_NUMBER');
|
||||
$join->on('APP_DELEGATION.DEL_PREVIOUS', '=', 'ADP.DEL_INDEX');
|
||||
});
|
||||
@@ -1084,7 +1203,6 @@ class Delegation extends Model
|
||||
$query2->join('TASK', function ($join) {
|
||||
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID');
|
||||
});
|
||||
|
||||
}
|
||||
// Add join clause with APPLICATION table if required
|
||||
if (array_search('APPLICATION.APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') {
|
||||
@@ -1114,9 +1232,14 @@ class Delegation extends Model
|
||||
}
|
||||
|
||||
// Build the complex query that uses "UNION DISTINCT" clause
|
||||
$query = sprintf('select ' . ($count ? 'count(*) as aggregate' : '*') .
|
||||
' from ((%s) union distinct (%s)) self_service_cases' . (!empty($sort) && !empty($dir) ? ' ORDER BY %s %s' : ''),
|
||||
toSqlWithBindings($query1), toSqlWithBindings($query2), $sort, $dir);
|
||||
$query = sprintf(
|
||||
'select ' . ($count ? 'count(*) as aggregate' : '*') .
|
||||
' from ((%s) union distinct (%s)) self_service_cases' . (!empty($sort) && !empty($dir) ? ' ORDER BY %s %s' : ''),
|
||||
toSqlWithBindings($query1),
|
||||
toSqlWithBindings($query2),
|
||||
$sort,
|
||||
$dir
|
||||
);
|
||||
|
||||
return $query;
|
||||
} else {
|
||||
@@ -1141,9 +1264,17 @@ class Delegation extends Model
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public static function getSelfService($usrUid, $selectedColumns = ['APP_DELEGATION.APP_NUMBER', 'APP_DELEGATION.DEL_INDEX'],
|
||||
$categoryUid = null, $processUid = null, $textToSearch = null, $sort = null, $dir = null, $offset = null, $limit = null)
|
||||
{
|
||||
public static function getSelfService(
|
||||
$usrUid,
|
||||
$selectedColumns = ['APP_DELEGATION.APP_NUMBER', 'APP_DELEGATION.DEL_INDEX'],
|
||||
$categoryUid = null,
|
||||
$processUid = null,
|
||||
$textToSearch = null,
|
||||
$sort = null,
|
||||
$dir = null,
|
||||
$offset = null,
|
||||
$limit = null
|
||||
) {
|
||||
// Initializing the variable to return
|
||||
$data = [];
|
||||
|
||||
@@ -1189,8 +1320,14 @@ class Delegation extends Model
|
||||
public static function countSelfService($usrUid, $categoryUid = null, $processUid = null, $textToSearch = null)
|
||||
{
|
||||
// Get the query
|
||||
$query = self::getSelfServiceQuery($usrUid, true, ['APP_DELEGATION.APP_NUMBER', 'APP_DELEGATION.DEL_INDEX'],
|
||||
$categoryUid, $processUid, $textToSearch);
|
||||
$query = self::getSelfServiceQuery(
|
||||
$usrUid,
|
||||
true,
|
||||
['APP_DELEGATION.APP_NUMBER', 'APP_DELEGATION.DEL_INDEX'],
|
||||
$categoryUid,
|
||||
$processUid,
|
||||
$textToSearch
|
||||
);
|
||||
|
||||
// Get count value
|
||||
if (!is_string($query)) {
|
||||
@@ -1311,9 +1448,9 @@ class Delegation extends Model
|
||||
$finishDate = new DateTime($endDate);
|
||||
$diff = $initDate->diff($finishDate);
|
||||
$format = ' %a ' . G::LoadTranslation('ID_DAY_DAYS');
|
||||
$format .= ' %H '. G::LoadTranslation('ID_HOUR_ABBREVIATE');
|
||||
$format .= ' %I '. G::LoadTranslation('ID_MINUTE_ABBREVIATE');
|
||||
$format .= ' %S '. G::LoadTranslation('ID_SECOND_ABBREVIATE');
|
||||
$format .= ' %H ' . G::LoadTranslation('ID_HOUR_ABBREVIATE');
|
||||
$format .= ' %I ' . G::LoadTranslation('ID_MINUTE_ABBREVIATE');
|
||||
$format .= ' %S ' . G::LoadTranslation('ID_SECOND_ABBREVIATE');
|
||||
$thread['DEL_THREAD_DURATION'] = $diff->format($format);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user