diff --git a/database/factories/ApplicationFactory.php b/database/factories/ApplicationFactory.php index 8d7e4df58..e04de6df0 100644 --- a/database/factories/ApplicationFactory.php +++ b/database/factories/ApplicationFactory.php @@ -77,6 +77,14 @@ $factory->state(\ProcessMaker\Model\Application::class, 'draft', function (Faker ]; }); +$factory->state(\ProcessMaker\Model\Application::class, 'completed', function (Faker $faker) { + return [ + 'APP_NUMBER' => $faker->unique()->numberBetween(1000), + 'APP_STATUS_ID' => 3, + 'APP_STATUS' => 'COMPLETED' + ]; +}); + $factory->state(\ProcessMaker\Model\Application::class, 'draft_minor_case', function (Faker $faker) { $caseNumber = $faker->unique()->numberBetween(1, 1000); return [ diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index fffbb43c4..29721a4df 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -42,7 +42,11 @@ $factory->define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) { $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function (Faker $faker) { // Create values in the foreign key relations $user = factory(\ProcessMaker\Model\User::class)->create(); - $process = factory(\ProcessMaker\Model\Process::class)->create(); + $category = factory(\ProcessMaker\Model\ProcessCategory::class)->create(); + $process = factory(\ProcessMaker\Model\Process::class)->create([ + 'PRO_CATEGORY' => $category->CATEGORY_UID, + 'CATEGORY_ID' => $category->CATEGORY_ID + ]); $task = factory(\ProcessMaker\Model\Task::class)->create([ 'PRO_UID' => $process->PRO_UID, 'PRO_ID' => $process->PRO_ID @@ -113,3 +117,10 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'closed', function (Faker 'DEL_FINISH_DATE' => $finishDate ]; }); + +// Create a last delegation +$factory->state(\ProcessMaker\Model\Delegation::class, 'last_thread', function (Faker $faker) { + return [ + 'DEL_LAST_INDEX' => 1, + ]; +}); 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 48eeca122..0a2288db9 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php @@ -10,7 +10,6 @@ use ProcessMaker\Model\ProcessCategory; use ProcessMaker\Model\User; use Tests\TestCase; - /** * @coversDefaultClass \ProcessMaker\BusinessModel\Cases\AbstractCases */ @@ -105,7 +104,7 @@ class AbstractCasesTest extends TestCase $absCases->setInboxStatus($arguments[$index]); $actual = $absCases->getInboxStatus(); if (empty($arguments[$index])) { - $this->assertEquals($arguments[$index], 'ALL'); + $this->assertEquals('ALL', $actual); } else { $this->assertEquals($arguments[$index], $actual); } @@ -126,7 +125,7 @@ class AbstractCasesTest extends TestCase $absCases->setParticipatedStatus($arguments[$index]); $actual = $absCases->getParticipatedStatus(); if (empty($arguments[$index])) { - $this->assertEquals($arguments[$index], 'ALL'); + $this->assertEquals('ALL', $actual); } else { $this->assertEquals($arguments[$index], $actual); } @@ -147,7 +146,7 @@ class AbstractCasesTest extends TestCase $absCases->setRiskStatus($arguments[$index]); $actual = $absCases->getRiskStatus(); if (empty($arguments[$index])) { - $this->assertEquals($arguments[$index], 'ALL'); + $this->assertEquals('ALL', $actual); } else { $this->assertEquals($arguments[$index], $actual); } @@ -168,7 +167,7 @@ class AbstractCasesTest extends TestCase $absCases->setCaseStatus($arguments[$index]); $actual = $absCases->getCaseStatus(); if (empty($arguments[$index])) { - $this->assertEquals($arguments[$index], 'ALL'); + $this->assertEquals('ALL', $actual); } else { $this->assertEquals($arguments[$index], $actual); } @@ -311,6 +310,13 @@ class AbstractCasesTest extends TestCase 'search' => G::generateUniqueID(), 'caseLink' => G::generateUniqueID(), 'appUidCheck' => [G::generateUniqueID()], + 'newestthan' => date('Y-m-d'), + 'oldestthan' => date('Y-m-d'), + 'sort' => 'APP_DELEGATION.APP_NUMBER', + 'dir' => 'DESC', + 'paged' => true, + 'start' => 5, + 'limit' => 10, ]; $absCases->setProperties($properties); $actual = $absCases->getCategoryUid(); @@ -321,5 +327,23 @@ class AbstractCasesTest extends TestCase $this->assertEquals($properties['user'], $actual); $actual = $absCases->getValueToSearch(); $this->assertEquals($properties['search'], $actual); + $actual = $absCases->getCaseUid(); + $this->assertEquals($properties['caseLink'], $actual); + $actual = $absCases->getCasesUids(); + $this->assertEquals($properties['appUidCheck'], $actual); + $actual = $absCases->getNewestThan(); + $this->assertEquals($properties['newestthan'], $actual); + $actual = $absCases->getOldestThan(); + $this->assertEquals($properties['oldestthan'], $actual); + $actual = $absCases->getOrderByColumn(); + $this->assertEquals($properties['sort'], $actual); + $actual = $absCases->getOrderDirection(); + $this->assertEquals($properties['dir'], $actual); + $actual = $absCases->getPaged(); + $this->assertEquals($properties['paged'], $actual); + $actual = $absCases->getOffset(); + $this->assertEquals($properties['start'], $actual); + $actual = $absCases->getLimit(); + $this->assertEquals($properties['limit'], $actual); } } \ No newline at end of file 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 673bd2d8a..00ee2c976 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php @@ -566,7 +566,7 @@ class InboxTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getCounter() * @test */ - public function it_should_test_the_counter_for_list_inbox() + public function it_should_test_the_counter_for_inbox() { //Create process $process = factory(Process::class)->create(); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php new file mode 100644 index 000000000..e1ef3ff35 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php @@ -0,0 +1,224 @@ +states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'CLOSED', + 'DEL_INDEX' => 1, + ]); + $delegation2 = factory(Delegation::class)->states('last_thread')->create([ + '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 $delegation2; + } + + /** + * It tests the getData method without filters + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @test + */ + public function it_should_test_get_data_method_without_filters() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the user UID + $participated->setUserUid($cases->USR_UID); + // Set the user ID + $participated->setUserId($cases->USR_ID); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(1, count($res)); + } + + /** + * It tests the getData method with process + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @test + */ + public function it_should_test_get_data_method_with_specific_process() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the user UID + $participated->setUserUid($cases->USR_UID); + // Set the user ID + $participated->setUserId($cases->USR_ID); + // Set the process ID + $participated->setProcessId($cases->PRO_ID); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(1, count($res)); + } + + /** + * It tests the getData method with process category + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @test + */ + public function it_should_test_get_data_method_with_specific_process_category() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + $process = Process::query()->where('PRO_ID', $cases->PRO_ID)->get()->toArray(); + $process = head($process); + // Create new Participated object + $participated = new Participated(); + // Set the user UID + $participated->setUserUid($cases->USR_UID); + // Set the user ID + $participated->setUserId($cases->USR_ID); + // Set the process ID + $participated->setProcessId($cases->PRO_ID); + // Set the category + $participated->setCategoryUid($process['PRO_CATEGORY']); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(1, count($res)); + } + + /** + * It tests the getData method with specific TO_DO status + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @test + */ + public function it_should_test_get_data_method_with_case_to_do() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the user UID + $participated->setUserUid($cases->USR_UID); + // Set the user ID + $participated->setUserId($cases->USR_ID); + // Set the case status + $participated->setCaseStatus('TO_DO'); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(1, count($res)); + } + + /** + * It tests the getData method with specific filter StartedByMe + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @test + */ + public function it_should_test_get_data_method_started_by_me_filter() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the user UID + $participated->setUserUid($cases->USR_UID); + // Set the user ID + $participated->setUserId($cases->USR_ID); + // Set the filter STARTED + $participated->setParticipatedStatus('STARTED'); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(0, count($res)); + } + + /** + * It tests the getData method with specific filter CompletedByMe + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @test + */ + public function it_should_test_get_data_method_completed_by_me_filter() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the user UID + $participated->setUserUid($cases->USR_UID); + // Set the user ID + $participated->setUserId($cases->USR_ID); + // Set the filter COMPLETED + $participated->setParticipatedStatus('COMPLETED'); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(0, count($res)); + } + + /** + * It tests the getCounter method + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getCounter() + * @test + */ + public function it_should_test_the_counter_for_participated() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the user UID + $participated->setUserUid($cases->USR_UID); + // Set the user ID + $participated->setUserId($cases->USR_ID); + $res = $participated->getCounter(); + // Assert the result of getCounter method + $this->assertEquals(1, $res); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index 70f0161e9..6e4aada28 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -2,7 +2,79 @@ namespace ProcessMaker\BusinessModel\Cases; +use ProcessMaker\Model\Application; +use ProcessMaker\Model\Delegation; + class Participated extends AbstractCases { + /** + * Get the data corresponding to Participated + * + * @return array + */ + public function getData() + { + // Start the query for get the cases related to the user + $query = Delegation::query()->select(); + // Scope to Participated + $query->participated($this->getUserId()); + // Scope to search for an specific process + if (!empty($this->getProcessId())) { + $query->processId($this->getProcessId()); + } + + // Scope the specific category + $category = $this->getCategoryUid(); + if (!empty($category)) { + $query->categoryProcess($category); + } + + // Scope the specific case status + $status = $this->getCaseStatus(); + if (array_key_exists($status, Application::$app_status_values)) { + $statusId = Application::$app_status_values[$status]; + $query->appStatusId($statusId); + } + + // Add filter + $filter = $this->getParticipatedStatus(); + if (!empty($filter)) { + switch ($filter) { + case 'STARTED': + // Scope that search for the STARTED cases by specific user + $query->caseStarted(); + break; + case 'COMPLETED': + // Scope that search for the COMPLETED cases by specific user + $query->caseCompleted(); + break; + } + } + + // The order by clause + $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); + + // The limit by clause + $query->offset($this->getOffset())->limit($this->getLimit()); + + //Execute the query + $result = $query->get(); + + //Return the values as an array format + return $result->values()->toArray(); + } + /** + * Get the number of rows corresponding to the Participate + * + * @return int + */ + public function getCounter() + { + $query = Delegation::query()->select(); + // Scope that sets the queries for Participated + $query->participated($this->getUserId()); + // Return the number of rows + return $query->count(); + } } diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index 092582f32..2a67506ec 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -17,6 +17,8 @@ class Application extends Model const STATUS_TODO = 2; const STATUS_COMPLETED = 3; const STATUS_CANCELED = 4; + // Status name and status id + public static $app_status_values = ['DRAFT' => 1, 'TO_DO' => 2, 'COMPLETED' => 3, 'CANCELLED' => 4]; public function delegations() {