From 293cbe4dede025f4f8e0e3a2862dec903cacd1b1 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Mon, 14 Dec 2020 15:24:08 -0400 Subject: [PATCH] PMCORE-2543 --- .../BusinessModel/Cases/DraftTest.php | 86 ++++++-- .../BusinessModel/Cases/InboxTest.php | 53 ++++- .../BusinessModel/Cases/ParticipatedTest.php | 73 +++++- .../BusinessModel/Cases/PausedTest.php | 88 ++++++++ .../BusinessModel/Cases/SupervisingTest.php | 207 ++++++++++++++++-- .../BusinessModel/Cases/UnassignedTest.php | 67 ++++++ .../BusinessModel/Cases/AbstractCases.php | 10 + .../BusinessModel/Cases/Draft.php | 21 +- .../BusinessModel/Cases/Inbox.php | 22 +- .../BusinessModel/Cases/Participated.php | 41 +++- .../BusinessModel/Cases/Paused.php | 20 +- .../BusinessModel/Cases/Search.php | 17 +- .../BusinessModel/Cases/Supervising.php | 23 +- .../BusinessModel/Cases/Unassigned.php | 21 +- .../src/ProcessMaker/Services/Api/Home.php | 12 +- 15 files changed, 696 insertions(+), 65 deletions(-) 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 1e8a25e1a..99c529871 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php @@ -22,7 +22,6 @@ class DraftTest extends TestCase public function setUp() { parent::setUp(); - $this->markTestIncomplete(); } /** @@ -45,6 +44,33 @@ class DraftTest extends TestCase return $delegation; } + /** + * Create many draft cases for one user + * + * @param int + * @return object + */ + public function createManyDraft($cases) + { + $user = factory(\ProcessMaker\Model\User::class)->create(); + + for ($i = 0; $i < $cases; $i = $i + 1) { + $application = factory(Application::class)->states('draft')->create([ + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 1, + 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER, + 'USR_ID' => $user->USR_ID + ]); + } + + return $user; + } + /** * This checks the counters is working properly in draft * @@ -57,7 +83,7 @@ class DraftTest extends TestCase $cases = $this->createDraft(); // Create new Draft object $draft = new Draft(); - $draft->setUserId($cases->USR_ID); + $draft->setUserId($cases['USR_ID']); $result = $draft->getCounter(); $this->assertTrue($result > 0); } @@ -74,9 +100,9 @@ class DraftTest extends TestCase // Create factories related to the draft cases $cases = $this->createDraft(); // Create new Draft object - $draft = new Inbox(); + $draft = new Draft(); // Set the user ID - $draft->setUserId($cases->USR_ID); + $draft->setUserId($cases['USR_ID']); $draft->setOrderByColumn('APP_NUMBER'); $res = $draft->getData(); $this->assertNotEmpty($res); @@ -96,8 +122,8 @@ class DraftTest extends TestCase $cases = $this->createDraft(); // Create new Draft object $draft = new Draft(); - $draft->setUserId($cases->USR_ID); - $draft->setProcessId($cases->PRO_ID); + $draft->setUserId($cases['USR_ID']); + $draft->setProcessId($cases['PRO_ID']); $draft->setOrderByColumn('APP_NUMBER'); $res = $draft->getData(); $this->assertNotEmpty($res); @@ -117,8 +143,8 @@ class DraftTest extends TestCase $cases = $this->createDraft(); // Create new Draft object $draft = new Draft(); - $draft->setUserId($cases->USR_ID); - $draft->setCaseNumber($cases->APP_NUMBER); + $draft->setUserId($cases['USR_ID']); + $draft->setCaseNumber($cases['APP_NUMBER']); $draft->setOrderByColumn('APP_NUMBER'); $res = $draft->getData(); $this->assertNotEmpty($res); @@ -138,11 +164,10 @@ class DraftTest extends TestCase $cases = $this->createDraft(); // Create new Draft object $draft = new Draft(); - $draft->setUserId($cases->USR_ID); - $draft->setTaskId($cases->TAS_ID); + $draft->setUserId($cases['USR_ID']); + $draft->setTaskId($cases['TAS_ID']); $res = $draft->getData(); $this->assertNotEmpty($res); - } /** @@ -157,14 +182,14 @@ class DraftTest extends TestCase { // Create factories related to the to_do cases $cases = $this->createDraft(); - $title = $cases->last()->DEL_TITLE; + $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($cases['USR_ID']); // Set the title - $draft->setCaseTitle($cases->DEL_TITLE); + $draft->setCaseTitle($cases['DEL_TITLE']); // Get the data $res = $draft->getData(); // Asserts @@ -194,10 +219,39 @@ class DraftTest extends TestCase $index = array_rand($columnsView); // Create new Inbox object $draft = new Draft(); - $draft->setUserId($cases->USR_ID); + $draft->setUserId($cases['USR_ID']); // Define the column to order $draft->setOrderByColumn($columnsView[$index]); $res = $draft->getData(); $this->assertNotEmpty($res); } -} \ No newline at end of file + + /** + * It tests the getPagingCounters() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getPagingCounters() + * @test + */ + public function it_should_test_get_paging_counters_method() + { + $cases = $this->createManyDraft(3); + + $draft = new Draft(); + $draft->setUserId($cases->USR_ID); + $draft->setUserUid($cases->USR_UID); + + $res = $draft->getPagingCounters(); + $this->assertEquals(3, $res); + + $delegation = Delegation::select()->where('USR_ID', $cases->USR_ID)->first(); + + $draft->setCaseNumber($delegation->APP_NUMBER); + $draft->setProcessId($delegation->PRO_ID); + $draft->setTaskId($delegation->TAS_ID); + $draft->setCaseUid($delegation->APP_UID); + + $res = $draft->getPagingCounters(); + + $this->assertEquals(1, $res); + } +} 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 412b618e0..ac0fe6ac3 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php @@ -37,6 +37,27 @@ class InboxTest extends TestCase return $delegation; } + /** + * Create many inbox cases for one user + * + * @param int + * @return object + */ + public function createMultipleInbox($cases) + { + $user = factory(\ProcessMaker\Model\User::class)->create(); + + for ($i = 0; $i < $cases; $i = $i + 1) { + factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 2, + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + ]); + } + return $user; + } + /** * It tests the getCounter method * @@ -156,9 +177,10 @@ class InboxTest extends TestCase DB::commit(); // Create new Inbox object $inbox = new Inbox(); - $inbox->setUserId($cases->USR_ID); + $inbox->setUserUid($cases['USR_UID']); + $inbox->setUserId($cases['USR_ID']); // Set the title - $inbox->setCaseTitle($cases->DEL_TITLE); + $inbox->setCaseTitle($cases['DEL_TITLE']); // Get the data $res = $inbox->getData(); // Asserts @@ -194,4 +216,31 @@ class InboxTest extends TestCase $res = $inbox->getData(); $this->assertNotEmpty($res); } + + /** + * It tests the getPagingCounters() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getPagingCounters() + * @test + */ + public function it_should_test_get_paging_counters_method() + { + $cases = $this->createMultipleInbox(3); + $inbox = new Inbox(); + $inbox->setUserId($cases->USR_ID); + $inbox->setUserUid($cases->USR_UID); + + $res = $inbox->getPagingCounters(); + $this->assertEquals(3, $res); + + $delegation = Delegation::select()->where('USR_ID', $cases->USR_ID)->first(); + + $inbox->setCaseNumber($delegation->APP_NUMBER); + $inbox->setProcessId($delegation->PRO_ID); + $inbox->setTaskId($delegation->TAS_ID); + $inbox->setCaseUid($delegation->APP_UID); + + $res = $inbox->getPagingCounters(); + $this->assertEquals(1, $res); + } } \ No newline at end of file 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 5f4c68ad2..ec4617634 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php @@ -45,6 +45,37 @@ class ParticipatedTest extends TestCase return $delegation2; } + /** + * Create many participated cases for one user + * + * @param int + * @return object + */ + public function createMultipleParticipated($cases) + { + $user = factory(\ProcessMaker\Model\User::class)->create(); + + for ($i = 0; $i < $cases; $i = $i + 1) { + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'CLOSED', + 'DEL_INDEX' => 1, + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + ]); + factory(Delegation::class)->states('last_thread')->create([ + 'APP_UID' => $delegation->APP_UID, + 'APP_NUMBER' => $delegation->APP_NUMBER, + 'TAS_ID' => $delegation->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $delegation->USR_UID, + 'USR_ID' => $delegation->USR_ID, + 'PRO_ID' => $delegation->PRO_ID, + 'DEL_INDEX' => 2, + ]); + } + return $user; + } + /** * It tests the getData method without filters * @@ -59,15 +90,15 @@ class ParticipatedTest extends TestCase // Create new Participated object $participated = new Participated(); // Set the user UID - $participated->setUserUid($cases->USR_UID); + $participated->setUserUid($cases['USR_UID']); // Set the user ID - $participated->setUserId($cases->USR_ID); + $participated->setUserId($cases['USR_ID']); // Set OrderBYColumn value $participated->setOrderByColumn('APP_NUMBER'); // Call to getData method $res = $participated->getData(); // This assert that the expected numbers of results are returned - $this->assertEquals(1, count($res)); + $this->assertEquals(2, count($res)); } /** @@ -143,17 +174,17 @@ class ParticipatedTest extends TestCase // Set the filter $participated->setFilterCases('STARTED'); // Set the user UID - $participated->setUserUid($cases->USR_UID); + $participated->setUserUid($cases['USR_UID']); // Set the user ID - $participated->setUserId($cases->USR_ID); + $participated->setUserId($cases['USR_ID']); // Set the process ID - $participated->setProcessId($cases->PRO_ID); + $participated->setProcessId($cases['PRO_ID']); // Set OrderBYColumn value $participated->setOrderByColumn('APP_NUMBER'); // Call to getData method $res = $participated->getData(); // This assert that the expected numbers of results are returned - $this->assertEquals(1, count($res)); + $this->assertEquals(2, count($res)); } /** @@ -209,4 +240,32 @@ class ParticipatedTest extends TestCase // Assert the result of getCounter method $this->assertEquals(1, $res); } + + /** + * It tests the getPagingCounters() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getPagingCounters() + * @test + */ + public function it_should_test_get_paging_counters_method() + { + $cases = $this->createMultipleParticipated(3); + $participated = new Participated(); + $participated->setUserId($cases->USR_ID); + $participated->setUserUid($cases->USR_UID); + $participated->setParticipatedStatus('STARTED'); + + $res = $participated->getPagingCounters(); + $this->assertEquals(3, $res); + + $delegation = Delegation::select()->where('USR_ID', $cases->USR_ID)->first(); + + $participated->setCaseNumber($delegation->APP_NUMBER); + $participated->setProcessId($delegation->PRO_ID); + $participated->setTaskId($delegation->TAS_ID); + $participated->setCaseUid($delegation->APP_UID); + + $res = $participated->getPagingCounters(); + $this->assertEquals(1, $res); + } } \ No newline at end of file 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 88efb0b12..aa9dbb8c0 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php @@ -122,6 +122,67 @@ class PausedTest extends TestCase return $delegation2; } + /** + * Create many paused cases for one user + * + * @param int + * @return object + */ + public function createMultiplePaused($cases) + { + $user = factory(\ProcessMaker\Model\User::class)->create(); + + for ($i = 0; $i < $cases; $i = $i + 1) { + $process1 = factory(Process::class)->create( + ['PRO_CATEGORY' => '1'] + ); + + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process1->PRO_UID, + 'TAS_TYPE' => 'NORMAL' + ]); + + $application1 = factory(Application::class)->create(); + + factory(Delegation::class)->create([ + 'APP_UID' => $application1->APP_UID, + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process1->PRO_ID, + 'PRO_UID' => $process1->PRO_UID, + 'DEL_PREVIOUS' => 0, + 'DEL_INDEX' => 1 + ]); + $delegation1 = factory(Delegation::class)->create([ + 'APP_UID' => $application1->APP_UID, + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process1->PRO_ID, + 'PRO_UID' => $process1->PRO_UID, + 'DEL_PREVIOUS' => 1, + 'DEL_INDEX' => 2 + ]); + + factory(AppDelay::class)->create([ + 'APP_DELEGATION_USER' => $user->USR_UID, + 'PRO_UID' => $process1->PRO_UID, + 'APP_NUMBER' => $delegation1->APP_NUMBER, + 'APP_DEL_INDEX' => $delegation1->DEL_INDEX, + 'APP_DISABLE_ACTION_USER' => 0, + 'APP_TYPE' => 'PAUSE' + ]); + } + return $user; + } + /** * It tests the getData method without filters * @@ -245,4 +306,31 @@ class PausedTest extends TestCase $res = $paused->getData(); $this->assertNotEmpty($res); } + + /** + * It tests the getPagingCounters() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getPagingCounters() + * @test + */ + public function it_should_test_get_paging_counters_method() + { + $cases = $this->createMultiplePaused(3); + $paused = new Paused(); + $paused->setUserId($cases->USR_ID); + $paused->setUserUid($cases->USR_UID); + + $res = $paused->getPagingCounters(); + $this->assertEquals(3, $res); + + $delegation = Delegation::select()->where('USR_ID', $cases->USR_ID)->first(); + + $paused->setCaseNumber($delegation->APP_NUMBER); + $paused->setProcessId($delegation->PRO_ID); + $paused->setTaskId($delegation->TAS_ID); + $paused->setCaseUid($delegation->APP_UID); + + $res = $paused->getPagingCounters(); + $this->assertEquals(1, $res); + } } 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 17fd04121..c702e7c81 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php @@ -83,7 +83,7 @@ class SupervisingTest extends TestCase 'PRO_UID' => $process->PRO_UID, 'APP_NUMBER' => $app1['APP_NUMBER'], 'DEL_INDEX' => 1, - 'DEL_PREVIOUS' =>0 + 'DEL_PREVIOUS' => 0 ]); factory(Delegation::class, 1)->create([ "APP_UID" => $app1['APP_UID'], @@ -96,7 +96,7 @@ class SupervisingTest extends TestCase 'PRO_UID' => $process->PRO_UID, 'APP_NUMBER' => $app1['APP_NUMBER'], 'DEL_INDEX' => 2, - 'DEL_PREVIOUS' =>1 + 'DEL_PREVIOUS' => 1 ]); factory(Delegation::class, 1)->create([ @@ -110,7 +110,7 @@ class SupervisingTest extends TestCase 'PRO_UID' => $process->PRO_UID, 'APP_NUMBER' => $app2['APP_NUMBER'], 'DEL_INDEX' => 1, - 'DEL_PREVIOUS' =>0 + 'DEL_PREVIOUS' => 0 ]); factory(Delegation::class, 1)->create([ "APP_UID" => $app2['APP_UID'], @@ -123,7 +123,7 @@ class SupervisingTest extends TestCase 'PRO_UID' => $process->PRO_UID, 'APP_NUMBER' => $app2['APP_NUMBER'], 'DEL_INDEX' => 2, - 'DEL_PREVIOUS' =>1 + 'DEL_PREVIOUS' => 1 ]); factory(Delegation::class, 1)->create([ @@ -137,7 +137,7 @@ class SupervisingTest extends TestCase 'PRO_UID' => $process->PRO_UID, 'APP_NUMBER' => $app3['APP_NUMBER'], 'DEL_INDEX' => 1, - 'DEL_PREVIOUS' =>0 + 'DEL_PREVIOUS' => 0 ]); $delegation = factory(Delegation::class)->create([ "APP_UID" => $app3['APP_UID'], @@ -150,7 +150,7 @@ class SupervisingTest extends TestCase 'PRO_UID' => $process->PRO_UID, 'APP_NUMBER' => $app3['APP_NUMBER'], 'DEL_INDEX' => 2, - 'DEL_PREVIOUS' =>1 + 'DEL_PREVIOUS' => 1 ]); // Create the register in the ProcessUser table @@ -165,6 +165,152 @@ class SupervisingTest extends TestCase return $delegation; } + /** + * Create many supervising cases for one user + * + * @param int + * @return object + */ + public function createMultipleSupervising($cases) + { + $user = factory(\ProcessMaker\Model\User::class)->create(); + + for ($i = 0; $i < $cases; $i = $i + 1) { + // Create process + $process = factory(Process::class)->create(); + + // Create user + $user = factory(User::class)->create(); + + // Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + // Create 3 cases + $app1 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app2 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app3 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + + // Create the registers in delegation + factory(Delegation::class)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' => 0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' => 1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' => 0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' => 1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' => 0 + ]); + $delegation = factory(Delegation::class)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' => 1 + ]); + + // Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + } + return $user; + } + /** * Tests the getData() method when the user is a supervisor of the process(es) * @@ -290,14 +436,14 @@ class SupervisingTest extends TestCase // Instance the Supervising object $Supervising = new Supervising(); // Set the user UID - $Supervising->setUserUid($cases->USR_UID); + $Supervising->setUserUid($cases['USR_UID']); // Set the user ID - $Supervising->setUserId($cases->USR_ID); + $Supervising->setUserId($cases['USR_ID']); // Set the process Id filter - $Supervising->setProcessId($cases->PRO_ID); + $Supervising->setProcessId($cases['PRO_ID']); // Call the getData method $res = $Supervising->getData(); - $this->assertCount(1, $res); + $this->assertCount(3, $res); } /** @@ -314,14 +460,14 @@ class SupervisingTest extends TestCase // Instance the Supervising object $Supervising = new Supervising(); // Set the user UID - $Supervising->setUserUid($cases->USR_UID); + $Supervising->setUserUid($cases['USR_UID']); // Set the user ID - $Supervising->setUserId($cases->USR_ID); + $Supervising->setUserId($cases['USR_ID']); // Set the process Id filter - $Supervising->setProcessId($cases->TAS_ID); + $Supervising->setTaskId($cases['TAS_ID']); // Call the getData method $res = $Supervising->getData(); - $this->assertCount(1, $res); + $this->assertCount(3, $res); } /** @@ -376,9 +522,9 @@ class SupervisingTest extends TestCase // Instance the Supervising object $Supervising = new Supervising(); //Set the user UID - $Supervising->setUserUid($cases->USR_UID); + $Supervising->setUserUid($cases['USR_UID']); //Set the user ID - $Supervising->setUserId($cases->USR_ID); + $Supervising->setUserId($cases['USR_ID']); //Set the order by value $Supervising->setOrderByColumn($columnsView[$index]); //Call the getData method @@ -386,4 +532,31 @@ class SupervisingTest extends TestCase $this->assertCount(3, $res); $this->assertTrue($res[0]['APP_NUMBER'] > $res[1]['APP_NUMBER']); } -} \ No newline at end of file + + /** + * It tests the getPagingCounters() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getPagingCounters() + * @test + */ + public function it_should_test_get_paging_counters_method() + { + $cases = $this->createMultipleSupervising(3); + $supervising = new Supervising(); + $supervising->setUserId($cases->USR_ID); + $supervising->setUserUid($cases->USR_UID); + + $res = $supervising->getPagingCounters(); + $this->assertEquals(3, $res); + + $delegation = Delegation::select()->where('USR_ID', $cases->USR_ID)->first(); + + $supervising->setCaseNumber($delegation->APP_NUMBER); + $supervising->setProcessId($delegation->PRO_ID); + $supervising->setTaskId($delegation->TAS_ID); + $supervising->setCaseUid($delegation->APP_UID); + + $res = $supervising->getPagingCounters(); + $this->assertEquals(1, $res); + } +} 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 e80df2b19..d142f072a 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php @@ -74,6 +74,45 @@ class UnassignedTest extends TestCase } + /** + * Create many unassigned cases for one user + * + * @param int + * @return object + */ + public function createMultipleUnassigned($cases) + { + $user = factory(\ProcessMaker\Model\User::class)->create(); + + for ($i = 0; $i < $cases; $i = $i + 1) { + $process = factory(Process::class)->create(); + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + 'PRO_ID' => $process->PRO_ID, + ]); + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + factory(Delegation::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + '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 $user; + } + /** * This checks the counters is working properly in self-service user assigned * @@ -906,4 +945,32 @@ class UnassignedTest extends TestCase // Asserts $this->assertNotEmpty($res); } + + /** + * It tests the getPagingCounters() method + * + * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getPagingCounters() + * @test + */ + public function it_should_test_get_paging_counters_method() + { + $cases = $this->createMultipleUnassigned(3); + $unassigned = new Unassigned(); + $unassigned->setUserId($cases->USR_ID); + $unassigned->setUserUid($cases->USR_UID); + + $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); + + $res = $unassigned->getPagingCounters(); + $this->assertEquals(1, $res); + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index 2183adab7..11c62f068 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -1256,4 +1256,14 @@ class AbstractCases implements CasesInterface { throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'."); } + + /** + * Get the list counter + * + * @throws Exception + */ + public function getPagingCounters() + { + throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'."); + } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php index ff3d726b1..cdcff64ec 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php @@ -110,7 +110,7 @@ class Draft extends AbstractCases } /** - * Count the self-services cases by user + * Count how many cases the user has in DRAFT, does not apply filters * * @return int */ @@ -119,8 +119,23 @@ class Draft extends AbstractCases $query = Delegation::query()->select(); // Add the initial scope for draft cases $query->draft($this->getUserId()); - $this->filters($query); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } - return $query->count(); + /** + * Count how many cases the user has in DRAFT, needs to apply filters + * + * @return int + */ + public function getPagingCounters() + { + $query = Delegation::query()->select(); + // Add the initial scope for draft cases + $query->draft($this->getUserId()); + // Apply filters + $this->filters($query); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php index d6c7fc2ca..1872039f8 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php @@ -114,18 +114,32 @@ class Inbox extends AbstractCases } /** - * Get the number of rows corresponding to the List Inbox + * Count how many cases the user has in TO_DO, does not apply filters * * @return int */ public function getCounter() { $query = Delegation::query()->select(); - // Scope that sets the queries for List Inbox $query->inbox($this->getUserId()); - // Return the number of rows - return $query->count(); + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } + + /** + * Count how many cases the user has in TO_DO, needs to apply filters + * + * @return int + */ + public function getPagingCounters() + { + $query = Delegation::query()->select(); + // Scope that sets the queries for List Inbox + $query->inbox($this->getUserId()); + // Apply filters + $this->filters($query); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index 8cfa79c65..dbd9868bd 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -214,7 +214,7 @@ class Participated extends AbstractCases } /** - * Get the number of rows corresponding to the Participated + * Get the number of rows corresponding has Participation, does not apply filters * * @return int */ @@ -249,4 +249,43 @@ class Participated extends AbstractCases // Return the number of rows return $query->count(['APP_DELEGATION.APP_NUMBER']); } + + /** + * Count how many cases the user has Participation, needs to apply filters + * + * @return int + */ + public function getPagingCounters() + { + // Get base query + $query = Delegation::query()->select(); + // Join with application + $query->joinApplication(); + // Scope that sets the queries for Participated + $query->participated($this->getUserId()); + // Get filter + $filter = $this->getParticipatedStatus(); + switch ($filter) { + case 'STARTED': + // Scope that search for the STARTED by user + $query->caseStarted(); + break; + case 'IN_PROGRESS': + // Only distinct APP_NUMBER + $query->distinct(); + // Scope for in progress cases + $query->statusIds([self::STATUS_DRAFT, self::STATUS_TODO]); + break; + case 'COMPLETED': + // Scope that search for the COMPLETED + $query->caseCompleted(); + // Scope to set the last thread + $query->lastThread(); + break; + } + // Apply filters + $this->filters($query); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php index a3ad87134..1f485ac9c 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php @@ -109,7 +109,7 @@ class Paused extends AbstractCases } /** - * Get the total for the paused cases list + * Count how many cases the user has in PAUSED, does not apply filters * * @return int */ @@ -118,7 +118,23 @@ class Paused extends AbstractCases $query = Delegation::query()->select(); // Scope that set the paused cases $query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber()); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } - return $query->count(); + /** + * Count how many cases the user has in PAUSED, needs to apply filters + * + * @return int + */ + public function getPagingCounters() + { + $query = Delegation::query()->select(); + // Scope that set the paused cases + $query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber()); + // Apply filters + $this->filters($query); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php index 88114b302..94907fbce 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php @@ -177,15 +177,24 @@ class Search extends AbstractCases } /** - * Get the number of rows corresponding to the advanced search + * Count how many cases the user has in the advanced search, does not apply filters * * @return int */ public function getCounter() { - $query = Delegation::query()->select(); + // The search does not have a counters + return 0; + } - // Return the number of rows - return $query->count(); + /** + * Get the number of rows corresponding to the advanced search, needs to apply filters + * + * @return int + */ + public function getPagingCounters() + { + // The search always will enable the pagination + return 0; } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php index 8deaf7d43..d3740dd3e 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php @@ -169,7 +169,7 @@ class Supervising extends AbstractCases } /** - * Gets the total of Review cases + * Count how many cases the user has in Supervising, does not apply filters * * @return int */ @@ -186,4 +186,25 @@ class Supervising extends AbstractCases // Return the number of rows return $query->count(['APP_DELEGATION.APP_NUMBER']); } + + /** + * Count how many cases the user has in Supervising, needs to apply filters + * + * @return int + */ + public function getPagingCounters() + { + // Get base query + $query = Delegation::query()->select(); + // Only distinct APP_NUMBER + $query->distinct(); + // Get the list of processes of the supervisor + $processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid()); + // Scope the specific array of processes supervising + $query->processInList($processes); + // Apply filters + $this->filters($query); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php index f6e523d02..2fc7a1eb9 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php @@ -119,15 +119,32 @@ class Unassigned extends AbstractCases } /** - * Count the self-services cases by user + * Count how many cases the user has in SELF_SERVICE, does not apply filters * * @return int */ public function getCounter() { $query = Delegation::query()->select(); + // Add the initial scope for self-service cases $query->selfService($this->getUserUid()); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } - return $query->count(); + /** + * Count how many cases the user has in SELF_SERVICE, needs to apply filters + * + * @return int + */ + public function getPagingCounters() + { + $query = Delegation::query()->select(); + // Add the initial scope for self-service cases + $query->selfService($this->getUserUid()); + // Apply filters + $this->filters($query); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); } } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Home.php b/workflow/engine/src/ProcessMaker/Services/Api/Home.php index ca9339c51..26bba8594 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Home.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Home.php @@ -86,7 +86,7 @@ class Home extends Api $list->setProperties($properties); $result = []; $result['data'] = $list->getData(); - $result['total'] = $list->getCounter(); + $result['total'] = $list->getPagingCounters(); return $result; } catch (Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); @@ -141,7 +141,7 @@ class Home extends Api $list->setProperties($properties); $result = []; $result['data'] = $list->getData(); - $result['total'] = $list->getCounter(); + $result['total'] = $list->getPagingCounters(); return $result; } catch (Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); @@ -198,7 +198,7 @@ class Home extends Api $list->setProperties($properties); $result = []; $result['data'] = $list->getData(); - $result['total'] = $list->getCounter(); + $result['total'] = $list->getPagingCounters(); return $result; } catch (Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); @@ -253,7 +253,7 @@ class Home extends Api $list->setProperties($properties); $result = []; $result['data'] = $list->getData(); - $result['total'] = $list->getCounter(); + $result['total'] = $list->getPagingCounters(); return $result; } catch (Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); @@ -329,14 +329,14 @@ class Home extends Api $list->setParticipatedStatus($filter); $list->setProperties($properties); $result['data'] = $list->getData(); - $result['total'] = $list->getCounter(); + $result['total'] = $list->getPagingCounters(); break; case 'SUPERVISING': // Scope that search for the SUPERVISING cases by specific user $list = new Supervising(); $list->setProperties($properties); $result['data'] = $list->getData(); - $result['total'] = $list->getCounter(); + $result['total'] = $list->getPagingCounters(); break; } }