diff --git a/database/factories/AppAssignSelfServiceValueFactory.php b/database/factories/AppAssignSelfServiceValueFactory.php new file mode 100644 index 000000000..f1b7360c1 --- /dev/null +++ b/database/factories/AppAssignSelfServiceValueFactory.php @@ -0,0 +1,18 @@ +define(\ProcessMaker\Model\AppAssignSelfServiceValue::class, function(Faker $faker) { + return [ + 'ID' => $faker->unique()->numberBetween(1, 2000), + 'APP_UID' => G::generateUniqueID(), + 'DEL_INDEX' => 2, + 'PRO_UID' => G::generateUniqueID(), + 'TAS_UID' => G::generateUniqueID(), + 'TAS_ID' => $faker->unique()->numberBetween(1, 2000), + 'GRP_UID' => G::generateUniqueID(), + ]; +}); + diff --git a/database/factories/AppAssignSelfServiceValueGroupFactory.php b/database/factories/AppAssignSelfServiceValueGroupFactory.php new file mode 100644 index 000000000..72057cb5c --- /dev/null +++ b/database/factories/AppAssignSelfServiceValueGroupFactory.php @@ -0,0 +1,15 @@ +define(\ProcessMaker\Model\AppAssignSelfServiceValueGroup::class, function(Faker $faker) { + return [ + 'ID' => $faker->unique()->numberBetween(1, 2000), + 'GRP_UID' => G::generateUniqueID(), + 'ASSIGNEE_ID' => $faker->unique()->numberBetween(1, 2000), + 'ASSIGNEE_TYPE' => $faker->unique()->numberBetween(1, 2000), + ]; +}); + diff --git a/database/factories/GroupUserFactory.php b/database/factories/GroupUserFactory.php new file mode 100644 index 000000000..d7f51ee31 --- /dev/null +++ b/database/factories/GroupUserFactory.php @@ -0,0 +1,14 @@ +define(\ProcessMaker\Model\GroupUser::class, function(Faker $faker) { + return [ + 'GRP_UID' => G::generateUniqueID(), + 'GRP_ID' => $faker->unique()->numberBetween(1, 2000), + 'USR_UID' => G::generateUniqueID() + ]; +}); + diff --git a/database/factories/GroupwfFactory.php b/database/factories/GroupwfFactory.php new file mode 100644 index 000000000..7ab6ca271 --- /dev/null +++ b/database/factories/GroupwfFactory.php @@ -0,0 +1,17 @@ +define(\ProcessMaker\Model\Groupwf::class, function(Faker $faker) { + return [ + 'GRP_UID' => G::generateUniqueID(), + 'GRP_ID' => $faker->unique()->numberBetween(1, 2000), + 'GRP_TITLE' => $faker->sentence(2), + 'GRP_STATUS' => 'ACTIVE', + 'GRP_LDAP_DN' => '', + 'GRP_UX' => 'NORMAL', + ]; +}); + diff --git a/database/factories/ListUnassignedFactory.php b/database/factories/ListUnassignedFactory.php new file mode 100644 index 000000000..afbc01949 --- /dev/null +++ b/database/factories/ListUnassignedFactory.php @@ -0,0 +1,40 @@ +define(\ProcessMaker\Model\ListUnassigned::class, function (Faker $faker) { + $app = factory(\ProcessMaker\Model\Application::class)->create(); + $process = \ProcessMaker\Model\Process::where('PRO_UID', $app->PRO_UID)->first(); + $task = $process->tasks->first(); + // Grab a user if random + $users = \ProcessMaker\Model\User::all(); + if(!count($users)) { + $user = factory(\ProcessMaker\Model\User::class)->create(); + } else{ + $user = $users->random(); + } + + return [ + 'APP_UID' => $app->APP_UID, + 'DEL_INDEX' => 1, + 'TAS_UID' => $task->TAS_UID, + 'PRO_UID' => $app->PRO_UID, + 'APP_NUMBER' => $app->APP_NUMBER, + 'APP_TITLE' => $app->APP_TITLE, + 'APP_PRO_TITLE' => $process->PRO_TITLE, + 'APP_TAS_TITLE' => $task->TAS_TITLE, + 'DEL_PREVIOUS_USR_USERNAME' => $user->USR_USERNAME, + 'DEL_PREVIOUS_USR_FIRSTNAME' => $user->USR_FIRSTNAME, + 'DEL_PREVIOUS_USR_LASTNAME' => $user->USR_LASTNAME, + 'APP_UPDATE_DATE' => $faker->dateTime(), + 'DEL_PREVIOUS_USR_UID' => G::generateUniqueID(), + 'DEL_DELEGATE_DATE' => $faker->dateTime(), + 'DEL_DUE_DATE' => $faker->dateTime(), + 'DEL_PRIORITY' => 3, + 'PRO_ID' => $process->PRO_ID, + 'TAS_ID' => $task->TAS_ID, + ]; +}); + diff --git a/database/factories/ProcessFactory.php b/database/factories/ProcessFactory.php index 40ae93dc3..3bfa727ed 100644 --- a/database/factories/ProcessFactory.php +++ b/database/factories/ProcessFactory.php @@ -15,6 +15,7 @@ $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) { 'PRO_CREATE_USER' => '00000000000000000000000000000001', 'PRO_DYNAFORMS' => '', 'PRO_ITEE' => 1, + 'PRO_STATUS' => 'ACTIVE' ]; $task1 = factory(\ProcessMaker\Model\Task::class) diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index 41f1167a9..992afea7c 100644 --- a/database/factories/TaskFactory.php +++ b/database/factories/TaskFactory.php @@ -11,6 +11,7 @@ $factory->define(\ProcessMaker\Model\Task::class, function(Faker $faker) { return $process->PRO_UID; }, 'TAS_UID' => G::generateUniqueID(), + 'TAS_ID' => $faker->unique()->numberBetween(1, 2000), 'TAS_TITLE' => $faker->sentence(2), 'TAS_TYPE' => 'NORMAL', 'TAS_TYPE_DAY' => 1, diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php new file mode 100644 index 000000000..6574caef7 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php @@ -0,0 +1,834 @@ +create(); + //Create user + $user = factory(User::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + $timeStart = microtime(true); + $result = ListUnassigned::doCount($user[0]->USR_UID); + $timeEnd = microtime(true); + $this->assertEquals(15, $result); + $time = $timeEnd - $timeStart; + error_log('it_should_count_cases_by_user_with_self_service_user_assigned took [15]--->' . $time); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the USR_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [USR_UID] + * @covers ListUnassigned::doCount + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create a case + $application = factory(Application::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Create a task self service value based + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task[0]->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class, 1)->create([ + 'ID' => $appSelfValue[0]->ID, + 'GRP_UID' => $user[0]->USR_UID, + 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 10)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, + 'TAS_ID' => $task[0]->TAS_ID, + ]); + $timeStart = microtime(true); + $result = ListUnassigned::doCount($user[0]->USR_UID); + $this->assertEquals(10, $result); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + error_log('it_should_count_cases_by_user_with_self_service_value_based_usr_uid took [10]--->' . $time); + } + + /** + * This checks the counters is working properly in self-service and self-service value based + * @covers ListUnassigned::doCount + * @test + */ + public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create a case + $application = factory(Application::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in self service + factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + //Create a task self service value based + $task1 = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task1[0]->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class, 1)->create([ + 'ID' => $appSelfValue[0]->ID, + 'GRP_UID' => $user[0]->USR_UID, + 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self service value based + factory(ListUnassigned::class, 10)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, + 'TAS_ID' => $task[0]->TAS_ID, + ]); + + $timeStart = microtime(true); + $result = ListUnassigned::doCount($user[0]->USR_UID); + $timeEnd = microtime(true); + $this->assertEquals(25, $result); + $time = $timeEnd - $timeStart; + error_log('it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based took [25]--->' . $time); + } + + /** + * This checks the counters is working properly in self-service group assigned + * @covers ListUnassigned::doCount + * @test + */ + public function it_should_count_cases_by_user_with_self_service_group_assigned() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create group + $group = factory(Groupwf::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Assign a user in the group + factory(GroupUser::class, 1)->create([ + 'GRP_UID' => $group[0]->GRP_UID, + 'GRP_ID' => $group[0]->GRP_ID, + 'USR_UID' => $user[0]->USR_UID + ]); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + $timeStart = microtime(true); + $result = ListUnassigned::doCount($user[0]->USR_UID); + $timeEnd = microtime(true); + $this->assertEquals(15, $result); + $time = $timeEnd - $timeStart; + error_log('it_should_count_cases_by_user_with_self_service_group_assigned took [15]--->' . $time); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the GRP_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID] + * @covers ListUnassigned::doCount + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create a task self service value based + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Create a case + $application = factory(Application::class, 1)->create(); + //Create group + $group = factory(Groupwf::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Gary', + 'USR_FIRSTNAME' => 'Bailey', + ]); + //Assign a user in the group + factory(GroupUser::class, 1)->create([ + 'GRP_UID' => $group[0]->GRP_UID, + 'GRP_ID' => $group[0]->GRP_ID, + 'USR_UID' => $user[0]->USR_UID, + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'APP_UID' => $application[0]->APP_UID, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task[0]->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class, 1)->create([ + 'ID' => $appSelfValue[0]->ID, + 'GRP_UID' => $group[0]->GRP_UID, + 'ASSIGNEE_ID' => $group[0]->GRP_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 10)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task[0]->TAS_ID, + ]); + $timeStart = microtime(true); + $result = ListUnassigned::doCount($user[0]->USR_UID); + $this->assertEquals(10, $result); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + error_log('it_should_count_cases_by_user_with_self_service_value_based_grp_uid took [10]--->' . $time); + } + + /** + * This checks the counters is working properly in self-service user and group assigned in parallel task + * @covers ListUnassigned::doCount + * @test + */ + public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create group + $group = factory(Groupwf::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Assign a user in the group + factory(GroupUser::class, 1)->create([ + 'GRP_UID' => $group[0]->GRP_UID, + 'GRP_ID' => $group[0]->GRP_ID, + 'USR_UID' => $user[0]->USR_UID + ]); + //Create a task self service + $task1 = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task1 + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task1[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task2 = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task2 + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task2[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task3 = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task3[0]->TAS_UID, + 'USR_UID' => $group[0]->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task4 = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task4[0]->TAS_UID, + 'USR_UID' => $group[0]->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned related to the task1 + factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task1[0]->TAS_ID + ]); + //Create the register in list unassigned related to the task2 + factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task2[0]->TAS_ID + ]); + //Create the register in list unassigned related to the task3 + factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task3[0]->TAS_ID + ]); + //Create the register in list unassigned related to the task4 + factory(ListUnassigned::class, 15)->create([ + 'TAS_ID' => $task4[0]->TAS_ID + ]); + $timeStart = microtime(true); + $result = ListUnassigned::doCount($user[0]->USR_UID); + $timeEnd = microtime(true); + $this->assertEquals(60, $result); + $time = $timeEnd - $timeStart; + error_log('it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task took [60]--->' . $time); + } + + /** + * This checks the counters is working properly in self-service-value-based with GRP_UID and USR_UID in parallel task + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID, USR_UID] + * @covers ListUnassigned::doCount + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create a case + $application = factory(Application::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Create a task1 self service value based + $task1 = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'TAS_ID' => $task1[0]->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class, 1)->create([ + 'ID' => $appSelfValue[0]->ID, + 'GRP_UID' => $user[0]->USR_UID, + 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 10)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, + 'TAS_ID' => $task1[0]->TAS_ID, + ]); + //Create a task2 self service value based + $task2 = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'TAS_ID' => $task2[0]->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class, 1)->create([ + 'ID' => $appSelfValue[0]->ID, + 'GRP_UID' => $user[0]->USR_UID, + 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 10)->create([ + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, + 'TAS_ID' => $task2[0]->TAS_ID, + ]); + $timeStart = microtime(true); + $result = ListUnassigned::doCount($user[0]->USR_UID); + $this->assertEquals(20, $result); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + error_log('it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid took [20]--->' . $time); + } + + /** + * This checks to make sure pagination is working properly + * @covers ListUnassigned::loadList + * @test + */ + public function it_should_return_pages_of_data() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 51)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + //Define the filters + $filters = ['start' => 0, 'limit' => 25]; + //Get data first page + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(25, $result); + //Get data second page + $filters = ['start' => 25, 'limit' => 25]; + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(25, $result); + //Get data third page + $filters = ['start' => 50, 'limit' => 25]; + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(1, $result); + } + + /** + * This ensures ordering ascending and descending works by case number APP_NUMBER + * @covers ListUnassigned::loadList + * @test + */ + public function it_should_sort_by_case_number() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a case + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 3000 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + //Create a case + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2000 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_NUMBER' => $application[0]->APP_NUMBER + ]); + //Define the filters + $filters = ['sort' => 'APP_NUMBER', 'dir' => 'ASC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the minor case number first + $this->assertEquals(2000, $result[0]['APP_NUMBER']); + //Get the major case number second + $this->assertEquals(3000, $result[1]['APP_NUMBER']); + //Define the filters + $filters = ['sort' => 'APP_NUMBER', 'dir' => 'DESC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the major case number first + $this->assertEquals(3000, $result[0]['APP_NUMBER']); + //Get the minor case number second + $this->assertEquals(2000, $result[1]['APP_NUMBER']); + } + + /** + * This ensures ordering ascending and descending works by case number APP_TITLE + * @covers ListUnassigned::loadList + * @test + */ + public function it_should_sort_by_case_title() + { + //Create process + $process = factory(Process::class, 1)->create(); + //Create user + $user = factory(User::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a case + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 3001 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'APP_TITLE' => 'Request nro ' . $application[0]->APP_NUMBER, + ]); + //Create a case + $application = factory(Application::class, 1)->create([ + 'APP_NUMBER' => 2001 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_NUMBER' => $application[0]->APP_NUMBER, + 'APP_TITLE' => 'Request nro ' . $application[0]->APP_NUMBER, + ]); + //Define the filters + $filters = ['sort' => 'APP_TITLE', 'dir' => 'ASC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the minor case title first + $this->assertEquals('Request nro 2001', $result[0]['APP_TITLE']); + //Get the major case title second + $this->assertEquals('Request nro 3001', $result[1]['APP_TITLE']); + //Define the filters + $filters = ['sort' => 'APP_TITLE', 'dir' => 'DESC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the major case title first + $this->assertEquals('Request nro 3001', $result[0]['APP_TITLE']); + //Get the minor case title second + $this->assertEquals('Request nro 2001', $result[1]['APP_TITLE']); + } + + /** + * This ensures ordering ascending and descending works by case number APP_PRO_TITLE + * @covers ListUnassigned::loadList + * @test + */ + public function it_should_sort_by_process() + { + //Create user + $user = factory(User::class, 1)->create(); + //Create process + $process = factory(Process::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_PRO_TITLE' => 'Egypt Supplier Payment Proposal', + ]); + + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_PRO_TITLE' => 'Russia Supplier Payment Proposal', + ]); + //Define the filters + $filters = ['sort' => 'APP_PRO_TITLE', 'dir' => 'ASC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the minor process name first + $this->assertEquals('Egypt Supplier Payment Proposal', $result[0]['APP_PRO_TITLE']); + //Get the major process name second + $this->assertEquals('Russia Supplier Payment Proposal', $result[1]['APP_PRO_TITLE']); + //Define the filters + $filters = ['sort' => 'APP_PRO_TITLE', 'dir' => 'DESC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the major process name first + $this->assertEquals('Russia Supplier Payment Proposal', $result[0]['APP_PRO_TITLE']); + //Get the minor process name second + $this->assertEquals('Egypt Supplier Payment Proposal', $result[1]['APP_PRO_TITLE']); + } + + /** + * This ensures ordering ascending and descending works by case number APP_TAS_TITLE + * @covers ListUnassigned::loadList + * @test + */ + public function it_should_sort_by_task() + { + //Create user + $user = factory(User::class, 1)->create(); + //Create process + $process = factory(Process::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_TAS_TITLE' => 'Initiate Request', + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 1)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_TAS_TITLE' => 'Waiting for AP Manager Validation', + ]); + //Define the filters + $filters = ['sort' => 'APP_TAS_TITLE', 'dir' => 'ASC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the minor task name first + $this->assertEquals('Initiate Request', $result[0]['APP_TAS_TITLE']); + //Get the major task name second + $this->assertEquals('Waiting for AP Manager Validation', $result[1]['APP_TAS_TITLE']); + //Define the filters + $filters = ['sort' => 'APP_TAS_TITLE', 'dir' => 'DESC']; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the major task name first + $this->assertEquals('Waiting for AP Manager Validation', $result[0]['APP_TAS_TITLE']); + //Get the minor task namesecond + $this->assertEquals('Initiate Request', $result[1]['APP_TAS_TITLE']); + } + + /** + * This checks to make sure filter by category is working properly + * @covers ListUnassigned::loadList + * @test + */ + public function it_should_return_data_filtered_by_process_category() + { + //Create user + $user = factory(User::class, 1)->create(); + //Create a category + $category = factory(ProcessCategory::class, 1)->create(); + //Create process + $process = factory(Process::class, 1)->create([ + 'PRO_CATEGORY' => $category[0]->CATEGORY_UID + ]); + //Create a category + $category1 = factory(ProcessCategory::class, 1)->create(); + //Create process + $process1 = factory(Process::class, 1)->create([ + 'PRO_CATEGORY' => $category1[0]->CATEGORY_UID + ]); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 2)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'PRO_UID' => $process[0]->PRO_UID, + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 5)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'PRO_UID' => $process1[0]->PRO_UID, + ]); + //Get all data + $result = ListUnassigned::loadList($user[0]->USR_UID); + $this->assertCount(7, $result); + //Define the filters + $filters = ['category' => $category[0]->CATEGORY_UID]; + //Get data + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Get the minor case number first + $this->assertEquals($category[0]->CATEGORY_UID, $result[0]['PRO_CATEGORY']); + //Get the major case number second + $this->assertEquals($category[0]->CATEGORY_UID, $result[1]['PRO_CATEGORY']); + } + + /** + * This checks to make sure filter by category is working properly + * @covers ListUnassigned::loadList + * @test + */ + public function it_should_return_data_filtered_by_generic_search() + { + //Create user + $user = factory(User::class, 1)->create(); + //Create process + $process = factory(Process::class, 1)->create(); + //Create a task self service + $task = factory(Task::class, 1)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process[0]->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class, 1)->create([ + 'TAS_UID' => $task[0]->TAS_UID, + 'USR_UID' => $user[0]->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 2)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_TITLE' => 'This is a case name', + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 2)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_PRO_TITLE' => 'This is a process name', + ]); + //Create the register in list unassigned + factory(ListUnassigned::class, 2)->create([ + 'TAS_ID' => $task[0]->TAS_ID, + 'APP_TAS_TITLE' => 'This is a task name', + ]); + //Create other registers + factory(ListUnassigned::class, 4)->create([ + 'TAS_ID' => $task[0]->TAS_ID + ]); + //Define the filters + $filters = ['search' => 'case name']; + //Get data related to the search + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Define the filters + $filters = ['search' => 'process name']; + //Get data related to the search + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + //Define the filters + $filters = ['search' => 'task name']; + //Get data related to the search + $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $this->assertCount(2, $result); + } +} + diff --git a/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValue.php b/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValue.php new file mode 100644 index 000000000..f2cf56c94 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValue.php @@ -0,0 +1,14 @@ +belongsTo(Application::class, 'APP_UID', 'APP_UID'); + } + + /** + * Return the process task this belongs to + */ + public function task() + { + return $this->belongsTo(Task::class, 'TAS_ID', 'TAS_ID'); + } + + /** + * Return the process this belongs to + */ + public function process() + { + return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID'); + } + + /** + * Get count + * + * @param string $userUid + * @param array $filters + * + * @return array + */ + public static function doCount($userUid, $filters = []) + { + $list = new PropelListUnassigned(); + $result = $list->getCountList($userUid, $filters); + + return $result; + } + + /** + * Search data + * + * @param string $userUid + * @param array $filters + * + * @return array + */ + public static function loadList($userUid, $filters = []) + { + $list = new PropelListUnassigned(); + $result = $list->loadList($userUid, $filters); + + return $result; + } +} + diff --git a/workflow/engine/src/ProcessMaker/Model/Task.php b/workflow/engine/src/ProcessMaker/Model/Task.php index de66e26a0..89ab49222 100644 --- a/workflow/engine/src/ProcessMaker/Model/Task.php +++ b/workflow/engine/src/ProcessMaker/Model/Task.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Task extends Model { protected $table = 'TASK'; + protected $primaryKey = 'TAS_ID'; // We do not have create/update timestamps for this table public $timestamps = false;