Merged in bugfix/PMC-370 (pull request #7068)
PMC-370 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
commit
016ffdf905
16
database/factories/AppThreadFactory.php
Normal file
16
database/factories/AppThreadFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Model factory for a APP_THREAD
|
||||
*/
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
$factory->define(\ProcessMaker\Model\AppThread::class, function (Faker $faker) {
|
||||
return [
|
||||
'APP_UID' => G::generateUniqueID(),
|
||||
'APP_THREAD_INDEX' => $faker->unique()->numberBetween(1, 2000),
|
||||
'APP_THREAD_PARENT' => $faker->unique()->numberBetween(1, 2000),
|
||||
'APP_THREAD_STATUS' => $faker->randomElement(['OPEN', 'CLOSED']),
|
||||
'DEL_INDEX' => $faker->unique()->numberBetween(1, 2000)
|
||||
];
|
||||
});
|
||||
@@ -4,6 +4,8 @@ use App\Jobs\EmailEvent;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\AppThread;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\EmailServer;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\Task;
|
||||
@@ -12,7 +14,6 @@ use Tests\TestCase;
|
||||
|
||||
class WsBaseTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor of the class.
|
||||
*
|
||||
@@ -32,6 +33,9 @@ class WsBaseTest extends TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Application::query()->truncate();
|
||||
AppThread::query()->truncate();
|
||||
Delegation::query()->truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,4 +470,146 @@ class WsBaseTest extends TestCase
|
||||
$wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType);
|
||||
Queue::assertNotPushed(EmailEvent::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the casesList method returns the case title value
|
||||
*
|
||||
* @test
|
||||
* @covers \WsBase::caseList
|
||||
*/
|
||||
public function it_should_test_that_the_cases_list_method_returns_the_case_title()
|
||||
{
|
||||
//Create the user factory
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
//Create the application factory
|
||||
$application1 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'TO_DO',
|
||||
'APP_TITLE' => 'Title1'
|
||||
]
|
||||
);
|
||||
$application2 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'DRAFT',
|
||||
'APP_TITLE' => 'Title2'
|
||||
]
|
||||
);
|
||||
|
||||
//Create the delegation factory
|
||||
$delegation1 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application1->APP_NUMBER
|
||||
]
|
||||
);
|
||||
$delegation2 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application2->APP_NUMBER
|
||||
]
|
||||
);
|
||||
|
||||
//Create app thread factory
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation1->APP_UID
|
||||
]
|
||||
);
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation2->APP_UID
|
||||
]
|
||||
);
|
||||
|
||||
//Instance the object
|
||||
$wsBase = new WsBase();
|
||||
//Call the caseList method
|
||||
$res = $wsBase->caseList($user->USR_UID);
|
||||
|
||||
//Assert the result has 2 rows
|
||||
$this->assertCount(2, $res);
|
||||
|
||||
//Assert the status of the case
|
||||
$this->assertTrue('TO_DO' || 'DRAFT' == $res[0]['status']);
|
||||
$this->assertTrue('TO_DO' || 'DRAFT' == $res[1]['status']);
|
||||
|
||||
//Assert the case title is returned
|
||||
$this->assertTrue($application1->APP_TITLE || $application2->APP_TITLE == $res[0]['name']);
|
||||
$this->assertTrue($application1->APP_TITLE || $application2->APP_TITLE == $res[1]['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the casesList method when the result is empty
|
||||
*
|
||||
* @test
|
||||
* @covers \WsBase::caseList
|
||||
*/
|
||||
public function it_should_test_the_cases_list_method_when_there_are_no_results()
|
||||
{
|
||||
//Create the user factory
|
||||
$user1 = factory(User::class)->create();
|
||||
$user2 = factory(User::class)->create();
|
||||
|
||||
//Create the application factory
|
||||
$application1 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'TO_DO',
|
||||
'APP_TITLE' => 'Title1'
|
||||
]
|
||||
);
|
||||
$application2 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'DRAFT',
|
||||
'APP_TITLE' => 'Title2'
|
||||
]
|
||||
);
|
||||
|
||||
//Create the delegation factory
|
||||
$delegation1 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user1->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application1->APP_NUMBER
|
||||
]
|
||||
);
|
||||
$delegation2 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user1->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application2->APP_NUMBER
|
||||
]
|
||||
);
|
||||
|
||||
//Create app thread factory
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation1->APP_UID
|
||||
]
|
||||
);
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation2->APP_UID
|
||||
]
|
||||
);
|
||||
|
||||
//Instance the object
|
||||
$wsBase = new WsBase();
|
||||
|
||||
//Call the caseList method
|
||||
$res = $wsBase->caseList($user2->USR_UID);
|
||||
|
||||
//Assert the result his empty
|
||||
$this->assertEmpty($res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use ProcessMaker\ChangeLog\ChangeLog;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
use ProcessMaker\Core\JobsManager;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Util\WsMessageResponse;
|
||||
|
||||
class WsBase
|
||||
@@ -477,54 +478,48 @@ class WsBase
|
||||
return $arrayData;
|
||||
}
|
||||
} else {
|
||||
$arrayData = [];
|
||||
$data = [];
|
||||
|
||||
$criteria = new Criteria("workflow");
|
||||
$selectedColumns = [
|
||||
'APP_DELEGATION.APP_UID',
|
||||
'APP_DELEGATION.DEL_INDEX',
|
||||
'APP_DELEGATION.APP_NUMBER',
|
||||
'APPLICATION.APP_STATUS',
|
||||
'APPLICATION.APP_TITLE',
|
||||
'APP_DELEGATION.PRO_UID'
|
||||
];
|
||||
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::APP_UID);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::DEL_INDEX);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::APP_NUMBER);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::APP_STATUS);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::PRO_UID);
|
||||
$query = Delegation::query()->select($selectedColumns);
|
||||
$query->join('APPLICATION', function ($join) {
|
||||
$join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
|
||||
});
|
||||
$query->join('APP_THREAD', function ($join) {
|
||||
$join->on('APP_THREAD.APP_UID', '=', 'APP_DELEGATION.APP_UID');
|
||||
});
|
||||
$query->where('APP_DELEGATION.USR_UID', $userUid);
|
||||
$query->whereNested(function ($query) {
|
||||
$query->where('APPLICATION.APP_STATUS', 'TO_DO');
|
||||
$query->orWhere('APPLICATION.APP_STATUS', 'DRAFT');
|
||||
});
|
||||
$query->whereNull('APP_DELEGATION.DEL_FINISH_DATE');
|
||||
$query->where('APP_DELEGATION.DEL_THREAD_STATUS', 'OPEN');
|
||||
$query->where('APP_THREAD.APP_THREAD_STATUS', 'OPEN');
|
||||
$query->orderBy('APP_DELEGATION.APP_NUMBER', 'DESC');
|
||||
|
||||
$criteria->add(AppCacheViewPeer::USR_UID, $userUid);
|
||||
$result = $query->get();
|
||||
$data2 = $result->values()->toArray();
|
||||
$aux = [];
|
||||
|
||||
$criteria->add(
|
||||
//ToDo - getToDo()
|
||||
$criteria->getNewCriterion(AppCacheViewPeer::APP_STATUS, "TO_DO", CRITERIA::EQUAL)->addAnd(
|
||||
$criteria->getNewCriterion(AppCacheViewPeer::DEL_FINISH_DATE, null, Criteria::ISNULL)
|
||||
)->addAnd(
|
||||
$criteria->getNewCriterion(AppCacheViewPeer::APP_THREAD_STATUS, "OPEN")
|
||||
)->addAnd(
|
||||
$criteria->getNewCriterion(AppCacheViewPeer::DEL_THREAD_STATUS, "OPEN")
|
||||
)
|
||||
)->addOr(
|
||||
//Draft - getDraft()
|
||||
$criteria->getNewCriterion(AppCacheViewPeer::APP_STATUS, "DRAFT", CRITERIA::EQUAL)->addAnd(
|
||||
$criteria->getNewCriterion(AppCacheViewPeer::APP_THREAD_STATUS, "OPEN")
|
||||
)->addAnd(
|
||||
$criteria->getNewCriterion(AppCacheViewPeer::DEL_THREAD_STATUS, "OPEN")
|
||||
)
|
||||
);
|
||||
|
||||
$criteria->addDescendingOrderByColumn(AppCacheViewPeer::APP_NUMBER);
|
||||
|
||||
$rsCriteria = AppCacheViewPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayData[] = array(
|
||||
"guid" => $row["APP_UID"],
|
||||
"name" => $row["APP_NUMBER"],
|
||||
"status" => $row["APP_STATUS"],
|
||||
"delIndex" => $row["DEL_INDEX"],
|
||||
"processId" => $row["PRO_UID"]
|
||||
);
|
||||
foreach ($data2 as $value) {
|
||||
$aux['guid'] = $value['APP_UID'];
|
||||
$aux['name'] = $value['APP_TITLE'];
|
||||
$aux['status'] = $value['APP_STATUS'];
|
||||
$aux['delIndex'] = $value['DEL_INDEX'];
|
||||
$aux['processId'] = $value['PRO_UID'];
|
||||
array_push($data, $aux);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
return $data;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$arrayData = [];
|
||||
|
||||
12
workflow/engine/src/ProcessMaker/Model/AppThread.php
Normal file
12
workflow/engine/src/ProcessMaker/Model/AppThread.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AppThread extends Model
|
||||
{
|
||||
protected $table = 'APP_THREAD';
|
||||
// We do not have create/update timestamps for this table
|
||||
public $timestamps = false;
|
||||
}
|
||||
Reference in New Issue
Block a user