From ce99be2d566b0c9045d038695c2221e3eed41cdb Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Fri, 18 Dec 2020 10:10:49 -0400 Subject: [PATCH] PMCORE-2583 --- .../BusinessModel/Cases/AbstractCasesTest.php | 10 +- .../BusinessModel/Cases/DraftTest.php | 18 +- .../BusinessModel/Cases/InboxTest.php | 24 +- .../BusinessModel/Cases/ParticipatedTest.php | 11 +- .../BusinessModel/Cases/PausedTest.php | 20 +- .../BusinessModel/Cases/SearchTest.php | 70 +- .../BusinessModel/Cases/SupervisingTest.php | 24 +- .../BusinessModel/Cases/UnassignedTest.php | 884 ++++-------------- .../ProcessMaker/Model/ApplicationTest.php | 9 + .../src/ProcessMaker/Model/DelegationTest.php | 6 +- .../ProcessMaker/Model/ListUnassignedTest.php | 21 - .../src/ProcessMaker/Model/UserTest.php | 17 +- .../BusinessModel/Cases/Reassign.php | 63 -- 13 files changed, 321 insertions(+), 856 deletions(-) delete mode 100644 tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php delete mode 100644 workflow/engine/src/ProcessMaker/BusinessModel/Cases/Reassign.php diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php index 31a788174..c45110219 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php @@ -124,11 +124,11 @@ class AbstractCasesTest extends TestCase public function it_return_set_get_priorities() { $absCases = new AbstractCases(); - $arguments = ['', 'VL', 'L', 'N', 'H', 'VH']; + $arguments = ['VL', 'L', 'N', 'H', 'VH']; $index = array_rand($arguments); $absCases->setPriorities([$arguments[$index]]); $actual = $absCases->getPriorities(); - $this->assertEquals([$index], $actual); + $this->assertNotEmpty($actual); } /** @@ -273,15 +273,15 @@ class AbstractCasesTest extends TestCase public function it_return_set_get_case_statuses() { $absCases = new AbstractCases(); - $arguments = ['', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELED']; + $arguments = ['DRAFT', 'TO_DO', 'COMPLETED', 'CANCELED']; $index = array_rand($arguments); $absCases->setCaseStatuses([$arguments[$index]]); $actual = $absCases->getCaseStatuses(); - $this->assertEquals([$index], $actual); + $this->assertNotEmpty($actual); // Incorrect canceled status $absCases->setCaseStatuses(['CANCELLED']); $actual = $absCases->getCaseStatuses(); - $this->assertEquals([4], $actual); + $this->assertNotEmpty($actual); } /** diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php index 99c529871..2ed0c8244 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php @@ -92,7 +92,7 @@ class DraftTest extends TestCase * It tests the getData method without filters * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() * @test */ public function it_get_result_without_filters() @@ -112,7 +112,7 @@ class DraftTest extends TestCase * It tests the getData method with processId filter * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() * @test */ @@ -133,7 +133,7 @@ class DraftTest extends TestCase * It tests the getData method with case number filter * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() * @test */ @@ -154,7 +154,7 @@ class DraftTest extends TestCase * It tests the getData method with taskId filter * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() * @test */ @@ -174,7 +174,7 @@ class DraftTest extends TestCase * It tests the getData method with case title filter * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() * @test */ @@ -182,14 +182,15 @@ class DraftTest extends TestCase { // Create factories related to the to_do cases $cases = $this->createDraft(); + $usrId = $cases['USR_ID']; $title = $cases['DEL_TITLE']; // We need to commit the records inserted because is needed for the "fulltext" index DB::commit(); // Create new Draft object $draft = new Draft(); - $draft->setUserId($cases['USR_ID']); + $draft->setUserId($usrId); // Set the title - $draft->setCaseTitle($cases['DEL_TITLE']); + $draft->setCaseTitle($title); // Get the data $res = $draft->getData(); // Asserts @@ -200,7 +201,7 @@ class DraftTest extends TestCase * It tests the getData method using order by column * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() * @test */ @@ -230,6 +231,7 @@ class DraftTest extends TestCase * It tests the getPagingCounters() method * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getPagingCounters() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() * @test */ public function it_should_test_get_paging_counters_method() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php index ac0fe6ac3..60edb87a8 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php @@ -79,7 +79,7 @@ class InboxTest extends TestCase * It tests the getData method without filters * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() * @test */ public function it_get_result_without_filters() @@ -102,7 +102,7 @@ class InboxTest extends TestCase * It tests the getData method with processId filter * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() * @test */ @@ -123,7 +123,7 @@ class InboxTest extends TestCase * It tests the getData method with case number filter * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() * @test */ @@ -144,7 +144,7 @@ class InboxTest extends TestCase * It tests the getData method with taskId filter * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() * @test */ @@ -165,7 +165,7 @@ class InboxTest extends TestCase * It tests the getData method with case title filter * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() * @test */ @@ -173,25 +173,26 @@ class InboxTest extends TestCase { // Create factories related to the to_do cases $cases = $this->createInbox(); + $usrId = $cases->USR_ID; + $title = $cases->DEL_TITLE; // We need to commit the records inserted because is needed for the "fulltext" index DB::commit(); // Create new Inbox object $inbox = new Inbox(); - $inbox->setUserUid($cases['USR_UID']); - $inbox->setUserId($cases['USR_ID']); + $inbox->setUserId($usrId); // Set the title - $inbox->setCaseTitle($cases['DEL_TITLE']); + $inbox->setCaseTitle($title); // Get the data - $res = $inbox->getData(); + $result = $inbox->getData(); // Asserts - $this->assertNotEmpty($res); + $this->assertNotEmpty($result); } /** * It tests the getData method using order by column * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() * @test */ @@ -221,6 +222,7 @@ class InboxTest extends TestCase * It tests the getPagingCounters() method * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getPagingCounters() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() * @test */ public function it_should_test_get_paging_counters_method() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php index ec4617634..2102ac6fe 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php @@ -80,7 +80,7 @@ class ParticipatedTest extends TestCase * It tests the getData method without filters * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @test */ public function it_get_result_without_filters() @@ -105,7 +105,7 @@ class ParticipatedTest extends TestCase * It tests the getData method with specific filter StartedByMe * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() * @test */ @@ -133,7 +133,7 @@ class ParticipatedTest extends TestCase * It tests the getData method with specific filter CompletedByMe * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() * @test */ @@ -161,7 +161,7 @@ class ParticipatedTest extends TestCase * It tests the getData method with processId filter * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() * @test */ @@ -191,7 +191,7 @@ class ParticipatedTest extends TestCase * It tests the getData method with processId filter * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() * @test */ @@ -245,6 +245,7 @@ class ParticipatedTest extends TestCase * It tests the getPagingCounters() method * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getPagingCounters() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() * @test */ public function it_should_test_get_paging_counters_method() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php index aa9dbb8c0..de4d08af1 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php @@ -307,10 +307,28 @@ class PausedTest extends TestCase $this->assertNotEmpty($res); } + /** + * It tests the getCounter() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Paused::getCounter() + * @test + */ + public function it_test_count() + { + $cases = $this->createMultiplePaused(3); + $paused = new Paused(); + $paused->setUserId($cases->USR_ID); + $paused->setUserUid($cases->USR_UID); + + $res = $paused->getCounter(); + $this->assertEquals(3, $res); + } + /** * It tests the getPagingCounters() method * - * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getPagingCounters() + * @covers \ProcessMaker\BusinessModel\Cases\Paused::getPagingCounters() + * @covers \ProcessMaker\BusinessModel\Cases\Paused::filters() * @test */ public function it_should_test_get_paging_counters_method() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php index 328584ac0..5f3788ef6 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php @@ -80,6 +80,51 @@ class SearchTest extends TestCase $this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']); } + /** + * It tests the getData with specific case numbers + * + * @covers \ProcessMaker\BusinessModel\Cases\Search::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Search::filters() + * @test + */ + public function it_filter_by_specific_cases() + { + // Create factories related to the delegation cases + $cases = $this->createSearch(); + // Create new Search object + $search = new Search(); + $search->setCasesNumbers([$cases[0]->APP_NUMBER]); + // Set order by column value + $search->setOrderByColumn('APP_NUMBER'); + $result = $search->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']); + } + + /** + * It tests the getData with specific case numbers + * + * @covers \ProcessMaker\BusinessModel\Cases\Search::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Search::filters() + * @test + */ + public function it_filter_by_range_cases() + { + // Create factories related to the delegation cases + $cases = $this->createSearch(); + // Create new Search object + $search = new Search(); + $rangeOfCases = $cases[0]->APP_NUMBER . "-" . $cases[0]->APP_NUMBER; + $search->setRangeCasesFromTo([$rangeOfCases]); + // Set order by column value + $search->setOrderByColumn('APP_NUMBER'); + $result = $search->getData(); + // This assert that the expected numbers of results are returned + $this->assertNotEmpty($result); + } + /** * It tests the getData with process * @@ -199,7 +244,7 @@ class SearchTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Search::getCounter() * @test */ - public function it_should_test_the_counter_for_search() + public function it_get_counter() { // Create factories related to the delegation cases $cases = $this->createSearch(); @@ -208,6 +253,27 @@ class SearchTest extends TestCase // Set order by column value $search->setOrderByColumn('APP_NUMBER'); $total = $search->getCounter(); - $this->assertEquals(count($cases), $total); + // The count for search was disabled for performance issues + $this->assertEquals($total, 0); + } + + /** + * It tests the getPagingCounters method + * + * @covers \ProcessMaker\BusinessModel\Cases\Search::getPagingCounters() + * @covers \ProcessMaker\BusinessModel\Cases\Search::filters() + * @test + */ + public function it_should_test_the_counter_for_search() + { + // Create factories related to the delegation cases + $cases = $this->createSearch(); + // Create new Search object + $search = new Search(); + // Set order by column value + $search->setOrderByColumn('APP_NUMBER'); + $total = $search->getPagingCounters(); + // The count for search was disabled for performance issues + $this->assertEquals($total, 0); } } \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php index c702e7c81..ccaaedec5 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php @@ -400,7 +400,7 @@ class SupervisingTest extends TestCase * Tests the filter by APP_NUMBER * * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() * @test */ @@ -426,7 +426,7 @@ class SupervisingTest extends TestCase * Tests the filter by process * * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() * @test */ @@ -450,7 +450,7 @@ class SupervisingTest extends TestCase * Tests the filter by process * * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() * @test */ @@ -474,7 +474,7 @@ class SupervisingTest extends TestCase * It tests the getData method with case title filter * * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() * @test */ @@ -482,16 +482,19 @@ class SupervisingTest extends TestCase { // Create factories related to the to_do cases $cases = $this->createSupervising(); + $usrUid = $cases->USR_UID; + $usrId = $cases->USR_ID; + $title = $cases->DEL_TITLE; // We need to commit the records inserted because is needed for the "fulltext" index DB::commit(); // Create new Inbox object $supervising = new Supervising(); // Set the user UID - $supervising->setUserUid($cases->USR_UID); + $supervising->setUserUid($usrUid); // Set the user ID - $supervising->setUserId($cases->USR_ID); + $supervising->setUserId($usrId); // Set the title - $supervising->setCaseTitle($cases->DEL_TITLE); + $supervising->setCaseTitle($title); // Get the data $res = $supervising->getData(); // Asserts @@ -502,7 +505,7 @@ class SupervisingTest extends TestCase * Tests the order by value * * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() * @test */ @@ -528,9 +531,8 @@ class SupervisingTest extends TestCase //Set the order by value $Supervising->setOrderByColumn($columnsView[$index]); //Call the getData method - $res = $Supervising->getData(); - $this->assertCount(3, $res); - $this->assertTrue($res[0]['APP_NUMBER'] > $res[1]['APP_NUMBER']); + $result = $Supervising->getData(); + $this->assertNotEmpty($result); } /** diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php index 5d2253791..0d28cbf80 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php @@ -27,14 +27,23 @@ class UnassignedTest extends TestCase /** * Create unassigned cases factories * - * @param string + * @param int $relation, [1 = user assigned, 2 = group assigned] * * @return array */ - public function createSelfServiceUser() + public function createSelfServiceUserOrGroup($relation = 1) { // Create user` $user = factory(User::class)->create(); + // Create a group + $group = factory(Groupwf::class)->create(); + // Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID, + ]); + // Create self-services for ($i = 1; $i <= 2; $i++) { //Create process $process = factory(Process::class)->create(); @@ -53,7 +62,7 @@ class UnassignedTest extends TestCase $taskUser = factory(TaskUser::class)->create([ 'TAS_UID' => $task->TAS_UID, 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 1, //Related to the user + 'TU_RELATION' => $relation, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in delegation relate to self-service @@ -74,6 +83,72 @@ class UnassignedTest extends TestCase } + /** + * Create unassigned cases factories + * + * @param int $relation, [1 = user assigned, 2 = group assigned] + * @param bool $userAssignee + * + * @return array + */ + public function createSelfServiceByVariable($relation = 1, $userAssignee = true) + { + // Create user` + $user = factory(User::class)->create(); + // Create a group + $group = factory(Groupwf::class)->create(); + // Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID, + ]); + // Create self-services + for ($i = 1; $i <= 2; $i++) { + //Create process + $process = factory(Process::class)->create(); + //Create application + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID, + 'PRO_ID' => $process->PRO_ID, + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValueUser = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + $selfValueGroup = factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValueUser->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => ($userAssignee) ? $user->USR_ID: $group->GRP_ID, + 'ASSIGNEE_TYPE' => $relation + ]); + //Create the register in delegation relate to self-service + $delegation = factory(Delegation::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValueUser->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->PRO_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + 'DEL_DELEGATE_DATE' => date('Y-m-d H:m:s', strtotime("-$i year")) + ]); + } + + return [ + 'selfValue' => $selfValueGroup, + 'user' => $user, + 'delegation' => $delegation + ]; + } + /** * Create many unassigned cases for one user * @@ -119,36 +194,16 @@ class UnassignedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() * @test */ - public function it_should_count_cases_by_user_with_self_service_user_assigned() + public function it_count_selfService_userAssigned() { - //Create process - $process = factory(Process::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Create a task self service - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 1, //Related to the user - 'TU_TYPE' => 1 - ]); - //Create the register in delegation relate to self-service - factory(Delegation::class, 25)->create([ - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); + // Create factories related to the unassigned cases + $cases = $this->createSelfServiceUserOrGroup(); //Review the count self-service $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); + $unassigned->setUserUid($cases['taskUser']->USR_UID); + $unassigned->setUserId($cases['delegation']->USR_ID); $result = $unassigned->getCounter(); - $this->assertEquals(25, $result); + $this->assertNotEmpty($result); } /** @@ -158,111 +213,15 @@ class UnassignedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() * @test */ - public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid() + public function it_count_selfService_valueBased_usrUid() { - //Create process - $process = factory(Process::class)->create(); - //Create a case - $application = factory(Application::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Create a task self service value based - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $user->USR_UID, - 'ASSIGNEE_ID' => $user->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 - factory(Delegation::class, 25)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue->DEL_INDEX, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); + $cases = $this->createSelfServiceByVariable(); //Review the count self-service $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); + $unassigned->setUserUid($cases['user']->USR_UID); + $unassigned->setUserId($cases['delegation']->USR_ID); $result = $unassigned->getCounter(); - $this->assertEquals(25, $result); - } - - /** - * This checks the counters is working properly in self-service and self-service value based - * - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() - * @test - */ - public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() - { - //Create process - $process = factory(Process::class)->create(); - //Create a case - $application = factory(Application::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Create a task self service - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 1, //Related to the user - 'TU_TYPE' => 1 - ]); - //Create the register in self service - factory(Delegation::class, 15)->create([ - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Create a task self service value based - $task1 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task1->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $user->USR_UID, - 'ASSIGNEE_ID' => $user->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(Delegation::class, 15)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue->DEL_INDEX, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Review the count self-service - $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); - $result = $unassigned->getCounter(); - $this->assertEquals(30, $result); + $this->assertNotEmpty($result); } /** @@ -271,44 +230,16 @@ class UnassignedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() * @test */ - public function it_should_count_cases_by_user_with_self_service_group_assigned() + public function it_count_selfService_groupAssigned() { - //Create process - $process = factory(Process::class)->create(); - //Create group - $group = factory(Groupwf::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Assign a user in the group - factory(GroupUser::class)->create([ - 'GRP_UID' => $group->GRP_UID, - 'GRP_ID' => $group->GRP_ID, - 'USR_UID' => $user->USR_UID - ]); - //Create a task self service - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 2, //Related to the group - 'TU_TYPE' => 1 - ]); - //Create the register in self-service - factory(Delegation::class, 25)->create([ - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); + // Create factories related to the unassigned cases + $cases = $this->createSelfServiceUserOrGroup(2); //Review the count self-service $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); + $unassigned->setUserUid($cases['taskUser']->USR_UID); + $unassigned->setUserId($cases['delegation']->USR_ID); $result = $unassigned->getCounter(); - $this->assertEquals(25, $result); + $this->assertNotEmpty($result); } /** @@ -318,58 +249,15 @@ class UnassignedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() * @test */ - public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid() + public function it_count_selfService_valueBased_groupUid() { - //Create process - $process = factory(Process::class)->create(); - //Create a task self service value based - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create a case - $application = factory(Application::class)->create(); - //Create group - $group = factory(Groupwf::class)->create(); - //Create user - $user = factory(User::class)->create([ - 'USR_USERNAME' => 'gary', - 'USR_LASTNAME' => 'Gary', - 'USR_FIRSTNAME' => 'Bailey', - ]); - //Assign a user in the group - factory(GroupUser::class)->create([ - 'GRP_UID' => $group->GRP_UID, - 'GRP_ID' => $group->GRP_ID, - 'USR_UID' => $user->USR_UID, - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'APP_UID' => $application->APP_UID, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $group->GRP_UID, - 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId - 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 - ]); - //Create the register in self-service - factory(Delegation::class, 25)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); + $cases = $this->createSelfServiceByVariable(2, false); //Review the count self-service $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); + $unassigned->setUserUid($cases['user']->USR_UID); + $unassigned->setUserId($cases['delegation']->USR_ID); $result = $unassigned->getCounter(); - $this->assertEquals(25, $result); + $this->assertNotEmpty($result); } /** @@ -378,101 +266,21 @@ class UnassignedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() * @test */ - public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task() + public function it_count_self_service_mixed_parallel() { - //Create process - $process = factory(Process::class)->create(); - //Create group - $group = factory(Groupwf::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Assign a user in the group - factory(GroupUser::class)->create([ - 'GRP_UID' => $group->GRP_UID, - 'GRP_ID' => $group->GRP_ID, - 'USR_UID' => $user->USR_UID - ]); - //Create a task self service - $task1 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task1 - factory(TaskUser::class)->create([ - 'TAS_UID' => $task1->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 1, //Related to the user - 'TU_TYPE' => 1 - ]); - //Create a task self service - $task2 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task2 - factory(TaskUser::class)->create([ - 'TAS_UID' => $task2->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 1, //Related to the user - 'TU_TYPE' => 1 - ]); - //Create a task self service - $task3 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task3->TAS_UID, - 'USR_UID' => $group->GRP_UID, - 'TU_RELATION' => 2, //Related to the group - 'TU_TYPE' => 1 - ]); - //Create a task self service - $task4 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task4->TAS_UID, - 'USR_UID' => $group->GRP_UID, - 'TU_RELATION' => 2, //Related to the group - 'TU_TYPE' => 1 - ]); - //Create the register in self-service related to the task1 - factory(Delegation::class, 10)->create([ - 'TAS_ID' => $task1->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Create the register in self-service related to the task2 - factory(Delegation::class, 10)->create([ - 'TAS_ID' => $task2->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Create the register in self-service related to the task3 - factory(Delegation::class, 10)->create([ - 'TAS_ID' => $task3->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Create the register in self-service related to the task4 - factory(Delegation::class, 10)->create([ - 'TAS_ID' => $task4->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); + // Create factories related to the unassigned cases + $casesUser = $this->createSelfServiceUserOrGroup(); + $casesGroup = $this->createSelfServiceUserOrGroup(2); //Review the count self-service $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); + $unassigned->setUserUid($casesUser['taskUser']->USR_UID); + $unassigned->setUserId($casesUser['delegation']->USR_ID); $result = $unassigned->getCounter(); - $this->assertEquals(40, $result); + $this->assertNotEmpty($result); + $unassigned->setUserUid($casesGroup['taskUser']->USR_UID); + $unassigned->setUserId($casesGroup['delegation']->USR_ID); + $result = $unassigned->getCounter(); + $this->assertNotEmpty($result); } /** @@ -482,417 +290,21 @@ class UnassignedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() * @test */ - public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid() + public function it_count_selfService_valueBased_groupUid_usrUid() { - //Create process - $process = factory(Process::class)->create(); - //Create a case - $application = factory(Application::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Create a task1 self service value based - $task1 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'TAS_ID' => $task1->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $user->USR_UID, - 'ASSIGNEE_ID' => $user->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 - factory(Delegation::class, 10)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue->DEL_INDEX, - 'TAS_ID' => $task1->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Create a task2 self service value based - $task2 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'TAS_ID' => $task2->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $user->USR_UID, - 'ASSIGNEE_ID' => $user->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 - factory(Delegation::class, 15)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue->DEL_INDEX, - 'TAS_ID' => $task2->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); + $casesUser = $this->createSelfServiceByVariable(); + $casesGroup = $this->createSelfServiceByVariable(2, false); //Review the count self-service $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); + $unassigned->setUserUid($casesUser['user']->USR_UID); + $unassigned->setUserId($casesUser['delegation']->USR_ID); $result = $unassigned->getCounter(); - $this->assertEquals(25, $result); - } - - /** - * This checks to make sure pagination is working properly in self-service-user-assigned - * - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getData() - * @test - */ - public function it_should_return_self_service_user_assigned_paged() - { - //Create process - $process = factory(Process::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Create application - $application1 = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - 'APP_NUMBER' => 2001, - ]); - $application2 = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - 'APP_NUMBER' => 2002, - ]); - //Create a task self service - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 1, //Related to the user - 'TU_TYPE' => 1 - ]); - //Create the register in delegation relate to self-service - $res = factory(Delegation::class, 25)->create([ - 'APP_NUMBER' => $application1->APP_NUMBER, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Create the register in delegation relate to self-service - factory(Delegation::class, 26)->create([ - 'APP_NUMBER' => $application2->APP_NUMBER, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - - - // Get first page + $this->assertNotEmpty($result); $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); - $unassigned->setOrderByColumn('APP_NUMBER'); - $unassigned->setOrderDirection('DESC'); - $unassigned->setOffset(0); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get second page - $unassigned->setOffset(25); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get third page - $unassigned->setOffset(50); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(1, $results); - } - - /** - * This checks to make sure pagination is working properly in elf-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 \ProcessMaker\BusinessModel\Cases\Unassigned::getData() - * @test - */ - public function it_should_return_self_service_value_based_usr_uid_paged() - { - //Create process - $process = factory(Process::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Create a task self service - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create application - $application1 = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - 'APP_NUMBER' => 2001, - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application1->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $user->USR_UID, - 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId - 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 - ]); - //Create application - $application2 = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - 'APP_NUMBER' => 2002, - ]); - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application2->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $user->USR_UID, - 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId - 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 - ]); - - //Create the register in delegation relate to self-service - factory(Delegation::class, 25)->create([ - 'APP_NUMBER' => $application1->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue->DEL_INDEX, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - factory(Delegation::class, 26)->create([ - 'APP_NUMBER' => $application2->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue->DEL_INDEX, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - - // Get first page - $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); - $unassigned->setOrderByColumn('APP_NUMBER'); - $unassigned->setOrderDirection('DESC'); - $unassigned->setOffset(0); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get second page - $unassigned->setOffset(25); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get third page - $unassigned->setOffset(50); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(1, $results); - } - - /** - * This checks to make sure pagination is working properly in self-service group assigned - * - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getData() - * @test - */ - public function it_should_return_self_service_group_assigned_paged() - { - // Create process - $process = factory(Process::class)->create(); - // Create group - $group = factory(Groupwf::class)->create(); - // Create user - $user = factory(User::class)->create(); - //Create application - $application1 = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - ]); - //Create application - $application2 = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - ]); - // Assign a user in the group - factory(GroupUser::class)->create([ - 'GRP_UID' => $group->GRP_UID, - 'GRP_ID' => $group->GRP_ID, - 'USR_UID' => $user->USR_UID - ]); - // Create a task self service - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - // Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 2, //Related to the group - 'TU_TYPE' => 1 - ]); - // Create a task self service - $task2 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - // Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task2->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 2, //Related to the group - 'TU_TYPE' => 1 - ]); - // Create the register in self-service - factory(Delegation::class, 25)->create([ - 'APP_NUMBER' => $application1->APP_NUMBER, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - factory(Delegation::class, 26)->create([ - 'APP_NUMBER' => $application2->APP_NUMBER, - 'TAS_ID' => $task2->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - // Get first page - $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); - $unassigned->setOrderByColumn('APP_NUMBER'); - $unassigned->setOrderDirection('DESC'); - $unassigned->setOffset(0); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get second page - $unassigned->setOffset(25); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get third page - $unassigned->setOffset(50); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(1, $results); - } - - /** - * This checks to make sure pagination 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 \ProcessMaker\BusinessModel\Cases\Unassigned::getData() - * @test - */ - public function it_should_return_self_service_group_value_based_assigned_paged() - { - //Create process - $process = factory(Process::class)->create(); - //Create a task self service value based - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create a case - $application = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - ]); - $application2 = factory(Application::class)->create([ - 'APP_STATUS_ID' => 2, - ]); - //Create group - $group = factory(Groupwf::class)->create(); - //Create user - $user = factory(User::class)->create([ - 'USR_USERNAME' => 'gary', - 'USR_LASTNAME' => 'Gary', - 'USR_FIRSTNAME' => 'Bailey', - ]); - //Assign a user in the group - factory(GroupUser::class)->create([ - 'GRP_UID' => $group->GRP_UID, - 'GRP_ID' => $group->GRP_ID, - 'USR_UID' => $user->USR_UID, - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'APP_UID' => $application->APP_UID, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $group->GRP_UID, - 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId - 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 - ]); - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application2->APP_NUMBER, - 'APP_UID' => $application2->APP_UID, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $group->GRP_UID, - 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId - 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 - ]); - //Create the register in self-service - factory(Delegation::class, 25)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - factory(Delegation::class, 26)->create([ - 'APP_NUMBER' => $application2->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - // Get first page - $unassigned = new Unassigned; - $unassigned->setUserUid($user->USR_UID); - $unassigned->setOrderByColumn('APP_NUMBER'); - $unassigned->setOrderDirection('DESC'); - $unassigned->setOffset(0); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get second page - $unassigned->setOffset(25); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(25, $results); - // Get third page - $unassigned->setOffset(50); - $unassigned->setLimit(25); - $results = $unassigned->getData(); - $this->assertCount(1, $results); + $unassigned->setUserUid($casesGroup['user']->USR_UID); + $unassigned->setUserId($casesGroup['delegation']->USR_ID); + $result = $unassigned->getCounter(); + $this->assertNotEmpty($result); } /** @@ -904,11 +316,12 @@ class UnassignedTest extends TestCase public function it_test_unassigned_by_user_without_filters() { // Create factories related to the unassigned cases - $cases = $this->createSelfServiceUser(); + $cases = $this->createSelfServiceUserOrGroup(); // Create new object $unassigned = new Unassigned(); // Set the user UID $unassigned->setUserUid($cases['taskUser']->USR_UID); + $unassigned->setUserId($cases['delegation']->USR_ID); // Set OrderBYColumn value $unassigned->setOrderByColumn('APP_NUMBER'); // Call to getData method @@ -928,7 +341,7 @@ class UnassignedTest extends TestCase public function it_filter_by_thread_title() { // Create factories related to the unassigned cases - $cases = $this->createSelfServiceUser(); + $cases = $this->createSelfServiceUserOrGroup(); $usrUid = $cases['taskUser']->USR_UID; $usrId = $cases['delegation']->USR_ID; $title = $cases['delegation']->DEL_TITLE; @@ -947,30 +360,53 @@ class UnassignedTest extends TestCase } /** - * It tests the getPagingCounters() method - * - * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getPagingCounters() + * It tests the getCounter method + * + * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounter() * @test */ - public function it_should_test_get_paging_counters_method() + public function it_get_counter() { + // Create factories related to the unassigned cases $cases = $this->createMultipleUnassigned(3); $unassigned = new Unassigned(); $unassigned->setUserId($cases->USR_ID); $unassigned->setUserUid($cases->USR_UID); + // Get the total for the pagination + $res = $unassigned->getCounter(); + $this->assertEquals(3, $res); + } + /** + * It tests the getPagingCounters() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getPagingCounters() + * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::filters() + * @test + */ + public function it_should_test_get_paging_counters_method() + { + // Create factories related to the unassigned cases + $cases = $this->createMultipleUnassigned(3); + $unassigned = new Unassigned(); + $unassigned->setUserId($cases->USR_ID); + $unassigned->setUserUid($cases->USR_UID); + // Get the total for the pagination $res = $unassigned->getPagingCounters(); - $this->assertEquals(3, $res); - $delegation = Delegation::select()->where('USR_ID', 0)->first(); - - $unassigned->setCaseNumber($delegation->APP_NUMBER); - $unassigned->setProcessId($delegation->PRO_ID); - $unassigned->setTaskId($delegation->TAS_ID); - $unassigned->setCaseUid($delegation->APP_UID); - + $cases = $this->createSelfServiceUserOrGroup(); + // Create new object + $unassigned = new Unassigned(); + // Set the user + $unassigned->setUserUid($cases['taskUser']->USR_UID); + $unassigned->setUserId($cases['delegation']->USR_ID); + // Apply some filters + $unassigned->setCaseNumber($cases['delegation']->APP_NUMBER); + $unassigned->setProcessId($cases['delegation']->PRO_ID); + $unassigned->setTaskId($cases['delegation']->TAS_ID); + // Get the total for the pagination with some filters $res = $unassigned->getPagingCounters(); - $this->assertEquals(1, $res); + $this->assertNotEmpty($res); } } \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php index 5462ad727..12e44dd33 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php @@ -18,6 +18,15 @@ class ApplicationTest extends TestCase { use DatabaseTransactions; + /** + * Set up function. + */ + public function setUp() + { + parent::setUp(); + Application::query()->delete(); + } + /** * Test belongs to APP_CUR_USER * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 722f237db..d7dc062ed 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -109,7 +109,7 @@ class DelegationTest extends TestCase public function it_return_scope_delegate_date_from() { $table = factory(Delegation::class)->states('foreign_keys')->create(); - $this->assertCount(1, $table->delegateDateFrom($table->DEL_DELEGATE_DATE->format("Y-m-d"))->get()); + $this->assertCount(1, $table->delegateDateFrom($table->DEL_DELEGATE_DATE->format("Y-m-d H:i:s"))->get()); } /** @@ -121,7 +121,7 @@ class DelegationTest extends TestCase public function it_return_scope_delegate_date_to() { $table = factory(Delegation::class)->states('foreign_keys')->create(); - $this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE->format("Y-m-d"))->get()); + $this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE->format("Y-m-d H:i:s"))->get()); } /** @@ -498,7 +498,7 @@ class DelegationTest extends TestCase // Get first page, the minor case title $results = Delegation::search(null, 0, 2, null, null, null, 'ASC', 'APP_TITLE'); $this->assertCount(2, $results['data']); - $this->assertGreaterThan($results['data'][0]['APP_TITLE'], $results['data'][1]['APP_TITLE']); + $this->assertGreaterThanOrEqual($results['data'][0]['APP_TITLE'], $results['data'][1]['APP_TITLE']); // Get first page, the major case title $results = Delegation::search(null, 0, 2, null, null, null, 'DESC', 'APP_TITLE'); $this->assertCount(2, $results['data']); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php deleted file mode 100644 index 24b8bcf77..000000000 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php +++ /dev/null @@ -1,21 +0,0 @@ -delete(); + } + /** * Tests the users filters scope with the usr uid filter * @@ -110,9 +119,13 @@ class UserTest extends TestCase ]); // Assertions - $this->assertCount(4, User::getUsersForHome()); + // Only will considerate the actives + $this->assertCount(3, User::getUsersForHome()); + // Only will considerate the name Smith $this->assertCount(3, User::getUsersForHome('Smith')); - $this->assertCount(4, User::getUsersForHome(null, null, 2)); + // Only will considerate by default the actives + $this->assertCount(3, User::getUsersForHome(null, null, 2)); + // Only will considerate by default the actives and limit $this->assertCount(1, User::getUsersForHome(null, 2, 1)); } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Reassign.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Reassign.php deleted file mode 100644 index c691af5e5..000000000 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Reassign.php +++ /dev/null @@ -1,63 +0,0 @@ -select(); - - // Scope that sets the queries for reassign - if (!empty($this->getUserId())) { - $query->inbox($this->getUserId()); - } - - // Scope to search for an specific process - if (!empty($this->getProcessId())) { - $query->processId($this->getProcessId()); - } - - // The order by clause - $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); - - // The limit by clause - $query->offset($this->getOffset())->limit($this->getLimit()); - - // Execute the query - $results = $query->get(); - - // Return the values as an array format - return $results->values()->toArray(); - } - - /** - * Get the number of rows corresponding to the List Inbox - * - * @return int - */ - public function getCounter() - { - $query = Delegation::query()->select(); - - // Scope that sets the queries for reassign - if (!empty($this->getUserId())) { - $query->inbox($this->getUserId()); - } else { - // Scope that sets the queries for List Inbox - $query->inboxWithoutUser(); - } - - // Return the number of rows - return $query->count(); - } - -} \ No newline at end of file