PMCORE-3201

This commit is contained in:
Paula Quispe
2021-08-04 12:26:09 -04:00
parent ec7b157c00
commit 37c3908338
3 changed files with 400 additions and 321 deletions

View File

@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Participated; use ProcessMaker\BusinessModel\Cases\Participated;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use Tests\TestCase; use Tests\TestCase;
@@ -26,7 +27,7 @@ class ParticipatedTest extends TestCase
} }
/** /**
* Create participated cases factories * Create participated cases factories when the case is TO_DO
* *
* @param string * @param string
* *
@@ -37,8 +38,9 @@ class ParticipatedTest extends TestCase
$delegation = factory(Delegation::class)->states('foreign_keys')->create([ $delegation = factory(Delegation::class)->states('foreign_keys')->create([
'DEL_THREAD_STATUS' => 'CLOSED', 'DEL_THREAD_STATUS' => 'CLOSED',
'DEL_INDEX' => 1, 'DEL_INDEX' => 1,
'DEL_LAST_INDEX' => 0,
]); ]);
$delegation2 = factory(Delegation::class)->states('last_thread')->create([ $delegation = factory(Delegation::class)->states('last_thread')->create([
'APP_NUMBER' => $delegation->APP_NUMBER, 'APP_NUMBER' => $delegation->APP_NUMBER,
'TAS_ID' => $delegation->TAS_ID, 'TAS_ID' => $delegation->TAS_ID,
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
@@ -46,9 +48,41 @@ class ParticipatedTest extends TestCase
'USR_ID' => $delegation->USR_ID, 'USR_ID' => $delegation->USR_ID,
'PRO_ID' => $delegation->PRO_ID, 'PRO_ID' => $delegation->PRO_ID,
'DEL_INDEX' => 2, 'DEL_INDEX' => 2,
'DEL_LAST_INDEX' => 1,
]); ]);
return $delegation2; return $delegation;
}
/**
* Create participated cases factories when the case is COMPLETED
*
* @param string
*
* @return array
*/
public function createParticipatedCompleted()
{
$application = factory(Application::class)->states('completed')->create();
$delegation = factory(Delegation::class)->states('first_thread')->create([
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'DEL_THREAD_STATUS' => 'CLOSED',
'DEL_INDEX' => 1,
'DEL_LAST_INDEX' => 0,
]);
$delegation = factory(Delegation::class)->states('last_thread')->create([
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'DEL_THREAD_STATUS' => 'CLOSED',
'USR_UID' => $delegation->USR_UID,
'USR_ID' => $delegation->USR_ID,
'PRO_ID' => $delegation->PRO_ID,
'DEL_INDEX' => 2,
'DEL_LAST_INDEX' => 1,
]);
return $delegation;
} }
/** /**
@@ -67,6 +101,7 @@ class ParticipatedTest extends TestCase
'DEL_INDEX' => 1, 'DEL_INDEX' => 1,
'USR_UID' => $user->USR_UID, 'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID, 'USR_ID' => $user->USR_ID,
'DEL_LAST_INDEX' => 0,
]); ]);
factory(Delegation::class)->states('last_thread')->create([ factory(Delegation::class)->states('last_thread')->create([
'APP_UID' => $delegation->APP_UID, 'APP_UID' => $delegation->APP_UID,
@@ -77,6 +112,7 @@ class ParticipatedTest extends TestCase
'USR_ID' => $delegation->USR_ID, 'USR_ID' => $delegation->USR_ID,
'PRO_ID' => $delegation->PRO_ID, 'PRO_ID' => $delegation->PRO_ID,
'DEL_INDEX' => 2, 'DEL_INDEX' => 2,
'DEL_LAST_INDEX' => 1,
]); ]);
} }
return $user; return $user;
@@ -105,9 +141,9 @@ class ParticipatedTest extends TestCase
// Set OrderBYColumn value // Set OrderBYColumn value
$participated->setOrderByColumn('APP_NUMBER'); $participated->setOrderByColumn('APP_NUMBER');
// Get the data // Get the data
$res = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals(2, count($res)); $this->assertNotEmpty($result);
} }
/** /**
@@ -137,9 +173,9 @@ class ParticipatedTest extends TestCase
// Set the filter STARTED // Set the filter STARTED
$participated->setParticipatedStatus('STARTED'); $participated->setParticipatedStatus('STARTED');
// Get the data // Get the data
$res = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals(1, count($res)); $this->assertNotEmpty($result);
} }
/** /**
@@ -156,7 +192,7 @@ class ParticipatedTest extends TestCase
public function it_filter_by_completed_by_me() public function it_filter_by_completed_by_me()
{ {
// Create factories related to the participated cases // Create factories related to the participated cases
$cases = $this->createParticipated(); $cases = $this->createParticipatedCompleted();
// Create new Participated object // Create new Participated object
$participated = new Participated(); $participated = new Participated();
// Set the user UID // Set the user UID
@@ -166,9 +202,9 @@ class ParticipatedTest extends TestCase
// Set the filter COMPLETED // Set the filter COMPLETED
$participated->setParticipatedStatus('COMPLETED'); $participated->setParticipatedStatus('COMPLETED');
// Get the data // Get the data
$res = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals(0, count($res)); $this->assertNotEmpty($result);
} }
/** /**
@@ -198,9 +234,9 @@ class ParticipatedTest extends TestCase
// Set the process // Set the process
$participated->setProcessId($cases['PRO_ID']); $participated->setProcessId($cases['PRO_ID']);
// Get the data // Get the data
$res = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals(2, count($res)); $this->assertNotEmpty($result);
} }
/** /**
@@ -227,9 +263,9 @@ class ParticipatedTest extends TestCase
// Set the case numbers // Set the case numbers
$participated->setCasesNumbers([$cases['APP_NUMBER']]); $participated->setCasesNumbers([$cases['APP_NUMBER']]);
// Get the data // Get the data
$res = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals(2, count($res)); $this->assertNotEmpty($result);
} }
/** /**
@@ -257,9 +293,9 @@ class ParticipatedTest extends TestCase
$rangeOfCases = $cases['APP_NUMBER'] . "-" . $cases['APP_NUMBER']; $rangeOfCases = $cases['APP_NUMBER'] . "-" . $cases['APP_NUMBER'];
$participated->setRangeCasesFromTo([$rangeOfCases]); $participated->setRangeCasesFromTo([$rangeOfCases]);
// Get the data // Get the data
$res = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals(2, count($res)); $this->assertNotEmpty($result);
} }
/** /**
@@ -291,9 +327,9 @@ class ParticipatedTest extends TestCase
// Set the title // Set the title
$participated->setCaseTitle($cases->DEL_TITLE); $participated->setCaseTitle($cases->DEL_TITLE);
// Get the data // Get the data
$res = $participated->getData(); $result = $participated->getData();
// Asserts // Asserts with the result
$this->assertCount(1, $res); $this->assertNotEmpty($result);
} }
/** /**
@@ -324,7 +360,7 @@ class ParticipatedTest extends TestCase
$participated->setCaseStatus('TO_DO'); $participated->setCaseStatus('TO_DO');
// Get the data // Get the data
$result = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
@@ -359,7 +395,7 @@ class ParticipatedTest extends TestCase
$participated->setStartCaseTo($date); $participated->setStartCaseTo($date);
// Get the data // Get the data
$result = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEmpty($result); $this->assertEmpty($result);
} }
@@ -394,7 +430,7 @@ class ParticipatedTest extends TestCase
$participated->setFinishCaseTo($date); $participated->setFinishCaseTo($date);
// Get the data // Get the data
$result = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEmpty($result); $this->assertEmpty($result);
} }
@@ -419,11 +455,39 @@ class ParticipatedTest extends TestCase
$participated->setUserId($cases->USR_ID); $participated->setUserId($cases->USR_ID);
// Set participated status // Set participated status
$participated->setParticipatedStatus('IN_PROGRESS'); $participated->setParticipatedStatus('IN_PROGRESS');
// Get result // Get the data
$result = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
/**
* It tests the specific filter setParticipatedStatus = STARTED
*
* @covers \ProcessMaker\BusinessModel\Cases\Participated::getData()
* @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView()
* @covers \ProcessMaker\BusinessModel\Cases\Participated::filters()
* @covers \ProcessMaker\BusinessModel\Cases\Participated::setParticipatedStatus()
* @test
*/
public function it_get_status_started()
{
// 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 participated status
$participated->setParticipatedStatus('STARTED');
// Get the data
$result = $participated->getData();
// Asserts with the result
$this->assertNotEmpty($result);
}
/** /**
* It tests the specific filter setParticipatedStatus = COMPLETED * It tests the specific filter setParticipatedStatus = COMPLETED
* *
@@ -436,7 +500,7 @@ class ParticipatedTest extends TestCase
public function it_get_status_completed() public function it_get_status_completed()
{ {
// Create factories related to the participated cases // Create factories related to the participated cases
$cases = $this->createParticipated(); $cases = $this->createParticipatedCompleted();
// Create new Participated object // Create new Participated object
$participated = new Participated(); $participated = new Participated();
// Set the user UID // Set the user UID
@@ -445,10 +509,10 @@ class ParticipatedTest extends TestCase
$participated->setUserId($cases->USR_ID); $participated->setUserId($cases->USR_ID);
// Set participated status // Set participated status
$participated->setParticipatedStatus('COMPLETED'); $participated->setParticipatedStatus('COMPLETED');
// Get result // Get the data
$result = $participated->getData(); $result = $participated->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEmpty($result); $this->assertNotEmpty($result);
} }
/** /**
@@ -460,7 +524,22 @@ class ParticipatedTest extends TestCase
*/ */
public function it_get_counter() public function it_get_counter()
{ {
// Create factories related to the participated cases // Create factories related to the in started 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 participated status
$participated->setParticipatedStatus('STARTED');
// Get the data
$result = $participated->getCounter();
// Asserts with the result
$this->assertTrue($result > 0);
// Create factories related to the in progress cases
$cases = $this->createParticipated(); $cases = $this->createParticipated();
// Create new Participated object // Create new Participated object
$participated = new Participated(); $participated = new Participated();
@@ -470,10 +549,25 @@ class ParticipatedTest extends TestCase
$participated->setUserId($cases->USR_ID); $participated->setUserId($cases->USR_ID);
// Set participated status // Set participated status
$participated->setParticipatedStatus('IN_PROGRESS'); $participated->setParticipatedStatus('IN_PROGRESS');
// Get result // Get the data
$res = $participated->getCounter(); $result = $participated->getCounter();
// Assert the result of getCounter method // Asserts with the result
$this->assertEquals(1, $res); $this->assertTrue($result > 0);
// Create factories related to the complete cases
$cases = $this->createParticipatedCompleted();
// 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 participated status
$participated->setParticipatedStatus('COMPLETED');
// Get the data
$result = $participated->getCounter();
// Asserts with the result
$this->assertTrue($result > 0);
} }
/** /**
@@ -485,20 +579,40 @@ class ParticipatedTest extends TestCase
*/ */
public function it_should_test_get_paging_counters_method() public function it_should_test_get_paging_counters_method()
{ {
$cases = $this->createMultipleParticipated(3); // Create factories related to the in started cases
$cases = $this->createParticipated();
$participated = new Participated(); $participated = new Participated();
$participated->setUserId($cases->USR_ID); $participated->setUserId($cases->USR_ID);
$participated->setUserUid($cases->USR_UID); $participated->setUserUid($cases->USR_UID);
$participated->setCaseUid($cases->APP_UID);
$participated->setParticipatedStatus('STARTED'); $participated->setParticipatedStatus('STARTED');
$res = $participated->getPagingCounters(); // Get the data
$this->assertEquals(3, $res); $result = $participated->getPagingCounters();
// Asserts with the result
$this->assertTrue($result >= 0);
$delegation = Delegation::select()->where('USR_ID', $cases->USR_ID)->first(); // Create factories related to the in progress cases
$participated->setCaseNumber($delegation->APP_NUMBER); $cases = $this->createParticipated();
$participated->setProcessId($delegation->PRO_ID); $participated = new Participated();
$participated->setTaskId($delegation->TAS_ID); $participated->setUserId($cases->USR_ID);
$participated->setCaseUid($delegation->APP_UID); $participated->setUserUid($cases->USR_UID);
$res = $participated->getPagingCounters(); $participated->setCaseUid($cases->APP_UID);
$this->assertEquals(1, $res); $participated->setParticipatedStatus('IN_PROGRESS');
// Get the data
$result = $participated->getPagingCounters();
// Asserts with the result
$this->assertTrue($result >= 0);
// Create factories related to the complete cases
$cases = $this->createParticipatedCompleted();
$participated = new Participated();
$participated->setUserId($cases->USR_ID);
$participated->setUserUid($cases->USR_UID);
$participated->setCaseUid($cases->APP_UID);
$participated->setParticipatedStatus('COMPLETED');
// Get the data
$result = $participated->getPagingCounters();
// Asserts with the result
$this->assertTrue($result >= 0);
} }
} }

View File

@@ -56,7 +56,7 @@ class SearchTest extends TestCase
// Create new Search object // Create new Search object
$search = new Search(); $search = new Search();
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
@@ -67,7 +67,6 @@ class SearchTest extends TestCase
* @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView()
* @covers \ProcessMaker\BusinessModel\Cases\Search::filters() * @covers \ProcessMaker\BusinessModel\Cases\Search::filters()
* @covers \ProcessMaker\BusinessModel\Cases\Search::setCaseNumber() * @covers \ProcessMaker\BusinessModel\Cases\Search::setCaseNumber()
* @covers \ProcessMaker\BusinessModel\Cases\Search::setOrderByColumn()
* @test * @test
*/ */
public function it_filter_by_app_number() public function it_filter_by_app_number()
@@ -77,10 +76,8 @@ class SearchTest extends TestCase
// Create new Search object // Create new Search object
$search = new Search(); $search = new Search();
$search->setCaseNumber($cases[0]->APP_NUMBER); $search->setCaseNumber($cases[0]->APP_NUMBER);
// Set order by column value
$search->setOrderByColumn('APP_NUMBER');
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']); $this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']);
} }
@@ -101,7 +98,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setCasesNumbers([$cases[0]->APP_NUMBER]); $search->setCasesNumbers([$cases[0]->APP_NUMBER]);
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']); $this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']);
} }
@@ -123,7 +120,31 @@ class SearchTest extends TestCase
$rangeOfCases = $cases[0]->APP_NUMBER . "-" . $cases[0]->APP_NUMBER; $rangeOfCases = $cases[0]->APP_NUMBER . "-" . $cases[0]->APP_NUMBER;
$search->setRangeCasesFromTo([$rangeOfCases]); $search->setRangeCasesFromTo([$rangeOfCases]);
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result);
}
/**
* Tests the specific filter setCasesNumbers and setRangeCasesFromTo
*
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
* @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView()
* @covers \ProcessMaker\BusinessModel\Cases\Search::filters()
* @covers \ProcessMaker\BusinessModel\Cases\Search::setCasesNumbers()
* @covers \ProcessMaker\BusinessModel\Cases\Search::setRangeCasesFromTo()
* @test
*/
public function it_filter_by_cases_and_range_cases()
{
// Create factories related to the delegation cases
$cases = $this->createSearch();
// Create new Search object
$search = new Search();
$search->setCasesNumbers([$cases[0]->APP_NUMBER]);
$rangeOfCases = $cases[0]->APP_NUMBER . "-" . $cases[0]->APP_NUMBER;
$search->setRangeCasesFromTo([$rangeOfCases]);
$result = $search->getData();
// Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
@@ -144,7 +165,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setProcessId($cases[0]->PRO_ID); $search->setProcessId($cases[0]->PRO_ID);
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
@@ -165,7 +186,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setTaskId($cases[0]->TAS_ID); $search->setTaskId($cases[0]->TAS_ID);
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
@@ -195,6 +216,27 @@ class SearchTest extends TestCase
$this->assertNotEmpty($res); $this->assertNotEmpty($res);
} }
/**
* It tests the getData with setCategoryId
*
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
* @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView()
* @covers \ProcessMaker\BusinessModel\Cases\Search::filters()
* @covers \ProcessMaker\BusinessModel\Cases\Search::setCategoryId()
* @test
*/
public function it_filter_by_category()
{
// Create factories related to the delegation cases
$cases = $this->createSearch();
// Create new Search object
$search = new Search();
$search->setCategoryId(12);
$result = $search->getData();
// Asserts with the result
$this->assertEmpty($result);
}
/** /**
* It tests the getData with user * It tests the getData with user
* *
@@ -212,12 +254,12 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setUserId($cases[0]->USR_ID); $search->setUserId($cases[0]->USR_ID);
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
/** /**
* It tests the getData with user * It tests the getData with setStartCaseFrom and setStartCaseTo
* *
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData() * @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
* @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView()
@@ -236,7 +278,31 @@ class SearchTest extends TestCase
$search->setStartCaseFrom($date); $search->setStartCaseFrom($date);
$search->setStartCaseTo($date); $search->setStartCaseTo($date);
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEmpty($result);
}
/**
* It tests the getData with setFinishCaseFrom and setFinishCaseTo
*
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
* @covers \ProcessMaker\BusinessModel\Cases\Search::getColumnsView()
* @covers \ProcessMaker\BusinessModel\Cases\Search::filters()
* @covers \ProcessMaker\BusinessModel\Cases\Search::setFinishCaseFrom()
* @covers \ProcessMaker\BusinessModel\Cases\Search::setFinishCaseTo()
* @test
*/
public function it_filter_by_finish_date()
{
// Create factories related to the delegation cases
$cases = $this->createSearch();
// Create new Search object
$search = new Search();
$date = date('Y-m-d');
$search->setFinishCaseFrom($date);
$search->setFinishCaseTo($date);
$result = $search->getData();
// Asserts with the result
$this->assertEmpty($result); $this->assertEmpty($result);
} }
@@ -257,7 +323,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setCaseStatuses(['TO_DO']); $search->setCaseStatuses(['TO_DO']);
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }

View File

@@ -7,6 +7,7 @@ use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Supervising; use ProcessMaker\BusinessModel\Cases\Supervising;
use ProcessMaker\Model\Application; use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\GroupUser;
use ProcessMaker\Model\Process; use ProcessMaker\Model\Process;
use ProcessMaker\Model\ProcessUser; use ProcessMaker\Model\ProcessUser;
use ProcessMaker\Model\Task; use ProcessMaker\Model\Task;
@@ -30,19 +31,26 @@ class SupervisingTest extends TestCase
/** /**
* Create supervising cases factories * Create supervising cases factories
* This function define a specific user in the supervisors list
* *
* @param string * @param int $cases
* *
* @return array * @return array
*/ */
public function createSupervising() public function createSupervising(int $cases = 2)
{ {
// Create process // Create process
$process = factory(Process::class)->create(); $process = factory(Process::class)->create();
// Create user // Create user
$user = factory(User::class)->create(); $user = factory(User::class)->create();
// Define this user like process supervisor
factory(ProcessUser::class)->create(
[
'PRO_UID' => $process->PRO_UID,
'USR_UID' => $user->USR_UID,
'PU_TYPE' => 'SUPERVISOR'
]
);
// Create a task // Create a task
$task = factory(Task::class)->create([ $task = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => 'NORMAL', 'TAS_ASSIGN_TYPE' => 'NORMAL',
@@ -54,246 +62,112 @@ class SupervisingTest extends TestCase
'TAS_GROUP_VARIABLE' => '', 'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process->PRO_UID, 'PRO_UID' => $process->PRO_UID,
]); ]);
// Create n cases related to the process
// Create 3 cases $delegation = [];
$app1 = factory(Application::class)->states('todo')->create([ for ($i = 0; $i < $cases; $i = $i + 1) {
'APP_STATUS' => 'TO_DO', // Create case
'APP_STATUS_ID' => 2, $app = factory(Application::class)->states('todo')->create([
'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, 'PRO_UID' => $process->PRO_UID,
'APP_INIT_USER' => $user->USR_UID,
'APP_CUR_USER' => $user->USR_UID,
]);
// Create two threads
$delegation = factory(Delegation::class)->create([
'APP_UID' => $app['APP_UID'],
'TAS_ID' => $task->TAS_ID,
'TAS_UID' => $task->TAS_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_UID' => $user->USR_UID, 'USR_UID' => $user->USR_UID,
'PU_TYPE' => 'SUPERVISOR' 'USR_ID' => $user->USR_ID,
] 'PRO_ID' => $process->PRO_ID,
); 'PRO_UID' => $process->PRO_UID,
'APP_NUMBER' => $app['APP_NUMBER'],
'DEL_INDEX' => 1,
'DEL_PREVIOUS' => 0,
'DEL_LAST_INDEX' => 0
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $app['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' => $app['APP_NUMBER'],
'DEL_INDEX' => 2,
'DEL_PREVIOUS' => 1,
'DEL_LAST_INDEX' => 1
]);
}
return $delegation; return $delegation;
} }
/** /**
* Create many supervising cases for one user * Create supervising cases factories
* * This function define a group user in the supervisors list
* @param int *
* @return object * @param int $cases
*
* @return array
*/ */
public function createMultipleSupervising($cases) public function createGroupSupervising(int $cases = 2)
{ {
$user = factory(\ProcessMaker\Model\User::class)->create(); // Create process
$process = factory(Process::class)->create();
// Create user
$user = factory(User::class)->create();
// Create group
$group = factory(GroupUser::class)->create([
'USR_UID' => $user->USR_UID,
]);
// Define this group like process supervisor
factory(ProcessUser::class)->create(
[
'PRO_UID' => $process->PRO_UID,
'USR_UID' => $group->GRP_UID,
'PU_TYPE' => 'GROUP_SUPERVISOR'
]
);
// 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 n cases related to the process
$delegation = [];
for ($i = 0; $i < $cases; $i = $i + 1) { for ($i = 0; $i < $cases; $i = $i + 1) {
// Create process // Create case
$process = factory(Process::class)->create(); $app = factory(Application::class)->states('todo')->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, 'PRO_UID' => $process->PRO_UID,
'APP_INIT_USER' => $user->USR_UID, 'APP_INIT_USER' => $user->USR_UID,
'APP_CUR_USER' => $user->USR_UID, 'APP_CUR_USER' => $user->USR_UID,
]); ]);
$app2 = factory(Application::class)->states('todo')->create([ // Create two threads
'APP_STATUS' => 'TO_DO', $delegation = factory(Delegation::class)->create([
'APP_STATUS_ID' => 2, 'APP_UID' => $app['APP_UID'],
'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_ID' => $task->TAS_ID,
'TAS_UID' => $task->TAS_UID, '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', 'DEL_THREAD_STATUS' => 'OPEN',
'USR_UID' => $user->USR_UID, 'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID, 'USR_ID' => $user->USR_ID,
'PRO_ID' => $process->PRO_ID, 'PRO_ID' => $process->PRO_ID,
'PRO_UID' => $process->PRO_UID, 'PRO_UID' => $process->PRO_UID,
'APP_NUMBER' => $app1['APP_NUMBER'], 'APP_NUMBER' => $app['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_INDEX' => 1,
'DEL_PREVIOUS' => 0 'DEL_PREVIOUS' => 0,
]); 'DEL_LAST_INDEX' => 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([ $delegation = factory(Delegation::class)->create([
"APP_UID" => $app3['APP_UID'], 'APP_UID' => $app['APP_UID'],
'TAS_ID' => $task2->TAS_ID, 'TAS_ID' => $task2->TAS_ID,
'TAS_UID' => $task2->TAS_UID, 'TAS_UID' => $task2->TAS_UID,
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
@@ -301,21 +175,14 @@ class SupervisingTest extends TestCase
'USR_ID' => $user->USR_ID, 'USR_ID' => $user->USR_ID,
'PRO_ID' => $process->PRO_ID, 'PRO_ID' => $process->PRO_ID,
'PRO_UID' => $process->PRO_UID, 'PRO_UID' => $process->PRO_UID,
'APP_NUMBER' => $app3['APP_NUMBER'], 'APP_NUMBER' => $app['APP_NUMBER'],
'DEL_INDEX' => 2, 'DEL_INDEX' => 2,
'DEL_PREVIOUS' => 1 'DEL_PREVIOUS' => 1,
'DEL_LAST_INDEX' => 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;
return $delegation;
} }
/** /**
@@ -337,8 +204,8 @@ class SupervisingTest extends TestCase
$supervising->setUserId($cases->USR_ID); $supervising->setUserId($cases->USR_ID);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts the result contains 3 registers // Asserts with the result
$this->assertCount(3, $result); $this->assertNotEmpty($result);
} }
/** /**
@@ -360,8 +227,8 @@ class SupervisingTest extends TestCase
$supervising->setUserId($cases->USR_ID); $supervising->setUserId($cases->USR_ID);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts the result contains 3 registers // Asserts with the result
$this->assertCount(3, $result); $this->assertNotEmpty($result);
} }
/** /**
@@ -384,7 +251,7 @@ class SupervisingTest extends TestCase
$supervising->setUserId($user->USR_ID); $supervising->setUserId($user->USR_ID);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts the result // Asserts with the result
$this->assertEmpty($result); $this->assertEmpty($result);
} }
@@ -412,10 +279,8 @@ class SupervisingTest extends TestCase
$supervising->setCaseNumber($cases->APP_NUMBER); $supervising->setCaseNumber($cases->APP_NUMBER);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts the result contains 3 registers // Asserts with the result
$this->assertCount(1, $result); $this->assertNotEmpty($result);
// Asserts that the result contains the app number searched
$this->assertContains($cases->APP_NUMBER, $result[0]);
} }
/** /**
@@ -442,10 +307,8 @@ class SupervisingTest extends TestCase
$supervising->setCasesNumbers([$cases->APP_NUMBER]); $supervising->setCasesNumbers([$cases->APP_NUMBER]);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts the result contains 3 registers // Asserts with the result
$this->assertCount(1, $result); $this->assertNotEmpty($result);
// Asserts that the result contains the app number searched
$this->assertContains($cases->APP_NUMBER, $result[0]);
} }
/** /**
@@ -473,10 +336,39 @@ class SupervisingTest extends TestCase
$supervising->setRangeCasesFromTo([$rangeOfCases]); $supervising->setRangeCasesFromTo([$rangeOfCases]);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts the result contains 3 registers // Asserts with the result
$this->assertCount(1, $result); $this->assertNotEmpty($result);
// Asserts that the result contains the app number searched }
$this->assertContains($cases->APP_NUMBER, $result[0]);
/**
* Tests the specific filter setCasesNumbers and setRangeCasesFromTo
*
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData()
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView()
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters()
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::setUserUid()
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::setUserId()
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::setCasesNumbers()
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::setRangeCasesFromTo()
* @test
*/
public function it_filter_by_cases_and_range_cases()
{
$cases = $this->createSupervising();
// Instance the Supervising object
$supervising = new Supervising();
// Set the user UID
$supervising->setUserUid($cases->USR_UID);
// Set the user ID
$supervising->setUserId($cases->USR_ID);
// Set the range of case numbers
$rangeOfCases = $cases->APP_NUMBER . "-" . $cases->APP_NUMBER;
$supervising->setCasesNumbers([$cases->APP_NUMBER]);
$supervising->setRangeCasesFromTo([$rangeOfCases]);
// Get the data
$result = $supervising->getData();
// Asserts with the result
$this->assertNotEmpty($result);
} }
/** /**
@@ -509,8 +401,8 @@ class SupervisingTest extends TestCase
$supervising->setCaseTitle($title); $supervising->setCaseTitle($title);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts // Asserts with the result
$this->assertCount(1, $result); $this->assertNotEmpty($result);
} }
/** /**
@@ -537,7 +429,8 @@ class SupervisingTest extends TestCase
$supervising->setProcessId($cases['PRO_ID']); $supervising->setProcessId($cases['PRO_ID']);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
$this->assertCount(3, $result); // Asserts with the result
$this->assertNotEmpty($result);
} }
/** /**
@@ -564,7 +457,8 @@ class SupervisingTest extends TestCase
$supervising->setTaskId($cases['TAS_ID']); $supervising->setTaskId($cases['TAS_ID']);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
$this->assertCount(3, $result); // Asserts with the result
$this->assertNotEmpty($result);
} }
/** /**
@@ -591,6 +485,7 @@ class SupervisingTest extends TestCase
$supervising->setCaseStatus('TO_DO'); $supervising->setCaseStatus('TO_DO');
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
@@ -621,7 +516,7 @@ class SupervisingTest extends TestCase
$supervising->setStartCaseTo($date); $supervising->setStartCaseTo($date);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEmpty($result); $this->assertEmpty($result);
} }
@@ -652,7 +547,7 @@ class SupervisingTest extends TestCase
$supervising->setFinishCaseTo($date); $supervising->setFinishCaseTo($date);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// This assert that the expected numbers of results are returned // Asserts with the result
$this->assertEmpty($result); $this->assertEmpty($result);
} }
@@ -687,6 +582,7 @@ class SupervisingTest extends TestCase
$supervising->setOrderByColumn($columnsView[$index]); $supervising->setOrderByColumn($columnsView[$index]);
// Get the data // Get the data
$result = $supervising->getData(); $result = $supervising->getData();
// Asserts with the result
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }
@@ -709,24 +605,27 @@ class SupervisingTest extends TestCase
$supervising->setUserId($cases->USR_ID); $supervising->setUserId($cases->USR_ID);
// Get the data // Get the data
$result = $supervising->getCounter(); $result = $supervising->getCounter();
// Assert the counter // Asserts with the result
$this->assertEquals(3, $result); $this->assertTrue($result > 0 );
} }
/** /**
* It tests the getPagingCounters() method * It tests the getPagingCounters() method
* *
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::getPagingCounters() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getPagingCounters()
* @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters()
* @test * @test
*/ */
public function it_should_test_get_paging_counters_method() public function it_should_test_get_paging_counters_method()
{ {
$cases = $this->createMultipleSupervising(3); $cases = $this->createSupervising(3);
$supervising = new Supervising(); $supervising = new Supervising();
$supervising->setUserId($cases->USR_ID); $supervising->setUserId($cases->USR_ID);
$supervising->setUserUid($cases->USR_UID); $supervising->setUserUid($cases->USR_UID);
$supervising->setCaseUid($cases->APP_UID);
// Get the count // Get the count
$result = $supervising->getPagingCounters(); $result = $supervising->getPagingCounters();
$this->assertEquals(3, $result); // Asserts with the result
$this->assertTrue($result > 0 );
} }
} }