PMCORE-1751
This commit is contained in:
@@ -56,6 +56,7 @@ define('PATH_SMARTY_CACHE', PATH_TRUNK . 'shared/compiled/smarty/cache');
|
||||
define('PATH_THIRDPARTY', PATH_TRUNK . 'thirdparty/');
|
||||
define("URL_KEY", 'c0l0s40pt1mu59r1m3');
|
||||
define("PATH_XMLFORM", PATH_CORE . "xmlform" . PATH_SEP);
|
||||
define('PATH_DOCUMENT', PATH_WORKSPACE . '/files/');
|
||||
|
||||
// Set Time Zone
|
||||
$_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int) (env('MAIN_SYSTEM_UTC_TIME_ZONE', 'workflow')) == 1;
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use Exception;
|
||||
use G;
|
||||
use ProcessMaker\BusinessModel\Cases;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Documents;
|
||||
@@ -29,8 +30,8 @@ class CasesTest extends TestCase
|
||||
Documents::truncate();
|
||||
Application::truncate();
|
||||
User::where('USR_ID', '=', 1)
|
||||
->where('USR_ID', '=', 2)
|
||||
->delete();
|
||||
->where('USR_ID', '=', 2)
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,4 +133,104 @@ class CasesTest extends TestCase
|
||||
// Remove the path created
|
||||
G::rm_dir($pathCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the uploadFiles method
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases::uploadFiles()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_upload_files_method()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$application = factory(Application::class)->create([
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
$delegation = factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID
|
||||
]);
|
||||
$varName = "/tmp/test.pdf";
|
||||
fopen($varName, "w");
|
||||
$_FILES = ["form" =>
|
||||
[
|
||||
"name" => ["test"],
|
||||
"type" => ["application/pdf"],
|
||||
"tmp_name" => ["/tmp/test.pdf"],
|
||||
"error" => [0],
|
||||
"size" => [0]
|
||||
]];
|
||||
|
||||
$case = new Cases();
|
||||
|
||||
// Call the uploadFiles method, sending the delIndex
|
||||
$res = $case->uploadFiles($user->USR_UID, $application->APP_UID, $varName, -1, null, $delegation->DEL_INDEX);
|
||||
// Asserts the result is not empy
|
||||
$this->assertNotEmpty($res);
|
||||
|
||||
//Call the uploadFiles method, without the delIndex
|
||||
$res = $case->uploadFiles($user->USR_UID, $application->APP_UID, $varName);
|
||||
// Asserts the result is not empy
|
||||
$this->assertNotEmpty($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the exception in the uploadFiles method
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases::uploadFiles()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_exception_in_upload_files_method()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$application = factory(Application::class)->create([
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID
|
||||
]);
|
||||
$varName = "/tmp/test.pdf";
|
||||
fopen($varName, "w");
|
||||
|
||||
$_FILES = [];
|
||||
$case = new Cases();
|
||||
|
||||
// Asserts an exception is expected
|
||||
$this->expectExceptionMessage("**ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR**");
|
||||
// Call the uploadFiles method
|
||||
$case->uploadFiles($user->USR_UID, $application->APP_UID, $varName);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the exception in uploadFiles method
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases::uploadFiles()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_exception_in_upload_files_method()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$application = factory(Application::class)->create([
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
$delegation = factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID
|
||||
]);
|
||||
$varName = "/tmp/test.pdf";
|
||||
fopen($varName, "w");
|
||||
$_FILES = ["form" =>
|
||||
[
|
||||
"name" => ["test"],
|
||||
"type" => ["application/pdf"],
|
||||
"tmp_name" => ["/tmp/test.pdf"],
|
||||
"error" => [UPLOAD_ERR_INI_SIZE],
|
||||
"size" => [0]
|
||||
]];
|
||||
|
||||
$case = new Cases();
|
||||
|
||||
// Asserts there is an exception for the file
|
||||
$this->expectExceptionMessage("The uploaded file exceeds the upload_max_filesize directive in php.ini");
|
||||
// Call the uploadFiles method
|
||||
$case->uploadFiles($user->USR_UID, $application->APP_UID, $varName, -1, null, $delegation->DEL_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ use Luracast\Restler\Defaults;
|
||||
use Luracast\Restler\HumanReadableCache;
|
||||
use Luracast\Restler\RestException;
|
||||
use Maveriks\Extension\Restler;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\User;
|
||||
use ProcessMaker\Services\Api\Cases;
|
||||
use RBAC;
|
||||
use ReflectionClass;
|
||||
@@ -213,4 +216,74 @@ class CasesTest extends TestCase
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the uploadDocumentToCase method
|
||||
*
|
||||
* @covers ProcessMaker\Services\Api\Cases::uploadDocumentToCase
|
||||
* @test
|
||||
*/
|
||||
public function test_upload_document_to_case_method()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$application = factory(Application::class)->create([
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
$delegation = factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID
|
||||
]);
|
||||
$varName = "/tmp/test.pdf";
|
||||
|
||||
$varName = "/tmp/test.pdf";
|
||||
fopen($varName, "w");
|
||||
$_FILES = ["form" =>
|
||||
[
|
||||
"name" => ["test"],
|
||||
"type" => ["application/pdf"],
|
||||
"tmp_name" => ["/tmp/test.pdf"],
|
||||
"error" => [0],
|
||||
"size" => [0]
|
||||
]];
|
||||
|
||||
$case = new Cases();
|
||||
|
||||
//Call the uploadDocumentToCase method without a post delindex
|
||||
$res = $case->uploadDocumentToCase($application->APP_UID, $varName);
|
||||
//Asserts the result is not empty
|
||||
$this->assertNotEmpty($res);
|
||||
$_POST['delIndex'] = $delegation->DEL_INDEX;
|
||||
//Call the uploadDocumentToCase method with a post delindex
|
||||
$res = $case->uploadDocumentToCase($application->APP_UID, $varName, -1, null, $delegation->DEL_INDEX);
|
||||
//Asserts the result is not empty
|
||||
$this->assertNotEmpty($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the exception in the uploadDocumentToCase method
|
||||
*
|
||||
* @covers ProcessMaker\Services\Api\Cases::uploadDocumentToCase
|
||||
* @test
|
||||
*/
|
||||
public function test_exception_upload_document_to_case_method()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$application = factory(Application::class)->create([
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
$delegation = factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID
|
||||
]);
|
||||
$varName = "/tmp/test.pdf";
|
||||
|
||||
$varName = "/tmp/test.pdf";
|
||||
fopen($varName, "w");
|
||||
$_FILES = [];
|
||||
|
||||
$case = new Cases();
|
||||
|
||||
//Asserts the expected exception
|
||||
$this->expectExceptionMessage("**ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR**");
|
||||
//Call the uploadDocumentToCase method without a post delindex
|
||||
$res = $case->uploadDocumentToCase($application->APP_UID, $varName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user