PMCORE-1782 Cannot import a PMTABLE.

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-07-14 13:46:17 -04:00
parent bd7aa4f1f8
commit acd24b40fb
2 changed files with 88 additions and 37 deletions

View File

@@ -1085,4 +1085,51 @@ class PmTablesProxyTest extends TestCase
$obj->delete($httpDataVarChar);
$obj->delete($httpDataTinyInt);
}
/**
* This test verifies the import of pmtable with post form error catching.
*
* Note: not all paths of this import method can be covered, because there is the
* definition of constants at the beginning of the method. Removing the
* constants would imply a very big change.
* @test
* @covers ::import()
*/
public function it_should_test_import_method_with_post_form_error_catch()
{
$httpData = [
'form' => [
"TYPE_TABLE" => "admin",
"PRO_UID" => "false"
]
];
$_POST['form'] = [
'TYPE_TABLE' => 'admin',
'FROM_CONFIRM' => 'admin'
];
$_SESSION['FILES_FORM'] = [
'error' => [
'FILENAME' => -1
]
];
$_FILES['form'] = [];
$pmTablesProxy = new pmTablesProxy();
$result = $pmTablesProxy->import($httpData);
//asserts
$this->assertObjectHasAttribute('fromAdmin', $result);
$this->assertObjectHasAttribute('arrayMessage', $result);
$this->assertObjectHasAttribute('arrayRelated', $result);
$this->assertObjectHasAttribute('arrayOverwrite', $result);
$this->assertObjectHasAttribute('validationType', $result);
$this->assertObjectHasAttribute('errorType', $result);
$this->assertObjectHasAttribute('buildResult', $result);
$this->assertObjectHasAttribute('success', $result);
$this->assertObjectHasAttribute('message', $result);
$this->assertObjectHasAttribute('type', $result);
$this->assertEquals($result->success, false);
$this->assertEquals($result->errorType, 'error');
}
}

View File

@@ -731,6 +731,10 @@ class pmTablesProxy extends HttpProxyController
*/
public function import($httpData)
{
//ob_start is for catching additional errors that have been printed on included files,
//this opening should be closed by ob_end_clean.
ob_start();
define('ERROR_PM_TABLES_OVERWRITE', 1);
define('ERROR_PROCESS_NOT_EXIST', 2);
define('ERROR_RP_TABLES_OVERWRITE', 3);
@@ -744,11 +748,15 @@ class pmTablesProxy extends HttpProxyController
}
}
$result = new stdClass();
$arrayOverwrite = [];
$arrayRelated = [];
$arrayMessage = [];
$validationType = 0;
try {
ValidationUploadedFiles::getValidationUploadedFiles()->dispatch(function($validator) {
throw new ExceptionRestApi($validator->getMessage());
});
$result = new stdClass();
$errors = '';
$fromConfirm = false;
@@ -765,7 +773,6 @@ class pmTablesProxy extends HttpProxyController
}
$_SESSION['FILES_FORM'] = $_FILES['form'];
$PUBLIC_ROOT_PATH = PATH_DATA . 'sites' . PATH_SEP . config("system.workspace") . PATH_SEP . 'public' . PATH_SEP;
$filename = $_FILES['form']['name']['FILENAME'];
$tempName = $_FILES['form']['tmp_name']['FILENAME'];
@@ -854,10 +861,6 @@ class pmTablesProxy extends HttpProxyController
//First Validate the file
$reportTable = new \ProcessMaker\BusinessModel\ReportTable();
$arrayOverwrite = array();
$arrayRelated = array();
$arrayMessage = array();
$validationType = 0;
if (!$fromConfirm) {
$aErrors = $reportTable->checkPmtFileThrowErrors(
$arrayTableSchema, $currentProUid, $fromAdmin, $overWrite, $_POST['form']['PRO_UID']
@@ -933,7 +936,6 @@ class pmTablesProxy extends HttpProxyController
$result->validationType = $validationType;
$result->errorType = 'error';
$result->buildResult = ob_get_contents();
ob_end_clean();
$result->success = false;
// if it is a propel exception message
@@ -946,6 +948,8 @@ class pmTablesProxy extends HttpProxyController
}
}
//ob_end_clean is used to close the ob_start opening at the beginning of this method.
ob_end_clean();
return $result;
}