Merged in feature/PMCORE-1388 (pull request #7374)
PMCORE-1388 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
BIN
tests/resources/images/activate.png
Normal file
BIN
tests/resources/images/activate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 750 B |
BIN
tests/resources/images/activity.gif
Normal file
BIN
tests/resources/images/activity.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
BIN
tests/resources/testDocument.pdf
Normal file
BIN
tests/resources/testDocument.pdf
Normal file
Binary file not shown.
@@ -3,10 +3,14 @@
|
||||
namespace Tests\unit\workflow\engine\classes\model;
|
||||
|
||||
use AppNotes as ModelAppNotes;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\AppMessage;
|
||||
use Exception;
|
||||
use Faker\Factory;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\AppMessage;
|
||||
use ProcessMaker\Model\AppNotes;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Documents;
|
||||
use ProcessMaker\Model\EmailServerModel;
|
||||
use ProcessMaker\Model\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -17,12 +21,23 @@ use Tests\TestCase;
|
||||
*/
|
||||
class AppNotesTest extends TestCase
|
||||
{
|
||||
private $faker;
|
||||
|
||||
/**
|
||||
* Set up method
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->faker = Factory::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* It test the cases notes creation
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_test_case_notes_creation()
|
||||
public function it_test_case_notes_creation()
|
||||
{
|
||||
$application = factory(Application::class)->create();
|
||||
$user = factory(User::class)->create();
|
||||
@@ -37,7 +52,7 @@ class AppNotesTest extends TestCase
|
||||
$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);
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +60,7 @@ class AppNotesTest extends TestCase
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_test_case_notes_creation_and_send_email_to_user()
|
||||
public function it_test_case_notes_creation_and_send_email_to_user()
|
||||
{
|
||||
$application = factory(Application::class)->create();
|
||||
$user = factory(User::class)->create();
|
||||
@@ -74,7 +89,7 @@ class AppNotesTest extends TestCase
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_test_case_notes_creation_and_send_email()
|
||||
public function it_test_case_notes_creation_and_send_email()
|
||||
{
|
||||
$application = factory(Application::class)->create();
|
||||
$user = factory(User::class)->create();
|
||||
@@ -101,4 +116,111 @@ class AppNotesTest extends TestCase
|
||||
$result = $query->get()->values()->toArray();
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies the sending of the notification note with Exception.
|
||||
* @test
|
||||
* @covers \AppNotes::sendNoteNotification
|
||||
*/
|
||||
public function it_should_test_send_note_notification_with_exception()
|
||||
{
|
||||
//assert
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$appNotes = new ModelAppNotes();
|
||||
$appNotes->sendNoteNotification(null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies the sending of the notification note.
|
||||
* @test
|
||||
* @covers \AppNotes::sendNoteNotification
|
||||
*/
|
||||
public function it_should_test_send_note_notification_without_user()
|
||||
{
|
||||
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
|
||||
->get()
|
||||
->first();
|
||||
$application = factory(Application::class)->create();
|
||||
$delegation = factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'USR_UID' => $user->USR_UID
|
||||
]);
|
||||
|
||||
$params = [
|
||||
$application->APP_UID,
|
||||
'',
|
||||
'',
|
||||
$user->USR_UID,
|
||||
$this->faker->email,
|
||||
$delegation->DEL_INDEX
|
||||
];
|
||||
$appNotes = new ModelAppNotes();
|
||||
$appNotes->sendNoteNotification(...$params);
|
||||
|
||||
//assert
|
||||
$appMessage = AppMessage::where('APP_UID', '=', $application->APP_UID)->get()->first()->toArray();
|
||||
$this->assertArrayHasKey('APP_UID', $appMessage);
|
||||
$this->assertEquals($appMessage['APP_UID'], $application->APP_UID);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies the sending of the notification note with attach files.
|
||||
* @test
|
||||
* @covers \AppNotes::sendNoteNotification
|
||||
*/
|
||||
public function it_should_test_send_note_notification_with_attach_files()
|
||||
{
|
||||
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
|
||||
->get()
|
||||
->first();
|
||||
$application = factory(Application::class)->create();
|
||||
$delegation = factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'USR_UID' => $user->USR_UID
|
||||
]);
|
||||
$appNote = factory(AppNotes::class)->create();
|
||||
$appDocument = factory(Documents::class)->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'DOC_ID' => $appNote->NOTE_ID
|
||||
]);
|
||||
factory(EmailServerModel::class)->create([
|
||||
'MESS_DEFAULT' => 1
|
||||
]);
|
||||
|
||||
$params = [
|
||||
$application->APP_UID,
|
||||
$user->USR_UID,
|
||||
'',
|
||||
$user->USR_UID,
|
||||
$this->faker->email,
|
||||
$delegation->DEL_INDEX
|
||||
];
|
||||
$appNotes = new ModelAppNotes();
|
||||
$appNotes->sendNoteNotification(...$params);
|
||||
|
||||
//assert
|
||||
$appMessage = AppMessage::where('APP_UID', '=', $application->APP_UID)->get()->first()->toArray();
|
||||
$this->assertArrayHasKey('APP_UID', $appMessage);
|
||||
$this->assertEquals($appMessage['APP_UID'], $application->APP_UID);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify if exists attachment files.
|
||||
* @test
|
||||
* @covers \AppNotes::getAttachedFilesFromTheCaseNote
|
||||
*/
|
||||
public function it_should_test_get_attached_files_from_the_casenote()
|
||||
{
|
||||
$appNote = factory(AppNotes::class)->create();
|
||||
$appDocument = factory(Documents::class)->create([
|
||||
'DOC_ID' => $appNote->NOTE_ID
|
||||
]);
|
||||
|
||||
$appUid = $appDocument->APP_UID;
|
||||
$appNotes = new ModelAppNotes();
|
||||
$result = $appNotes->getAttachedFilesFromTheCaseNote($appNote->NOTE_ID);
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace ProcessMaker\BusinessModel;
|
||||
use Exception;
|
||||
use G;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Documents;
|
||||
use ProcessMaker\Model\User;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -15,6 +18,21 @@ use Tests\TestCase;
|
||||
*/
|
||||
class CasesTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Set up method.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
Documents::truncate();
|
||||
Application::truncate();
|
||||
User::where('USR_ID', '=', 1)
|
||||
->where('USR_ID', '=', 2)
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks the delete case
|
||||
*
|
||||
@@ -26,11 +44,11 @@ class CasesTest extends TestCase
|
||||
{
|
||||
// Set the RBAC
|
||||
global $RBAC;
|
||||
$_SESSION['USER_LOGGED'] = '00000000000000000000000000000002';
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$_SESSION['USER_LOGGED'] = G::generateUniqueID();
|
||||
$RBAC = RBAC::getSingleton();
|
||||
$RBAC->initRBAC();
|
||||
|
||||
$application = factory(Application::class)->create();
|
||||
$application = factory(Application::class)->create(['APP_INIT_USER' => G::generateUniqueID()]);
|
||||
// Tried to delete case
|
||||
$case = new Cases();
|
||||
$case->deleteCase($application->APP_UID, $_SESSION['USER_LOGGED']);
|
||||
@@ -48,7 +66,7 @@ class CasesTest extends TestCase
|
||||
// Set the RBAC
|
||||
global $RBAC;
|
||||
$_SESSION['USER_LOGGED'] = '00000000000000000000000000000001';
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$RBAC = RBAC::getSingleton();
|
||||
$RBAC->initRBAC();
|
||||
|
||||
$application = factory(Application::class)->create(['APP_STATUS' => 'TO_DO']);
|
||||
@@ -68,13 +86,50 @@ class CasesTest extends TestCase
|
||||
{
|
||||
// Set the RBAC
|
||||
global $RBAC;
|
||||
$_SESSION['USER_LOGGED'] = '00000000000000000000000000000001';
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$_SESSION['USER_LOGGED'] = G::generateUniqueID();
|
||||
$RBAC = RBAC::getSingleton();
|
||||
$RBAC->initRBAC();
|
||||
|
||||
$application = factory(Application::class)->create(['APP_INIT_USER' => '00000000000000000000000000000002']);
|
||||
$application = factory(Application::class)->create(['APP_INIT_USER' => G::generateUniqueID()]);
|
||||
// Tried to delete case
|
||||
$case = new Cases();
|
||||
$case->deleteCase($application->APP_UID, $_SESSION['USER_LOGGED']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Review the upload file related to the case notes
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases::uploadFilesInCaseNotes()
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_upload_files_related_case_note()
|
||||
{
|
||||
$application = factory(Application::class)->create();
|
||||
factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'APP_UID' => $application->APP_UID
|
||||
]);
|
||||
// File reference to upload
|
||||
$filesReferences = [
|
||||
'activityRename.gif' => PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activity.gif',
|
||||
];
|
||||
// Path of the case
|
||||
$pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . $application->APP_UID . PATH_SEP;
|
||||
// Upload the file
|
||||
$case = new Cases();
|
||||
$result = $case->uploadFilesInCaseNotes('00000000000000000000000000000001', $application->APP_UID, $filesReferences);
|
||||
$this->assertNotEmpty($result['attachments']);
|
||||
$result = head($result['attachments']);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertArrayHasKey('APP_UID', $result);
|
||||
$this->assertEquals($application->APP_UID, $result['APP_UID']);
|
||||
$this->assertArrayHasKey('APP_DOC_TYPE', $result);
|
||||
$this->assertEquals(Documents::DOC_TYPE_CASE_NOTE, $result['APP_DOC_TYPE']);
|
||||
$this->assertArrayHasKey('APP_DOC_FILENAME', $result);
|
||||
$this->assertEquals('activityRename.gif', $result['APP_DOC_FILENAME']);
|
||||
|
||||
// Remove the path created
|
||||
G::rm_dir($pathCase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\AppNotes;
|
||||
use ProcessMaker\Model\Documents;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class DocumentsTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\Documents
|
||||
*/
|
||||
class DocumentsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* Review get app files related to the case notes
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_test_get_case_note_files()
|
||||
{
|
||||
$appDoc = factory(Documents::class)->states('case_notes')->create();
|
||||
$doc = new Documents();
|
||||
$res = $doc->getAppFiles($appDoc->APP_UID, Documents::DOC_TYPE_CASE_NOTE);
|
||||
$this->assertNotEmpty($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify if exists attachment files.
|
||||
* @test
|
||||
* @covers Documents::getAttachedFilesFromTheCaseNote
|
||||
*/
|
||||
public function it_should_test_get_attached_files_from_the_casenote()
|
||||
{
|
||||
$appNote = factory(AppNotes::class)->create();
|
||||
$appDocument = factory(Documents::class)->create([
|
||||
'DOC_ID' => $appNote->NOTE_ID
|
||||
]);
|
||||
|
||||
$appUid = $appDocument->APP_UID;
|
||||
$result = Documents::getAttachedFilesFromTheCaseNote($appUid);
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\src\ProcessMaker\Util\Helpers;
|
||||
|
||||
use G;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SaveAppDocumentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* It test if the file reference was uploaded
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_copy_file_same_name()
|
||||
{
|
||||
$files = [
|
||||
'name' => PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activate.png',
|
||||
'tmp_name' => PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activate.png',
|
||||
];
|
||||
$appUid = G::generateUniqueID();
|
||||
$appDocUid = G::generateUniqueID();
|
||||
$pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP;
|
||||
saveAppDocument($files, $appUid, $appDocUid, 1, false);
|
||||
$this->assertFileExists($pathCase . $appDocUid . '_1.png');
|
||||
G::rm_dir($pathCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* It test if the file reference was uploaded
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_copy_file_different_name()
|
||||
{
|
||||
$files = [
|
||||
'name' => 'activityRename.gif',
|
||||
'tmp_name' => PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activity.gif',
|
||||
];
|
||||
$appUid = G::generateUniqueID();
|
||||
$appDocUid = G::generateUniqueID();
|
||||
$pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP;
|
||||
saveAppDocument($files, $appUid, $appDocUid, 1, false);
|
||||
$this->assertFileExists($pathCase . $appDocUid . '_1.gif');
|
||||
G::rm_dir($pathCase);
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,43 @@ class ValidationUploadedFilesTest extends TestCase
|
||||
$this->assertEquals(0, $result->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify validation rules for files post in cases notes.
|
||||
* @test
|
||||
* @covers ::runRulesForPostFilesOfNote
|
||||
*/
|
||||
public function it_should_test_run_rules_for_post_files_of_note()
|
||||
{
|
||||
//assert for file has not exist
|
||||
$file = [
|
||||
'filename' => 'testDocument.pdf',
|
||||
'path' => "testDocument.pdf"
|
||||
];
|
||||
$validation = new ValidationUploadedFiles();
|
||||
$result = $validation->runRulesForPostFilesOfNote($file);
|
||||
$this->assertTrue($result->fails());
|
||||
|
||||
//assert for file has not valid extension
|
||||
$file = [
|
||||
'filename' => 'projectData.json',
|
||||
'path' => PATH_TRUNK . "tests/resources/projectData.json"
|
||||
];
|
||||
$validation = new ValidationUploadedFiles();
|
||||
$result = $validation->runRulesForPostFilesOfNote($file);
|
||||
$this->assertTrue($result->fails());
|
||||
|
||||
//assert the file exists and has valid extension
|
||||
$file = [
|
||||
'filename' => 'testDocument.pdf',
|
||||
'path' => PATH_TRUNK . "tests/resources/testDocument.pdf"
|
||||
];
|
||||
$validation = new ValidationUploadedFiles();
|
||||
$result = $validation->runRulesForPostFilesOfNote($file);
|
||||
$this->assertFalse($result->fails());
|
||||
$this->assertEmpty($result->getMessage());
|
||||
$this->assertEquals(0, $result->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* It deletes the images created
|
||||
*/
|
||||
@@ -128,4 +165,4 @@ class ValidationUploadedFilesTest extends TestCase
|
||||
unlink(PATH_DATA . '1.PnG');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user