PMCORE-3598
This commit is contained in:
@@ -26,6 +26,7 @@ $factory->define(\ProcessMaker\Model\Process::class, function (Faker $faker) {
|
||||
'PRO_DYNAFORMS' => serialize([]),
|
||||
'PRO_ITEE' => 1,
|
||||
'PRO_ACTION_DONE' => serialize([]),
|
||||
'PRO_SUBPROCESS' => 0,
|
||||
'PRO_CATEGORY' => function () {
|
||||
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_ITEE' => 1,
|
||||
'PRO_ACTION_DONE' => serialize([]),
|
||||
'PRO_SUBPROCESS' => 0,
|
||||
'PRO_CATEGORY' => function () {
|
||||
return factory(\ProcessMaker\Model\ProcessCategory::class)->create()->CATEGORY_UID;
|
||||
},
|
||||
|
||||
@@ -258,8 +258,10 @@ class ProcessTest extends TestCase
|
||||
* It tests the process list
|
||||
*
|
||||
* @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::scopeSubProcess()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_process_without_filter()
|
||||
@@ -278,7 +280,11 @@ class ProcessTest extends TestCase
|
||||
* It tests the process list with specific category
|
||||
*
|
||||
* @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::scopePerUser()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_process_with_category_filter()
|
||||
@@ -288,16 +294,23 @@ class ProcessTest extends TestCase
|
||||
return factory(ProcessCategory::class)->create()->CATEGORY_UID;
|
||||
}
|
||||
]);
|
||||
$result = Process::getProcessesFilter(
|
||||
$process->PRO_CATEGORY
|
||||
);
|
||||
$result = Process::getProcessesFilter($process->PRO_CATEGORY);
|
||||
// Assert with the specific 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
|
||||
*
|
||||
* @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()
|
||||
* @test
|
||||
*/
|
||||
@@ -315,6 +328,9 @@ class ProcessTest extends TestCase
|
||||
* It tests the process list with specific process title
|
||||
*
|
||||
* @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()
|
||||
* @test
|
||||
*/
|
||||
@@ -329,10 +345,41 @@ class ProcessTest extends TestCase
|
||||
$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
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Process::getCounter()
|
||||
* @covers \ProcessMaker\Model\Process::scopePerUser()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_count_process()
|
||||
@@ -346,6 +393,8 @@ class ProcessTest extends TestCase
|
||||
* It test get processes for the new home view
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Process::getProcessesForHome()
|
||||
* @covers \ProcessMaker\Model\Process::scopeCategoryId()
|
||||
* @covers \ProcessMaker\Model\Process::scopeStatus()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_processes_for_home()
|
||||
@@ -356,11 +405,13 @@ class ProcessTest extends TestCase
|
||||
// Create five processes (4 active, 1 inactive)
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'My Process 1',
|
||||
'PRO_CATEGORY' => $processCategory->CATEGORY_UID
|
||||
'PRO_CATEGORY' => $processCategory->CATEGORY_UID,
|
||||
'CATEGORY_ID' => $processCategory->CATEGORY_ID
|
||||
]);
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'My Process 2',
|
||||
'PRO_CATEGORY' => $processCategory->CATEGORY_UID
|
||||
'PRO_CATEGORY' => $processCategory->CATEGORY_UID,
|
||||
'CATEGORY_ID' => $processCategory->CATEGORY_ID
|
||||
]);
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'My Process 3',
|
||||
@@ -376,8 +427,21 @@ class ProcessTest extends TestCase
|
||||
// Assertions
|
||||
$this->assertCount(4, Process::getProcessesForHome());
|
||||
$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(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ class Process extends Model
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $proUid
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeProcess($query, $proUid)
|
||||
@@ -90,6 +91,7 @@ class Process extends Model
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $title
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTitle($query, $title)
|
||||
@@ -102,6 +104,7 @@ class Process extends Model
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $status
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeNoStatus($query, $status = 'DISABLED')
|
||||
@@ -120,6 +123,19 @@ class Process extends Model
|
||||
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
|
||||
*
|
||||
@@ -407,14 +423,14 @@ class Process extends Model
|
||||
* Get all processes, paged optionally, can be sent a string to filter results by "PRO_TITLE"
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $category
|
||||
* @param int $catId
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
* @param bool $paged
|
||||
*
|
||||
* @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
|
||||
$query = Process::query()->select(['PRO_ID', 'PRO_TITLE']);
|
||||
@@ -424,9 +440,9 @@ class Process extends Model
|
||||
$query->title($text);
|
||||
}
|
||||
|
||||
// Set "PRO_CATEGORY" condition if is sent
|
||||
if (!is_null($category)) {
|
||||
$query->category($category);
|
||||
// Set "CATEGORY_ID" condition if is sent
|
||||
if ($catId) {
|
||||
$query->categoryId($catId);
|
||||
}
|
||||
|
||||
// Set "PRO_STATUS" condition
|
||||
@@ -452,6 +468,7 @@ class Process extends Model
|
||||
* Return true if process is active, false otherwise.
|
||||
* @param int|string $proId
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isActive($proId, string $key = 'PRO_ID'): bool
|
||||
|
||||
@@ -889,7 +889,7 @@ class Home extends Api
|
||||
* @url GET /processes
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $category
|
||||
* @param int $category
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
* @param bool $paged
|
||||
@@ -901,7 +901,7 @@ class Home extends Api
|
||||
* @access protected
|
||||
* @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 {
|
||||
return Process::getProcessesForHome($text, $category, $offset, $limit, $paged);
|
||||
|
||||
Reference in New Issue
Block a user