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

FEAT #9284 Export controller Test

parent 14b7869e
No related branches found
No related tags found
No related merge requests found
......@@ -151,7 +151,7 @@ foreach ($customs as $custom) {
if ($countMail % 50 == 0) {
\SrcCore\models\DatabaseModel::insertMultiple([
'table' => 'emails',
'columnsValues' => ['user_id', 'sender', 'recipients', 'cc', 'cci', 'object', 'body', 'document', 'is_html', 'status', 'message_exchange_id', 'creation_date', 'send_date'],
'columns' => ['user_id', 'sender', 'recipients', 'cc', 'cci', 'object', 'body', 'document', 'is_html', 'status', 'message_exchange_id', 'creation_date', 'send_date'],
'values' => $aValues
]);
$aValues = [];
......@@ -161,7 +161,7 @@ foreach ($customs as $custom) {
if (!empty($aValues)) {
\SrcCore\models\DatabaseModel::insertMultiple([
'table' => 'emails',
'columnsValues' => ['user_id', 'sender', 'recipients', 'cc', 'cci', 'object', 'body', 'document', 'is_html', 'status', 'message_exchange_id', 'creation_date', 'send_date'],
'columns' => ['user_id', 'sender', 'recipients', 'cc', 'cci', 'object', 'body', 'document', 'is_html', 'status', 'message_exchange_id', 'creation_date', 'send_date'],
'values' => $aValues
]);
}
......
......@@ -63,13 +63,13 @@ class ExportController
$body = $request->getParsedBody();
if (!Validator::stringType()->notEmpty()->validate($body['delimiter']) || !in_array($body['delimiter'], [',', ';', 'TAB'])) {
return ['errors' => 'Delimiter is not set or not set well', 'code' => 400];
return $response->withStatus(400)->withJson(['errors' => 'Delimiter is not set or not set well']);
} elseif (!Validator::arrayType()->notEmpty()->validate($body['data'])) {
return ['errors' => 'Data is not an array or empty', 'code' => 400];
return $response->withStatus(400)->withJson(['errors' => 'Data is not an array or empty']);
}
foreach ($body['data'] as $value) {
if (!isset($value['value']) || !Validator::stringType()->notEmpty()->validate($value['label']) || !Validator::boolType()->validate($value['isFunction'])) {
return ['errors' => 'One data is not set well', 'code' => 400];
return $response->withStatus(400)->withJson(['errors' => 'One data is not set well']);
}
}
......@@ -202,10 +202,13 @@ class ExportController
$csvContent[] = $resource['entwo.short_label'];
} elseif ($value['value'] == 'getContactType') {
//TODO
$csvContent[] = '';
} elseif ($value['value'] == 'getContactCivility') {
//TODO
$csvContent[] = '';
} elseif ($value['value'] == 'getContactFunction') {
//TODO
$csvContent[] = '';
} elseif ($value['value'] == 'getTags') {
$csvContent[] = ExportController::getTags(['resId' => $resource['res_id']]);
} elseif ($value['value'] == 'getSignatories') {
......@@ -229,7 +232,6 @@ class ExportController
private static function getCategory(array $args)
{
ValidatorModel::notEmpty($args, ['categoryId']);
ValidatorModel::stringType($args, ['categoryId']);
static $categories;
......
......@@ -330,7 +330,7 @@ class ResourceListController
public static function getResourcesListQueryData(array $args)
{
ValidatorModel::notEmpty($args, ['data', 'basketClause', 'login']);
ValidatorModel::notEmpty($args, ['basketClause', 'login']);
ValidatorModel::stringType($args, ['basketClause', 'login']);
ValidatorModel::arrayType($args, ['data']);
......
......@@ -25,4 +25,111 @@ class ExportControllerTest extends TestCase
$this->assertInternalType('string', $responseBody->template);
$this->assertInternalType('string', $responseBody->delimiter);
}
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 = [
"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" => "getCategory",
"label" => "Catégorie",
"isFunction" => true
],
]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => 'MyBasket']);
$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' => 'MyBasket']);
$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' => 'MyBasket']);
$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' => 'MyBasket']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Delimiter is not set or not set well', $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