PMCORE-1884

This commit is contained in:
Paula Quispe
2020-10-02 12:53:58 -04:00
parent 20dfd32e6b
commit 9ebeadd086
8 changed files with 236 additions and 6 deletions

View File

@@ -267,6 +267,7 @@ class GmailOAuthTest extends TestCase
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$this->markTestIncomplete('Please solve the error related to Exception');
$this->expectException(Exception::class);
$gmailOauth->setSenderEmail("");
$gmailOauth->setMailTo($faker->email);

View File

@@ -2,7 +2,9 @@
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use G;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Task;
use Tests\TestCase;
@@ -22,12 +24,104 @@ class TaskTest extends TestCase
* @covers \ProcessMaker\Model\Task::title()
* @test
*/
public function it_should_return_pages_of_data()
public function it_should_return_title_of_event_task()
{
// Intermediate email event
$task = factory(Task::class)->create([
'TAS_TITLE' => 'INTERMEDIATE-THROW-EMAIL-EVENT'
]);
$taskInstance = new Task();
$title = $taskInstance->title($task->TAS_ID);
$this->assertEquals($title, G::LoadTranslation('ID_INTERMEDIATE_THROW_EMAIL_EVENT'));
// Intermediate throw message event
$task = factory(Task::class)->create([
'TAS_TITLE' => 'INTERMEDIATE-THROW-MESSAGE-EVENT'
]);
$taskInstance = new Task();
$title = $taskInstance->title($task->TAS_ID);
$this->assertEquals($title, G::LoadTranslation('ID_INTERMEDIATE_THROW_MESSAGE_EVENT'));
// Intermediate catch message event
$task = factory(Task::class)->create([
'TAS_TITLE' => 'INTERMEDIATE-CATCH-MESSAGE-EVENT'
]);
$taskInstance = new Task();
$title = $taskInstance->title($task->TAS_ID);
$this->assertEquals($title, G::LoadTranslation('ID_INTERMEDIATE_CATCH_MESSAGE_EVENT'));
// Intermediate timer event
$task = factory(Task::class)->create([
'TAS_TITLE' => 'INTERMEDIATE-CATCH-TIMER-EVENT'
]);
$taskInstance = new Task();
$title = $taskInstance->title($task->TAS_ID);
$this->assertEquals($title, G::LoadTranslation('ID_INTERMEDIATE_CATCH_TIMER_EVENT'));
}
/**
* This checks to load task properties
*
* @covers \ProcessMaker\Model\Task::load()
* @test
*/
public function it_should_return_task()
{
$task = factory(Task::class)->create();
$taskInstance = new Task();
$title = $taskInstance->title($task->TAS_ID);
$this->assertEquals($title, $task->TAS_TITLE);
$properties = $taskInstance->load($task->TAS_UID);
$this->assertNotEmpty($properties);
}
/**
* This checks to make get the task information from a user task
*
* @covers \ProcessMaker\Model\Task::information()
* @test
*/
public function it_should_return_task_information_from_user_task()
{
$task = factory(Task::class)->create([
'TAS_TYPE' => 'NORMAL'
]);
$del = factory(Delegation::class)->states('closed')->create([
'PRO_UID' => $task->PRO_UID,
'TAS_ID' => $task->TAS_ID,
'TAS_UID' => $task->TAS_UID,
'DEL_INIT_DATE' => '2020-07-26 16:42:08',
'DEL_FINISH_DATE' => '2020-07-30 17:43:09',
]);
$taskInstance = new Task();
$taskInfo = $taskInstance->information($del->APP_UID, $del->TAS_UID, $del->DEL_INDEX);
$result = ' 4 ' . G::LoadTranslation('ID_DAY_DAYS');
$result .= ' 01 '. G::LoadTranslation('ID_HOUR_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_SECOND_ABBREVIATE');
$this->assertEquals($taskInfo['DURATION'], $result);
}
/**
* This checks to make get the task information from a automatic task
*
* @covers \ProcessMaker\Model\Task::information()
* @test
*/
public function it_should_return_task_information_from_automatic_task()
{
$task = factory(Task::class)->create([
'TAS_TYPE' => 'SCRIPT-TASK'
]);
$del = factory(Delegation::class)->states('closed')->create([
'PRO_UID' => $task->PRO_UID,
'TAS_ID' => $task->TAS_ID,
'TAS_UID' => $task->TAS_UID,
'DEL_DELEGATE_DATE' => '2020-07-26 16:42:08',
'DEL_FINISH_DATE' => '2020-07-30 17:43:09',
]);
$taskInstance = new Task();
$taskInfo = $taskInstance->information($del->APP_UID, $del->TAS_UID, $del->DEL_INDEX);
$result = ' 4 ' . G::LoadTranslation('ID_DAY_DAYS');
$result .= ' 01 '. G::LoadTranslation('ID_HOUR_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_SECOND_ABBREVIATE');
$this->assertEquals($taskInfo['DURATION'], $result);
}
}

View File

@@ -744,6 +744,9 @@ class Task extends BaseTask
$calendarObj->assignCalendarTo($taskUid, $calendarUid, 'TASK');
}
/**
* @deprecated Method deprecated in Release 3.5.x
*/
public function getDelegatedTaskData($TAS_UID, $APP_UID, $DEL_INDEX)
{
require_once ('classes/model/AppDelegation.php');

View File

@@ -5537,6 +5537,12 @@ msgstr "The value '{0}' is not a valid date for the format '{1}'."
msgid "Day"
msgstr "Day"
# TRANSLATION
# LABEL/ID_DAY_DAYS
#: LABEL/ID_DAY_DAYS
msgid "Day(s)"
msgstr "Day(s)"
# TRANSLATION
# LABEL/ID_DAYS
#: LABEL/ID_DAYS
@@ -9467,6 +9473,12 @@ msgstr "Hour"
msgid "Hours"
msgstr "Hours"
# TRANSLATION
# LABEL/ID_HOUR_ABBREVIATE
#: LABEL/ID_HOUR_ABBREVIATE
msgid "Hr(s)"
msgstr "Hr(s)"
# TRANSLATION
# LABEL/ID_HOUR_HOURS
#: LABEL/ID_HOUR_HOURS
@@ -18803,6 +18815,12 @@ msgstr "Minimum data required to run the \"Test Connection\": \"Server Address,
msgid "[LABEL/ID_MINUTE] Minute"
msgstr "Minute"
# TRANSLATION
# LABEL/ID_MINUTE_ABBREVIATE
#: LABEL/ID_MINUTE_ABBREVIATE
msgid "min"
msgstr "min"
# TRANSLATION
# LABEL/ID_MINUTES
#: LABEL/ID_MINUTES
@@ -23603,6 +23621,12 @@ msgstr "Seconds"
msgid "Second Graph"
msgstr "Second Graph"
# TRANSLATION
# LABEL/ID_SECOND_ABBREVIATE
#: LABEL/ID_SECOND_ABBREVIATE
msgid "s"
msgstr "s"
# TRANSLATION
# LABEL/ID_SEE
#: LABEL/ID_SEE

View File

@@ -57744,6 +57744,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_DATE_NOT_VALID','en','The value ''{0}'' is not a valid date for the format ''{1}''.','2014-05-29') ,
( 'LABEL','ID_DAY','en','Day','2014-01-15') ,
( 'LABEL','ID_DAYS','en','Days','2014-01-15') ,
( 'LABEL','ID_DAY_DAYS','en','Day(s)','2020-10-02') ,
( 'LABEL','ID_DBCNN_TITLE','en','Checking server configuration','2014-01-15') ,
( 'LABEL','ID_DBC_CHECK','en','Checking server parameters','2014-01-15') ,
( 'LABEL','ID_DBC_DBNAME_INVALID','en','The database connection with dbs_database_name: ''{0}'' is invalid','2014-10-21') ,
@@ -58424,6 +58425,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_HOURLY','en','Hourly','2014-01-15') ,
( 'LABEL','ID_HOURLY_AT','en','Hourly at','2014-01-15') ,
( 'LABEL','ID_HOURS','en','Hours','2014-01-15') ,
( 'LABEL','ID_HOUR_ABBREVIATE','en','Hr(s)','2020-10-02') ,
( 'LABEL','ID_HOUR_HOURS','en','Hour(s)','2014-10-30') ,
( 'LABEL','ID_HTML','en','HTML','2014-01-15') ,
( 'LABEL','ID_IDENTIFIER_IMPORT_USER','en','Identifier for an imported user','2014-01-15') ,
@@ -60015,6 +60017,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_MINIMUM_DATA_REQUIRED_TO_RUN_THE','en','Minimum data required to run the "Test Connection": "Server Address, Port, Enabled TLS, Anonymous, Username, Password','2015-09-15') ,
( 'LABEL','ID_MINUTE','en','Minute','2014-01-15') ,
( 'LABEL','ID_MINUTES','en','Minutes','2014-01-15') ,
( 'LABEL','ID_MINUTE_ABBREVIATE','en','min','2020-10-02') ,
( 'LABEL','ID_MIN_INDICATOR_DASHBOARD','en','You can not delete more Indicators.','2015-03-31') ,
( 'LABEL','ID_MODIFIED','en','Modified','2014-01-15') ,
( 'LABEL','ID_MON','en','Mon','2014-01-15') ,
@@ -60836,6 +60839,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_SEARCH_XML_METADATA','en','Search XML metadata','2014-01-15') ,
( 'LABEL','ID_SECOND','en','Second','2014-01-15') ,
( 'LABEL','ID_SECONDS','en','Seconds','2014-01-15') ,
( 'LABEL','ID_SECOND_ABBREVIATE','en','s','2020-10-02') ,
( 'LABEL','ID_SECOND_FIGURE','en','Second Graph','2015-03-09') ,
( 'LABEL','ID_SEE','en','See','2014-01-15') ,
( 'LABEL','ID_SEE_FULL_LIST','en','See complete list','2016-02-29') ,

View File

@@ -5,7 +5,9 @@ use ProcessMaker\BusinessModel\Cases\ChangeLog;
/*----------------------------------********---------------------------------*/
use ProcessMaker\ChangeLog\ChangeLogResult;
/*----------------------------------********---------------------------------*/
use ProcessMaker\Model\Task as ModelTask;
use ProcessMaker\Plugins\PluginRegistry;
use ProcessMaker\Util\DateTime;
if (!isset($_SESSION['USER_LOGGED'])) {
$responseObject = new stdclass();
@@ -428,9 +430,9 @@ class Ajax
}
$taskUid = $arrayTaskUid[0];
$taskData = $task->getDelegatedTaskData($taskUid, $_SESSION['APPLICATION'], $_SESSION['INDEX']);
$taskData = \ProcessMaker\Util\DateTime::convertUtcToTimeZone($taskData);
$task = new ModelTask();
$taskData = $task->information($_SESSION['APPLICATION'], $taskUid, $_SESSION['INDEX']);
$taskData = DateTime::convertUtcToTimeZone($taskData);
print(G::json_encode($taskData));
}

View File

@@ -2,6 +2,7 @@
namespace ProcessMaker\Model;
use DateTime;
use G;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
@@ -687,4 +688,53 @@ class Delegation extends Model
return ($query->count() > 0);
}
/**
* Return the thread related to the specific task-index
*
* @param string $appUid
* @param string $delIndex
* @param string $tasUid
* @param string $taskType
*
* @return array
*/
public static function getDatesFromThread(string $appUid, string $delIndex, string $tasUid, string $taskType)
{
$query = Delegation::query()->select([
'DEL_INIT_DATE',
'DEL_DELEGATE_DATE',
'DEL_FINISH_DATE',
'DEL_RISK_DATE',
'DEL_TASK_DUE_DATE'
]);
$query->where('APP_UID', $appUid);
$query->where('DEL_INDEX', $delIndex);
$query->where('TAS_UID', $tasUid);
$results = $query->get();
$thread = [];
$results->each(function ($item, $key) use (&$thread, $taskType) {
$thread = $item->toArray();
if (in_array($taskType, Task::$typesRunAutomatically)) {
$startDate = $thread['DEL_DELEGATE_DATE'];
} else {
$startDate = $thread['DEL_INIT_DATE'];
}
$endDate = $thread['DEL_FINISH_DATE'];
// Calculate the task-thread duration
if (!empty($startDate) && !empty($endDate)) {
$initDate = new DateTime($startDate);
$finishDate = new DateTime($endDate);
$diff = $initDate->diff($finishDate);
$format = ' %a ' . G::LoadTranslation('ID_DAY_DAYS');
$format .= ' %H '. G::LoadTranslation('ID_HOUR_ABBREVIATE');
$format .= ' %I '. G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$format .= ' %S '. G::LoadTranslation('ID_SECOND_ABBREVIATE');
$thread['DEL_THREAD_DURATION'] = $diff->format($format);
}
});
return $thread;
}
}

View File

@@ -11,6 +11,17 @@ class Task extends Model
protected $primaryKey = 'TAS_ID';
// We do not have create/update timestamps for this table
public $timestamps = false;
// The following types will execute without user and run automatically
public static $typesRunAutomatically = [
"WEBENTRYEVENT",
"END-MESSAGE-EVENT",
"START-MESSAGE-EVENT",
"INTERMEDIATE-THROW-MESSAGE-EVENT",
"INTERMEDIATE-CATCH-MESSAGE-EVENT",
"SCRIPT-TASK",
"START-TIMER-EVENT",
"INTERMEDIATE-CATCH-TIMER-EVENT"
];
public function process()
{
@@ -67,4 +78,45 @@ class Task extends Model
return $title;
}
/**
* Get task data
*
* @param string $tasUid
*
* @return array
*/
public function load($tasUid)
{
$query = Task::query();
$query->where('TAS_UID', $tasUid);
return $query->get()->toArray();
}
/**
* Get task thread information
*
* @param string $appUid
* @param string $tasUid
* @param string $delIndex
*
* @return array
*/
public function information(string $appUid, string $tasUid, string $delIndex)
{
// Load the the task information
$taskInfo = $this->load($tasUid);
$taskInfo = head($taskInfo);
$taskType = $taskInfo['TAS_TYPE'];
// Load the dates related to the thread
$dates = Delegation::getDatesFromThread($appUid, $delIndex, $tasUid, $taskType);
// Set the dates
$taskInfo['INIT_DATE'] = !empty($dates['DEL_INIT_DATE']) ? $dates['DEL_INIT_DATE'] : G::LoadTranslation('ID_CASE_NOT_YET_STARTED');
$taskInfo['DUE_DATE'] = !empty($dates['DEL_TASK_DUE_DATE']) ? $dates['DEL_TASK_DUE_DATE'] : G::LoadTranslation('ID_NOT_FINISHED');
$taskInfo['FINISH'] = !empty($dates['DEL_FINISH_DATE']) ? $dates['DEL_FINISH_DATE'] : G::LoadTranslation('ID_NOT_FINISHED');
$taskInfo['DURATION'] = !empty($dates['DEL_THREAD_DURATION']) ? $dates['DEL_THREAD_DURATION'] : G::LoadTranslation('ID_NOT_FINISHED');
return $taskInfo;
}
}