Skip to content
Snippets Groups Projects
Verified Commit e4cf793c authored by Damien's avatar Damien
Browse files

FEAT #9104 Export Unit tests + fixes

parent f4447508
No related branches found
No related tags found
No related merge requests found
......@@ -137,7 +137,7 @@ class ResourceListController
'leftJoin' => $leftJoinFunction,
'where' => ['res_letterbox.res_id in (?)'],
'data' => [$resIds],
'order' => [$order]
'orderBy' => [$order]
]);
foreach ($resources as $key => $resource) {
......
......@@ -214,17 +214,17 @@ class SummarySheetController
$pdf->SetY($pdf->GetY() + 2);
$pdf->SetFont('', '', 10);
$pdf->MultiCell($widthNoMargins / 2, 27, _CATEGORY . " : {$category}", 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthNoMargins / 2, 27, _STATUS . " : {$status}", 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($widthNoMargins / 2, 27, _PRIORITY . " : {$priority}", 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthNoMargins / 2, 27, _PROCESS_LIMIT_DATE . " : {$processLimitDate}", 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($widthNoMargins / 2, 30, _CATEGORY . " : {$category}", 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthNoMargins / 2, 30, _STATUS . " : {$status}", 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($widthNoMargins / 2, 30, _PRIORITY . " : {$priority}", 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthNoMargins / 2, 30, _PROCESS_LIMIT_DATE . " : {$processLimitDate}", 1, 'L', false, 1, '', '', true, 0, true);
} elseif ($unit['unit'] == 'senderRecipientInformations') {
$ext = ResModel::getExtById(['select' => ['category_id', 'address_id', 'exp_user_id', 'dest_user_id', 'is_multicontacts'], 'resId' => $resource['res_id']]);
if (!empty($ext)) {
$resourcesContacts = ResourceContactModel::getFormattedByResId(['resId' => $resource['res_id']]);
foreach ($resourcesContacts as $key => $value) {
foreach ($resourcesContacts as $contactsKey => $value) {
$entitiesFormat = '';
if ($value['type'] == 'user') {
$userEntity = UserModel::getPrimaryEntityById(['id' => $value['item_id']]);
......@@ -232,7 +232,7 @@ class SummarySheetController
$entitiesFormat = ' (' . $userEntity['entity_label'] . ')';
}
}
$resourcesContacts[$key]['format'] = $value['format'] . $entitiesFormat;
$resourcesContacts[$contactsKey]['format'] = $value['format'] . $entitiesFormat;
}
$oldContacts = [];
......
......@@ -27,116 +27,147 @@ class ExportControllerTest extends TestCase
$this->assertNotEmpty($responseBody->templates->csv);
}
// public function testUpdateExport()
// {
// $GLOBALS['userId'] = 'bbain';
//
// $ExportController = new \Resource\controllers\ExportController();
//
// // PUT
// $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
// $request = \Slim\Http\Request::createFromEnvironment($environment);
//
// $aArgs = [
// "resources" => $GLOBALS['resources'],
// "delimiter" => ';',
// "data" => [
// [
// "value" => "subject",
// "label" => "Sujet",
// "isFunction" => false
// ],
// [
// "value" => "getStatus",
// "label" => "Status",
// "isFunction" => true
// ],
// [
// "value" => "getPriority",
// "label" => "Priorité",
// "isFunction" => true
// ],
// [
// "value" => "getCopyEntities",
// "label" => "Copies",
// "isFunction" => true
// ],
// [
// "value" => "getDetailLink",
// "label" => "Lien page détaillé",
// "isFunction" => true
// ],
// [
// "value" => "getParentFolder",
// "label" => "Dossier",
// "isFunction" => true
// ],
// [
// "value" => "getInitiatorEntity",
// "label" => "Entité initiatrice",
// "isFunction" => true
// ],
// [
// "value" => "getDestinationEntity",
// "label" => "Entité traitante",
// "isFunction" => true
// ],
// [
// "value" => "getDestinationEntityType",
// "label" => "Entité traitante",
// "isFunction" => true
// ],
// [
// "value" => "getCategory",
// "label" => "Catégorie",
// "isFunction" => true
// ],
// ]
// ];
// $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
//
// $response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
// $responseBody = json_decode((string)$response->getBody());
//
// $this->assertSame(null, $responseBody);
//
// // GET
// $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
// $request = \Slim\Http\Request::createFromEnvironment($environment);
//
// $response = $ExportController->getExportTemplate($request, new \Slim\Http\Response());
// $responseBody = json_decode((string)$response->getBody());
//
// $template = (array)$responseBody->template;
// foreach ($template as $key => $value) {
// $template[$key] = (array)$value;
// }
// $this->assertSame($aArgs['data'], $template);
// $this->assertSame(';', $responseBody->delimiter);
//
//
// //ERRORS
// $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
// $request = \Slim\Http\Request::createFromEnvironment($environment);
//
// unset($aArgs['data'][2]['label']);
// $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
// $response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
// $responseBody = json_decode((string)$response->getBody());
// $this->assertSame('One data is not set well', $responseBody->errors);
//
// unset($aArgs['data']);
// $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
// $response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
// $responseBody = json_decode((string)$response->getBody());
// $this->assertSame('Data is not an array or empty', $responseBody->errors);
//
// $aArgs['delimiter'] = 't';
// $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
// $response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
// $responseBody = json_decode((string)$response->getBody());
// $this->assertSame('Delimiter is not set or not set well', $responseBody->errors);
//
// $GLOBALS['userId'] = 'superadmin';
// }
public function testUpdateExport()
{
$GLOBALS['userId'] = 'bbain';
$ExportController = new \Resource\controllers\ExportController();
// PUT
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
"resources" => $GLOBALS['resources'],
"delimiter" => ';',
"format" => 'csv',
"data" => [
[
"value" => "subject",
"label" => "Sujet",
"isFunction" => false
],
[
"value" => "getStatus",
"label" => "Status",
"isFunction" => true
],
[
"value" => "getPriority",
"label" => "Priorité",
"isFunction" => true
],
[
"value" => "getCopyEntities",
"label" => "Copies",
"isFunction" => true
],
[
"value" => "getDetailLink",
"label" => "Lien page détaillé",
"isFunction" => true
],
[
"value" => "getParentFolder",
"label" => "Dossier",
"isFunction" => true
],
[
"value" => "getInitiatorEntity",
"label" => "Entité initiatrice",
"isFunction" => true
],
[
"value" => "getDestinationEntity",
"label" => "Entité traitante",
"isFunction" => true
],
[
"value" => "getDestinationEntityType",
"label" => "Entité traitante",
"isFunction" => true
],
[
"value" => "getCategory",
"label" => "Catégorie",
"isFunction" => true
],
]
];
//CSV
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(null, $responseBody);
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $ExportController->getExportTemplates($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$templateData = (array)$responseBody->templates->csv->data;
foreach ($templateData as $key => $value) {
$templateData[$key] = (array)$value;
}
$this->assertSame($aArgs['data'], $templateData);
$this->assertSame(';', $responseBody->templates->csv->delimiter);
//PDF
$aArgs['format'] = 'pdf';
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(null, $responseBody);
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $ExportController->getExportTemplates($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$templateData = (array)$responseBody->templates->pdf->data;
foreach ($templateData as $key => $value) {
$templateData[$key] = (array)$value;
}
$this->assertSame($aArgs['data'], $templateData);
//ERRORS
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
unset($aArgs['data'][2]['label']);
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('One data is not set well', $responseBody->errors);
unset($aArgs['data']);
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Data data is empty or not an array', $responseBody->errors);
$aArgs['delimiter'] = 't';
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Delimiter is empty or not a string between [\',\', \';\', \'TAB\']', $responseBody->errors);
$aArgs['format'] = 'pd';
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 10]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Data format is empty or not a string between [\'pdf\', \'csv\']', $responseBody->errors);
$GLOBALS['userId'] = 'superadmin';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment