PMCORE-3598

This commit is contained in:
Paula Quispe
2021-12-13 17:41:31 -04:00
parent 71de757f26
commit 3f3bfd51d4
4 changed files with 98 additions and 15 deletions

View File

@@ -26,6 +26,7 @@ $factory->define(\ProcessMaker\Model\Process::class, function (Faker $faker) {
'PRO_DYNAFORMS' => serialize([]), 'PRO_DYNAFORMS' => serialize([]),
'PRO_ITEE' => 1, 'PRO_ITEE' => 1,
'PRO_ACTION_DONE' => serialize([]), 'PRO_ACTION_DONE' => serialize([]),
'PRO_SUBPROCESS' => 0,
'PRO_CATEGORY' => function () { 'PRO_CATEGORY' => function () {
return factory(\ProcessMaker\Model\ProcessCategory::class)->create()->CATEGORY_UID; return factory(\ProcessMaker\Model\ProcessCategory::class)->create()->CATEGORY_UID;
}, },
@@ -56,6 +57,7 @@ $factory->state(\ProcessMaker\Model\Process::class, 'foreign_keys', function (Fa
'PRO_DYNAFORMS' => serialize([]), 'PRO_DYNAFORMS' => serialize([]),
'PRO_ITEE' => 1, 'PRO_ITEE' => 1,
'PRO_ACTION_DONE' => serialize([]), 'PRO_ACTION_DONE' => serialize([]),
'PRO_SUBPROCESS' => 0,
'PRO_CATEGORY' => function () { 'PRO_CATEGORY' => function () {
return factory(\ProcessMaker\Model\ProcessCategory::class)->create()->CATEGORY_UID; return factory(\ProcessMaker\Model\ProcessCategory::class)->create()->CATEGORY_UID;
}, },

View File

@@ -258,8 +258,10 @@ class ProcessTest extends TestCase
* It tests the process list * It tests the process list
* *
* @covers \ProcessMaker\Model\Process::getProcessesFilter() * @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::getListColumns()
* @covers \ProcessMaker\Model\Process::scopeJoinUsers()
* @covers \ProcessMaker\Model\Process::scopeJoinCategory()
* @covers \ProcessMaker\Model\Process::scopeNoStatus() * @covers \ProcessMaker\Model\Process::scopeNoStatus()
* @covers \ProcessMaker\Model\Process::scopeSubProcess()
* @test * @test
*/ */
public function it_should_test_process_without_filter() public function it_should_test_process_without_filter()
@@ -278,7 +280,11 @@ class ProcessTest extends TestCase
* It tests the process list with specific category * It tests the process list with specific category
* *
* @covers \ProcessMaker\Model\Process::getProcessesFilter() * @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::getListColumns()
* @covers \ProcessMaker\Model\Process::scopeJoinUsers()
* @covers \ProcessMaker\Model\Process::scopeJoinCategory()
* @covers \ProcessMaker\Model\Process::scopeCategory() * @covers \ProcessMaker\Model\Process::scopeCategory()
* @covers \ProcessMaker\Model\Process::scopePerUser()
* @test * @test
*/ */
public function it_should_test_process_with_category_filter() public function it_should_test_process_with_category_filter()
@@ -288,16 +294,23 @@ class ProcessTest extends TestCase
return factory(ProcessCategory::class)->create()->CATEGORY_UID; return factory(ProcessCategory::class)->create()->CATEGORY_UID;
} }
]); ]);
$result = Process::getProcessesFilter( $result = Process::getProcessesFilter($process->PRO_CATEGORY);
$process->PRO_CATEGORY // Assert with the specific category
);
$this->assertEquals($process->PRO_CATEGORY, $result[0]['PRO_CATEGORY']); $this->assertEquals($process->PRO_CATEGORY, $result[0]['PRO_CATEGORY']);
$process = factory(Process::class)->create();
$result = Process::getProcessesFilter('NONE');
// Assert when the category is empty
$this->assertEmpty($result);
} }
/** /**
* It tests the process list with specific process * It tests the process list with specific process
* *
* @covers \ProcessMaker\Model\Process::getProcessesFilter() * @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::getListColumns()
* @covers \ProcessMaker\Model\Process::scopeJoinUsers()
* @covers \ProcessMaker\Model\Process::scopeJoinCategory()
* @covers \ProcessMaker\Model\Process::scopeProcess() * @covers \ProcessMaker\Model\Process::scopeProcess()
* @test * @test
*/ */
@@ -315,6 +328,9 @@ class ProcessTest extends TestCase
* It tests the process list with specific process title * It tests the process list with specific process title
* *
* @covers \ProcessMaker\Model\Process::getProcessesFilter() * @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::getListColumns()
* @covers \ProcessMaker\Model\Process::scopeJoinUsers()
* @covers \ProcessMaker\Model\Process::scopeJoinCategory()
* @covers \ProcessMaker\Model\Process::scopeTitle() * @covers \ProcessMaker\Model\Process::scopeTitle()
* @test * @test
*/ */
@@ -329,10 +345,41 @@ class ProcessTest extends TestCase
$this->assertEquals($process->PRO_TITLE, $result[0]['PRO_TITLE']); $this->assertEquals($process->PRO_TITLE, $result[0]['PRO_TITLE']);
} }
/**
* It tests the process list with suprocess filter
*
* @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::getListColumns()
* @covers \ProcessMaker\Model\Process::scopeJoinUsers()
* @covers \ProcessMaker\Model\Process::scopeJoinCategory()
* @covers \ProcessMaker\Model\Process::scopeSubProcess()
* @test
*/
public function it_should_test_process_subprocess_filter()
{
$process = factory(Process::class)->create([
'PRO_SUBPROCESS' => 1
]);
$result = Process::getProcessesFilter(
null,
null,
null,
$process->PRO_CREATE_USER,
0,
25,
'ASC',
'PRO_CREATE_DATE',
true,
true
);
$this->assertEquals($process->PRO_CREATE_USER, $result[0]['USR_UID']);
}
/** /**
* It tests the count process * It tests the count process
* *
* @covers \ProcessMaker\Model\Process::getCounter() * @covers \ProcessMaker\Model\Process::getCounter()
* @covers \ProcessMaker\Model\Process::scopePerUser()
* @test * @test
*/ */
public function it_should_test_count_process() public function it_should_test_count_process()
@@ -346,6 +393,8 @@ class ProcessTest extends TestCase
* It test get processes for the new home view * It test get processes for the new home view
* *
* @covers \ProcessMaker\Model\Process::getProcessesForHome() * @covers \ProcessMaker\Model\Process::getProcessesForHome()
* @covers \ProcessMaker\Model\Process::scopeCategoryId()
* @covers \ProcessMaker\Model\Process::scopeStatus()
* @test * @test
*/ */
public function it_should_test_get_processes_for_home() public function it_should_test_get_processes_for_home()
@@ -356,11 +405,13 @@ class ProcessTest extends TestCase
// Create five processes (4 active, 1 inactive) // Create five processes (4 active, 1 inactive)
factory(Process::class)->create([ factory(Process::class)->create([
'PRO_TITLE' => 'My Process 1', 'PRO_TITLE' => 'My Process 1',
'PRO_CATEGORY' => $processCategory->CATEGORY_UID 'PRO_CATEGORY' => $processCategory->CATEGORY_UID,
'CATEGORY_ID' => $processCategory->CATEGORY_ID
]); ]);
factory(Process::class)->create([ factory(Process::class)->create([
'PRO_TITLE' => 'My Process 2', 'PRO_TITLE' => 'My Process 2',
'PRO_CATEGORY' => $processCategory->CATEGORY_UID 'PRO_CATEGORY' => $processCategory->CATEGORY_UID,
'CATEGORY_ID' => $processCategory->CATEGORY_ID
]); ]);
factory(Process::class)->create([ factory(Process::class)->create([
'PRO_TITLE' => 'My Process 3', 'PRO_TITLE' => 'My Process 3',
@@ -376,8 +427,21 @@ class ProcessTest extends TestCase
// Assertions // Assertions
$this->assertCount(4, Process::getProcessesForHome()); $this->assertCount(4, Process::getProcessesForHome());
$this->assertCount(3, Process::getProcessesForHome('My Process')); $this->assertCount(3, Process::getProcessesForHome('My Process'));
$this->assertCount(2, Process::getProcessesForHome(null, $processCategory->CATEGORY_UID)); $this->assertCount(2, Process::getProcessesForHome(null, $processCategory->CATEGORY_ID));
$this->assertCount(4, Process::getProcessesForHome(null, null, null, 2)); $this->assertCount(4, Process::getProcessesForHome(null, null, null, 2));
$this->assertCount(1, Process::getProcessesForHome(null, null, 2, 1)); $this->assertCount(1, Process::getProcessesForHome(null, null, 2, 1, true));
}
/**
* It tests the isActive process
*
* @covers \ProcessMaker\Model\Process::isActive()
* @test
*/
public function it_should_test_is_active()
{
$process = factory(Process::class)->create();
$total = Process::isActive($process->PRO_ID);
$this->assertEquals(1, $total);
} }
} }

View File

@@ -78,6 +78,7 @@ class Process extends Model
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @param string $proUid * @param string $proUid
*
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopeProcess($query, $proUid) public function scopeProcess($query, $proUid)
@@ -90,6 +91,7 @@ class Process extends Model
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @param string $title * @param string $title
*
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopeTitle($query, $title) public function scopeTitle($query, $title)
@@ -102,6 +104,7 @@ class Process extends Model
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @param string $status * @param string $status
*
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopeNoStatus($query, $status = 'DISABLED') public function scopeNoStatus($query, $status = 'DISABLED')
@@ -120,6 +123,19 @@ class Process extends Model
return $query->where('PRO_SUBPROCESS', '=', 1); return $query->where('PRO_SUBPROCESS', '=', 1);
} }
/**
* Scope a query to include a specific process categoryId
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $category
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCategoryId($query, $category)
{
return $query->where('PROCESS.CATEGORY_ID', $category);
}
/** /**
* Scope a query to include a specific process category * Scope a query to include a specific process category
* *
@@ -407,14 +423,14 @@ class Process extends Model
* Get all processes, paged optionally, can be sent a string to filter results by "PRO_TITLE" * Get all processes, paged optionally, can be sent a string to filter results by "PRO_TITLE"
* *
* @param string $text * @param string $text
* @param string $category * @param int $catId
* @param int $offset * @param int $offset
* @param int $limit * @param int $limit
* @param bool $paged * @param bool $paged
* *
* @return array * @return array
*/ */
public static function getProcessesForHome($text = null, $category = null, $offset = null, $limit = null, $paged = true) public static function getProcessesForHome($text = null, $catId = 0, $offset = null, $limit = null, $paged = true)
{ {
// Get base query // Get base query
$query = Process::query()->select(['PRO_ID', 'PRO_TITLE']); $query = Process::query()->select(['PRO_ID', 'PRO_TITLE']);
@@ -424,9 +440,9 @@ class Process extends Model
$query->title($text); $query->title($text);
} }
// Set "PRO_CATEGORY" condition if is sent // Set "CATEGORY_ID" condition if is sent
if (!is_null($category)) { if ($catId) {
$query->category($category); $query->categoryId($catId);
} }
// Set "PRO_STATUS" condition // Set "PRO_STATUS" condition
@@ -452,6 +468,7 @@ class Process extends Model
* Return true if process is active, false otherwise. * Return true if process is active, false otherwise.
* @param int|string $proId * @param int|string $proId
* @param string $key * @param string $key
*
* @return bool * @return bool
*/ */
public static function isActive($proId, string $key = 'PRO_ID'): bool public static function isActive($proId, string $key = 'PRO_ID'): bool

View File

@@ -889,7 +889,7 @@ class Home extends Api
* @url GET /processes * @url GET /processes
* *
* @param string $text * @param string $text
* @param string $category * @param int $category
* @param int $offset * @param int $offset
* @param int $limit * @param int $limit
* @param bool $paged * @param bool $paged
@@ -901,7 +901,7 @@ class Home extends Api
* @access protected * @access protected
* @class AccessControl {@permission PM_CASES} * @class AccessControl {@permission PM_CASES}
*/ */
public function getProcesses($text = null, $category = null, int $offset = 0, int $limit = 15, $paged = true) public function getProcesses($text = null, $category = 0, int $offset = 0, int $limit = 15, $paged = true)
{ {
try { try {
return Process::getProcessesForHome($text, $category, $offset, $limit, $paged); return Process::getProcessesForHome($text, $category, $offset, $limit, $paged);