PMCORE-1221

This commit is contained in:
Andrea Adamczyk
2021-04-30 09:17:09 -04:00
parent d669aedf46
commit f7fbc8f05e
2 changed files with 216 additions and 86 deletions

View File

@@ -10,6 +10,7 @@ use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\EmailServerModel; use ProcessMaker\Model\EmailServerModel;
use ProcessMaker\Model\Process; use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task; use ProcessMaker\Model\Task;
use ProcessMaker\Model\TaskUser;
use ProcessMaker\Model\User; use ProcessMaker\Model\User;
use ProcessMaker\Model\UserReporting; use ProcessMaker\Model\UserReporting;
use Tests\TestCase; use Tests\TestCase;
@@ -167,14 +168,14 @@ class WsBaseTest extends TestCase
private function createDefaultHtmlContent($content = '') private function createDefaultHtmlContent($content = '')
{ {
$string = '' $string = ''
. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
. '<html>' . '<html>'
. '<head>' . '<head>'
. '</head>' . '</head>'
. '<body>' . '<body>'
. $content . $content
. '</body>' . '</body>'
. '</html>'; . '</html>';
return $string; return $string;
} }
@@ -493,48 +494,48 @@ class WsBaseTest extends TestCase
//Create the application factory //Create the application factory
$application1 = factory(Application::class)->create( $application1 = factory(Application::class)->create(
[ [
'APP_STATUS' => 'TO_DO', 'APP_STATUS' => 'TO_DO',
'APP_TITLE' => 'Title1' 'APP_TITLE' => 'Title1'
] ]
); );
$application2 = factory(Application::class)->create( $application2 = factory(Application::class)->create(
[ [
'APP_STATUS' => 'DRAFT', 'APP_STATUS' => 'DRAFT',
'APP_TITLE' => 'Title2' 'APP_TITLE' => 'Title2'
] ]
); );
//Create the delegation factory //Create the delegation factory
$delegation1 = factory(Delegation::class)->create( $delegation1 = factory(Delegation::class)->create(
[ [
'USR_UID' => $user->USR_UID, 'USR_UID' => $user->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null, 'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application1->APP_NUMBER 'APP_NUMBER' => $application1->APP_NUMBER
] ]
); );
$delegation2 = factory(Delegation::class)->create( $delegation2 = factory(Delegation::class)->create(
[ [
'USR_UID' => $user->USR_UID, 'USR_UID' => $user->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null, 'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application2->APP_NUMBER 'APP_NUMBER' => $application2->APP_NUMBER
] ]
); );
//Create app thread factory //Create app thread factory
factory(AppThread::class)->create( factory(AppThread::class)->create(
[ [
'APP_THREAD_STATUS' => 'OPEN', 'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation1->APP_UID 'APP_UID' => $delegation1->APP_UID
] ]
); );
factory(AppThread::class)->create( factory(AppThread::class)->create(
[ [
'APP_THREAD_STATUS' => 'OPEN', 'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation2->APP_UID 'APP_UID' => $delegation2->APP_UID
] ]
); );
//Instance the object //Instance the object
@@ -568,48 +569,48 @@ class WsBaseTest extends TestCase
//Create the application factory //Create the application factory
$application1 = factory(Application::class)->create( $application1 = factory(Application::class)->create(
[ [
'APP_STATUS' => 'TO_DO', 'APP_STATUS' => 'TO_DO',
'APP_TITLE' => 'Title1' 'APP_TITLE' => 'Title1'
] ]
); );
$application2 = factory(Application::class)->create( $application2 = factory(Application::class)->create(
[ [
'APP_STATUS' => 'DRAFT', 'APP_STATUS' => 'DRAFT',
'APP_TITLE' => 'Title2' 'APP_TITLE' => 'Title2'
] ]
); );
//Create the delegation factory //Create the delegation factory
$delegation1 = factory(Delegation::class)->create( $delegation1 = factory(Delegation::class)->create(
[ [
'USR_UID' => $user1->USR_UID, 'USR_UID' => $user1->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null, 'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application1->APP_NUMBER 'APP_NUMBER' => $application1->APP_NUMBER
] ]
); );
$delegation2 = factory(Delegation::class)->create( $delegation2 = factory(Delegation::class)->create(
[ [
'USR_UID' => $user1->USR_UID, 'USR_UID' => $user1->USR_UID,
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
'DEL_FINISH_DATE' => null, 'DEL_FINISH_DATE' => null,
'APP_NUMBER' => $application2->APP_NUMBER 'APP_NUMBER' => $application2->APP_NUMBER
] ]
); );
//Create app thread factory //Create app thread factory
factory(AppThread::class)->create( factory(AppThread::class)->create(
[ [
'APP_THREAD_STATUS' => 'OPEN', 'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation1->APP_UID 'APP_UID' => $delegation1->APP_UID
] ]
); );
factory(AppThread::class)->create( factory(AppThread::class)->create(
[ [
'APP_THREAD_STATUS' => 'OPEN', 'APP_THREAD_STATUS' => 'OPEN',
'APP_UID' => $delegation2->APP_UID 'APP_UID' => $delegation2->APP_UID
] ]
); );
//Instance the object //Instance the object
@@ -1122,4 +1123,140 @@ class WsBaseTest extends TestCase
$this->assertEquals($response->status_code, 100); $this->assertEquals($response->status_code, 100);
$this->assertContains($fakeApp, $response->message); $this->assertContains($fakeApp, $response->message);
} }
/**
* Test the unassigned case list method with unassigned cases
*
* @test
* @covers WsBase::unassignedCaseList()
*/
public function it_should_test_the_unassigned_case_list_method_with_unassigned_cases()
{
//Create process
$process1 = factory(Process::class)->create([
'PRO_TITLE' => 'China Supplier Payment Proposal'
]);
$process2 = factory(Process::class)->create([
'PRO_TITLE' => 'Egypt Supplier Payment Proposal'
]);
//Create application
$application1 = factory(Application::class)->create([
'APP_STATUS_ID' => 2
]);
//Create user
$user = factory(User::class)->create();
//Create a task self service
$task1 = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => 'SELF_SERVICE',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process1->PRO_UID
]);
$task2 = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => 'SELF_SERVICE',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process1->PRO_UID
]);
//Assign a user in the task
factory(TaskUser::class)->create([
'TAS_UID' => $task1->TAS_UID,
'USR_UID' => $user->USR_UID,
'TU_RELATION' => 1, //Related to the user
'TU_TYPE' => 1
]);
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 the register in delegation relate to self-service
factory(Delegation::class, 2)->create([
'APP_NUMBER' => $application1->APP_NUMBER,
'TAS_ID' => $task1->TAS_ID,
'PRO_ID' => $process1->id,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_ID' => 0,
]);
factory(Delegation::class, 2)->create([
'APP_NUMBER' => $application1->APP_NUMBER,
'TAS_ID' => $task2->TAS_ID,
'PRO_ID' => $process2->id,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_ID' => 0,
]);
$wsBase = new WsBase();
$res = $wsBase->unassignedCaseList($user->USR_UID);
//Assert the expected number of unassigned cases
$this->assertCount(4, $res);
}
/**
* Test the unassigned case list method without unassigned cases
*
* @test
* @covers WsBase::unassignedCaseList()
*/
public function it_should_test_the_unassigned_case_list_method_without_unassigned_cases()
{
//Create process
$process1 = factory(Process::class)->create([
'PRO_TITLE' => 'China Supplier Payment Proposal'
]);
$process2 = factory(Process::class)->create([
'PRO_TITLE' => 'Egypt Supplier Payment Proposal'
]);
//Create application
$application1 = factory(Application::class)->create([
'APP_STATUS_ID' => 2
]);
//Create user
$user = factory(User::class)->create();
//Create a task self service
$task1 = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => 'SELF_SERVICE',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process1->PRO_UID
]);
$task2 = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => 'SELF_SERVICE',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process1->PRO_UID
]);
//Assign a user in the task
factory(TaskUser::class)->create([
'TAS_UID' => $task1->TAS_UID,
'USR_UID' => $user->USR_UID,
'TU_RELATION' => 1, //Related to the user
'TU_TYPE' => 1
]);
//Assign a user in the task
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 the register in delegation relate to self-service
factory(Delegation::class, 2)->create([
'APP_NUMBER' => $application1->APP_NUMBER,
'TAS_ID' => $task1->TAS_ID,
'PRO_ID' => $process1->id,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_ID' => 5,
]);
factory(Delegation::class, 2)->create([
'APP_NUMBER' => $application1->APP_NUMBER,
'TAS_ID' => $task2->TAS_ID,
'PRO_ID' => $process2->id,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_ID' => 3,
]);
$wsBase = new WsBase();
$res = $wsBase->unassignedCaseList($user->USR_UID);
//Assert the expected number of unassigned cases
$this->assertCount(0, $res);
}
} }

View File

@@ -3,6 +3,7 @@
use App\Jobs\EmailEvent; use App\Jobs\EmailEvent;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use ProcessMaker\BusinessModel\Cases as BmCases; use ProcessMaker\BusinessModel\Cases as BmCases;
use ProcessMaker\BusinessModel\Cases\Unassigned;
use ProcessMaker\BusinessModel\EmailServer; use ProcessMaker\BusinessModel\EmailServer;
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
use ProcessMaker\ChangeLog\ChangeLog; use ProcessMaker\ChangeLog\ChangeLog;
@@ -541,41 +542,33 @@ class WsBase
/** /**
* Get unassigned case list * Get unassigned case list
* *
* @param string $userId * @param string $userUid
* *
* @return $result will return an object * @return $result will return an object
*/ */
public function unassignedCaseList($userId) public function unassignedCaseList($userUid)
{ {
try { try {
$result = []; $result = [];
$oAppCache = new AppCacheView(); $unassigned = new Unassigned();
$Criteria = $oAppCache->getUnassignedListCriteria($userId); $unassigned->setUserUid($userUid);
$oDataset = AppCacheViewPeer::doSelectRS($Criteria); $data = $unassigned->getData();
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); foreach ($data as $var) {
$oDataset->next(); array_push($result, [
'guid' => $var['APP_UID'],
while ($aRow = $oDataset->getRow()) { 'name' => $var['APP_NUMBER'],
$result[] = array( 'delIndex' => $var['DEL_INDEX'],
'guid' => $aRow['APP_UID'], 'processId' => $var['PRO_UID']
'name' => $aRow['APP_NUMBER'], ]);
'delIndex' => $aRow['DEL_INDEX'],
'processId' => $aRow['PRO_UID']
);
$oDataset->next();
} }
return $result; return $result;
} catch (Exception $e) { } catch (Exception $e) {
$result[] = array( $result[] = [
'guid' => $e->getMessage(), 'guid' => $e->getMessage(),
'name' => $e->getMessage(), 'name' => $e->getMessage(),
'status' => $e->getMessage(), 'status' => $e->getMessage(),
'status' => $e->getMessage(),
'processId' => $e->getMessage() 'processId' => $e->getMessage()
); ];
return $result; return $result;
} }
} }