Merged in bugfix/PMCORE-1487 (pull request #7346)
PMCORE-1487 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
40
database/factories/AppNotesFactory.php
Normal file
40
database/factories/AppNotesFactory.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
$factory->define(\ProcessMaker\Model\AppNotes::class, function (Faker $faker) {
|
||||
return [
|
||||
'APP_UID' => G::generateUniqueID(),
|
||||
'USR_UID' => G::generateUniqueID(),
|
||||
'NOTE_DATE' => $faker->dateTime(),
|
||||
'NOTE_CONTENT' => $faker->sentence(3),
|
||||
'NOTE_TYPE' => 'USER',
|
||||
'NOTE_AVAILABILITY' => 'PUBLIC',
|
||||
'NOTE_ORIGIN_OBJ' => '',
|
||||
'NOTE_AFFECTED_OBJ1' => '',
|
||||
'NOTE_AFFECTED_OBJ2' => '',
|
||||
'NOTE_RECIPIENTS' => '',
|
||||
];
|
||||
});
|
||||
|
||||
// Create a case notes with the foreign keys
|
||||
$factory->state(\ProcessMaker\Model\AppNotes::class, 'foreign_keys', function (Faker $faker) {
|
||||
// Create values in the foreign key relations
|
||||
$application = factory(\ProcessMaker\Model\Application::class)->create();
|
||||
$user = factory(\ProcessMaker\Model\User::class)->create();
|
||||
|
||||
// Return with default values
|
||||
return [
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'NOTE_DATE' => $faker->dateTime(),
|
||||
'NOTE_CONTENT' => $faker->sentence(3),
|
||||
'NOTE_TYPE' => 'USER',
|
||||
'NOTE_AVAILABILITY' => 'PUBLIC',
|
||||
'NOTE_ORIGIN_OBJ' => '',
|
||||
'NOTE_AFFECTED_OBJ1' => '',
|
||||
'NOTE_AFFECTED_OBJ2' => '',
|
||||
'NOTE_RECIPIENTS' => '',
|
||||
];
|
||||
});
|
||||
|
||||
104
tests/unit/workflow/engine/classes/model/AppNotesTest.php
Normal file
104
tests/unit/workflow/engine/classes/model/AppNotesTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\classes\model;
|
||||
|
||||
use AppNotes as ModelAppNotes;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\AppMessage;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\AppNotes;
|
||||
use ProcessMaker\Model\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AppNotesTest
|
||||
*
|
||||
* @coversDefaultClass AppNotes
|
||||
*/
|
||||
class AppNotesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* It test the cases notes creation
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_test_case_notes_creation()
|
||||
{
|
||||
$application = factory(Application::class)->create();
|
||||
$user = factory(User::class)->create();
|
||||
$reason = "The case was canceled due to:";
|
||||
$appNotes = new ModelAppNotes();
|
||||
$noteContent = addslashes($reason);
|
||||
$appNotes->postNewNote(
|
||||
$application->APP_UID, $user->USR_UID, $noteContent, false
|
||||
);
|
||||
|
||||
// Query to get the cases notes
|
||||
$query = AppNotes::query();
|
||||
$query->select()->where('APP_UID', $application->APP_UID)->where('USR_UID', $user->USR_UID);
|
||||
$result = $query->get()->values()->toArray();
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* It test the cases notes creation and send a email to specific user
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_test_case_notes_creation_and_send_email_to_user()
|
||||
{
|
||||
$application = factory(Application::class)->create();
|
||||
$user = factory(User::class)->create();
|
||||
$reason = "The case was canceled due to:";
|
||||
$appNotes = new ModelAppNotes();
|
||||
$noteContent = addslashes($reason);
|
||||
$appNotes->postNewNote(
|
||||
$application->APP_UID, $user->USR_UID, $noteContent, true, 'PUBLIC', $user->USR_UID
|
||||
);
|
||||
|
||||
// Query to get the cases notes
|
||||
$query = AppNotes::query();
|
||||
$query->select()->where('APP_UID', $application->APP_UID)->where('USR_UID', $user->USR_UID);
|
||||
$result = $query->get()->values()->toArray();
|
||||
$this->assertNotEmpty($result);
|
||||
|
||||
// Query to get the emails
|
||||
$query = AppMessage::query();
|
||||
$query->select()->where('APP_UID', $application->APP_UID)->where('APP_MSG_TYPE', 'CASE_NOTE');
|
||||
$result = $query->get()->values()->toArray();
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* It test the cases notes creation and send a email to user with participaion in the case
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_test_case_notes_creation_and_send_email()
|
||||
{
|
||||
$application = factory(Application::class)->create();
|
||||
$user = factory(User::class)->create();
|
||||
factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'USR_UID' => $user->USR_UID
|
||||
]);
|
||||
$reason = "The case was canceled due to:";
|
||||
$appNotes = new ModelAppNotes();
|
||||
$noteContent = addslashes($reason);
|
||||
$appNotes->postNewNote(
|
||||
$application->APP_UID, $user->USR_UID, $noteContent, true, 'PUBLIC'
|
||||
);
|
||||
|
||||
// Query to get the cases notes
|
||||
$query = AppNotes::query();
|
||||
$query->select()->where('APP_UID', $application->APP_UID)->where('USR_UID', $user->USR_UID);
|
||||
$result = $query->get()->values()->toArray();
|
||||
$this->assertNotEmpty($result);
|
||||
|
||||
// Query to get the emails
|
||||
$query = AppMessage::query();
|
||||
$query->select()->where('APP_UID', $application->APP_UID)->where('APP_MSG_TYPE', 'CASE_NOTE');
|
||||
$result = $query->get()->values()->toArray();
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
}
|
||||
@@ -571,6 +571,14 @@ class Ajax
|
||||
// Review if the case was cancelled, true if the case was cancelled
|
||||
$result->status = ($response->status_code == 0) ? true : false;
|
||||
$result->msg = $response->message;
|
||||
// Register in cases notes
|
||||
if (!empty($_POST['NOTE_REASON'])) {
|
||||
$appNotes = new AppNotes();
|
||||
$noteContent = addslashes($_POST['NOTE_REASON']);
|
||||
$appNotes->postNewNote(
|
||||
$appUid, $usrUid, $noteContent, $_POST['NOTIFY_CANCEL']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$result->status = false;
|
||||
$result->msg = G::LoadTranslation("ID_CASE_USER_INVALID_CANCEL_CASE", [$usrUid]);
|
||||
|
||||
11
workflow/engine/src/ProcessMaker/Model/AppNotes.php
Normal file
11
workflow/engine/src/ProcessMaker/Model/AppNotes.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AppNotes extends Model
|
||||
{
|
||||
protected $table = 'APP_NOTES';
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -1073,7 +1073,7 @@ Ext.onReady(function(){
|
||||
params: {
|
||||
action: 'cancelCase',
|
||||
NOTE_REASON: noteReasonTxt,
|
||||
NOTIFY_PAUSE: notifyReasonVal
|
||||
NOTIFY_CANCEL: notifyReasonVal
|
||||
},
|
||||
success: function (result, request) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user