From 31d312b981ea2d305aa4343cc3d553afe5e6b0e7 Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Wed, 29 Apr 2020 14:11:29 +0200
Subject: [PATCH] FEAT #13676 TIME 7:00 finished improving resource tests

---
 phpunit.xml                                   |   2 +-
 .../controllers/WatermarkController.php       |   3 +
 src/app/resource/models/ChronoModel.php       |   6 +
 .../app/indexing/IndexingControllerTest.php   |  21 +
 .../app/resource/ExportControllerTest.php     |   7 +
 .../app/resource/ResControllerTest.php        | 931 +++++++++++++++++-
 .../resource/ResourceListControllerTest.php   | 254 ++++-
 7 files changed, 1173 insertions(+), 51 deletions(-)

diff --git a/phpunit.xml b/phpunit.xml
index 0afa21a6643..bf74b4e9c80 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -20,13 +20,13 @@
             <file>test/unitTests/app/group/PrivilegeControllerTest.php</file>
             <file>test/unitTests/app/entity/ListTemplateControllerTest.php</file>
             <file>test/unitTests/app/indexingModel/IndexingModelControllerTest.php</file>
-            <file>test/unitTests/app/indexing/IndexingControllerTest.php</file>
             <file>test/unitTests/app/notification/NotificationControllerTest.php</file>
             <file>test/unitTests/app/notification/NotificationScheduleControllerTest.php</file>
             <file>test/unitTests/app/parameter/ParameterControllerTest.php</file>
             <file>test/unitTests/app/priority/PriorityControllerTest.php</file>
             <file>test/unitTests/app/resource/ResControllerTest.php</file>
             <file>test/unitTests/app/resource/ResourceListControllerTest.php</file>
+            <file>test/unitTests/app/indexing/IndexingControllerTest.php</file>
             <file>test/unitTests/app/resource/ExportControllerTest.php</file>
             <file>test/unitTests/app/resource/LinkControllerTest.php</file>
             <file>test/unitTests/app/entity/ListInstanceControllerTest.php</file>
diff --git a/src/app/resource/controllers/WatermarkController.php b/src/app/resource/controllers/WatermarkController.php
index bf675ab5da9..3cb15ce8b80 100644
--- a/src/app/resource/controllers/WatermarkController.php
+++ b/src/app/resource/controllers/WatermarkController.php
@@ -95,6 +95,9 @@ class WatermarkController
         return $fileContent;
     }
 
+    /**
+     * @codeCoverageIgnore
+     */
     public static function watermarkAttachment(array $args)
     {
         ValidatorModel::notEmpty($args, ['attachmentId', 'path']);
diff --git a/src/app/resource/models/ChronoModel.php b/src/app/resource/models/ChronoModel.php
index dec8fb5bafa..f09102f2f5f 100755
--- a/src/app/resource/models/ChronoModel.php
+++ b/src/app/resource/models/ChronoModel.php
@@ -81,6 +81,9 @@ class ChronoModel
         return implode('', $chronoNumber);
     }
 
+    /**
+     * @codeCoverageIgnore
+     */
     public static function getChronoGlobal()
     {
         $chronoId = 'chrono_global_' . date('Y');
@@ -99,6 +102,9 @@ class ChronoModel
         return $chrono;
     }
 
+    /**
+     * @codeCoverageIgnore
+     */
     public static function getChronoEntity($entityId)
     {
         $chronoId = "chrono_{$entityId}_" . date('Y');
diff --git a/test/unitTests/app/indexing/IndexingControllerTest.php b/test/unitTests/app/indexing/IndexingControllerTest.php
index d9c5cb59ce5..867034b972a 100755
--- a/test/unitTests/app/indexing/IndexingControllerTest.php
+++ b/test/unitTests/app/indexing/IndexingControllerTest.php
@@ -276,6 +276,27 @@ class IndexingControllerTest extends TestCase
         $responseBody = json_decode((string)$response->getBody());
         $this->assertSame('Resource does not exist', $responseBody->errors);
 
+        \Resource\models\ResModel::update([
+            'set'   => ['status' => ''],
+            'where' => ['res_id = ?'],
+            'data'  => [$GLOBALS['resources'][2]]
+        ]);
+
+        $body = [
+            'resource' => $GLOBALS['resources'][2]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $indexingController->setAction($fullRequest, new \Slim\Http\Response(), ['groupId' => 2, 'actionId' => '20']);
+        $responseBody = json_decode((string)$response->getBody());
+        print_r($responseBody);
+        $this->assertSame(204, $response->getStatusCode());
+
+        \Resource\models\ResModel::update([
+            'set'   => ['status' => 'NEW'],
+            'where' => ['res_id = ?'],
+            'data'  => [$GLOBALS['resources'][2]]
+        ]);
+
         $GLOBALS['login'] = 'superadmin';
         $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
         $GLOBALS['id'] = $userInfo['id'];
diff --git a/test/unitTests/app/resource/ExportControllerTest.php b/test/unitTests/app/resource/ExportControllerTest.php
index c1d3009130a..e38fe92ed69 100755
--- a/test/unitTests/app/resource/ExportControllerTest.php
+++ b/test/unitTests/app/resource/ExportControllerTest.php
@@ -163,8 +163,15 @@ class ExportControllerTest extends TestCase
 
         $response     = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => $myBasket['id']]);
         $responseBody = json_decode((string)$response->getBody());
+        $this->assertSame(null, $responseBody);
+        $headers = $response->getHeaders();
+        $this->assertSame('application/pdf', $headers['Content-Type'][0]);
 
+        $response     = $ExportController->updateExport($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => $myBasket['id']]);
+        $responseBody = json_decode((string)$response->getBody());
         $this->assertSame(null, $responseBody);
+        $headers = $response->getHeaders();
+        $this->assertSame('application/pdf', $headers['Content-Type'][0]);
 
         //  GET
         $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
diff --git a/test/unitTests/app/resource/ResControllerTest.php b/test/unitTests/app/resource/ResControllerTest.php
index 2905807bcd9..a9dc5ee1ffc 100755
--- a/test/unitTests/app/resource/ResControllerTest.php
+++ b/test/unitTests/app/resource/ResControllerTest.php
@@ -13,6 +13,7 @@ class ResControllerTest extends TestCase
 {
     private static $id = null;
     private static $id2 = null;
+    private static $id3 = null;
 
     public function testGetDepartmentById()
     {
@@ -39,48 +40,48 @@ class ResControllerTest extends TestCase
         $fileContent = file_get_contents('test/unitTests/samples/test.txt');
         $encodedFile = base64_encode($fileContent);
 
-        $aArgs = [
-            'modelId'       => 1,
-            'status'        => 'NEW',
-            'encodedFile'   => $encodedFile,
-            'format'        => 'txt',
-            'confidentiality'   => false,
-            'documentDate'  => '2019-01-01 17:18:47',
-            'arrivalDate'   => '2019-01-01 17:18:47',
-            'processLimitDate'  => '2029-01-01',
-            'doctype'       => 102,
-            'destination'   => 15,
-            'initiator'     => 15,
-            'subject'       => 'Breaking News : Superman is alive - PHP unit',
-            'typist'        => 19,
-            'priority'      => 'poiuytre1357nbvc',
-            'senders'       => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
+        $body = [
+            'modelId'          => 1,
+            'status'           => 'NEW',
+            'encodedFile'      => $encodedFile,
+            'format'           => 'txt',
+            'confidentiality'  => false,
+            'documentDate'     => '2019-01-01 17:18:47',
+            'arrivalDate'      => '2019-01-01 17:18:47',
+            'processLimitDate' => '2029-01-01',
+            'doctype'          => 102,
+            'destination'      => 15,
+            'initiator'        => 15,
+            'subject'          => 'Breaking News : Superman is alive - PHP unit',
+            'typist'           => 19,
+            'priority'         => 'poiuytre1357nbvc',
+            'senders'          => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
         ];
 
-        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
 
         $response     = $resController->create($fullRequest, new \Slim\Http\Response());
         $responseBody = json_decode((string)$response->getBody());
         self::$id = $responseBody->resId;
         $this->assertIsInt(self::$id);
 
-        $aArgs = [
-            'modelId'       => 2,
-            'status'        => 'NEW',
-            'confidentiality'   => false,
-            'documentDate'  => '2019-01-01 17:18:47',
-            'arrivalDate'   => '2019-01-01 17:18:47',
-            'processLimitDate'  => '2029-01-01',
-            'doctype'       => 102,
-            'destination'   => 15,
-            'initiator'     => 15,
-            'subject'       => 'Breaking News : Superman is alive - PHP unit',
-            'typist'        => 19,
-            'priority'      => 'poiuytre1357nbvc',
-            'senders'       => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
+        $body = [
+            'modelId'          => 2,
+            'status'           => 'NEW',
+            'confidentiality'  => false,
+            'documentDate'     => '2019-01-01 17:18:47',
+            'arrivalDate'      => '2019-01-01 17:18:47',
+            'processLimitDate' => '2029-01-01',
+            'doctype'          => 102,
+            'destination'      => 15,
+            'initiator'        => 15,
+            'subject'          => 'Breaking News : Superman is alive - PHP unit',
+            'typist'           => 19,
+            'priority'         => 'poiuytre1357nbvc',
+            'senders'          => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
         ];
 
-        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
 
         $response     = $resController->create($fullRequest, new \Slim\Http\Response());
         $this->assertSame(200, $response->getStatusCode());
@@ -88,6 +89,34 @@ class ResControllerTest extends TestCase
         $this->assertIsInt($responseBody['resId']);
         self::$id2 = $responseBody['resId'];
 
+        $fileContent = file_get_contents('modules/templates/templates/styles/AR_Masse_Simple.docx');
+        $encodedFile = base64_encode($fileContent);
+
+        $body = [
+            'modelId'          => 2,
+            'status'           => 'NEW',
+            'confidentiality'  => false,
+            'encodedFile'      => $encodedFile,
+            'format'           => 'docx',
+            'arrivalDate'      => '2019-01-01 17:18:47',
+            'processLimitDate' => '2029-01-01',
+            'doctype'          => 102,
+            'destination'      => 15,
+            'initiator'        => 15,
+            'subject'          => 'Breaking News : Superman is alive (again) - PHP unit',
+            'typist'           => 19,
+            'priority'         => 'poiuytre1357nbvc',
+            'senders'          => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
+        ];
+
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(200, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertIsInt($responseBody['resId']);
+        self::$id3 = $responseBody['resId'];
+
         //  READ
         $res = \Resource\models\ResModel::getById(['resId' => self::$id, 'select' => ['*']]);
 
@@ -108,10 +137,348 @@ class ResControllerTest extends TestCase
         $fileContent = file_get_contents('test/unitTests/samples/test.txt');
         $encodedFile = base64_encode($fileContent);
 
-        $aArgs = [
+        $body = [
+            'status'        => 'NEW',
+            'encodedFile'   => $encodedFile,
+            'format'        => 'txt',
+            'confidentiality'   => false,
+            'documentDate'  => '2019-01-01 17:18:47',
+            'arrivalDate'   => '2019-01-01 17:18:47',
+            'processLimitDate'  => '2029-01-01',
+            'doctype'       => 102,
+            'destination'   => 15,
+            'initiator'     => 15,
+            'subject'       => 'Breaking News : Superman is alive - PHP unit',
+            'typist'        => 19,
+            'priority'      => 'poiuytre1357nbvc',
+            'tags'          => [1, 2],
+            'folders'       => [1, 2],
+        ];
+
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body modelId is empty or not an integer', $responseBody['errors']);
+
+        // Errors from ResourceControlController::controlResource
+        $body = [];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body is not set or empty', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body doctype is empty or not an integer', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 1 // wrong format
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body status is empty or not a string', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102000000,
+            'modelId' => 1,
+            'status'  => 'NEW'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body doctype does not exist', $responseBody['errors']);
+
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1000,
+            'status'  => 'NEW'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body modelId does not exist', $responseBody['errors']);
+
+        $body = [
+            'doctype'     => 102,
+            'modelId'     => 1,
+            'status'      => 'NEW',
+            'encodedFile' => $encodedFile,
+            'format'      => 'docx'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Format with this mimeType is not allowed : docx text/plain', $responseBody['errors']);
+
+        $body = [
+            'doctype'      => 102,
+            'modelId'      => 1,
+            'status'       => 'NEW',
+            'customFields' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype'      => 102,
+            'modelId'      => 1,
+            'status'       => 'NEW',
+            'customFields' => [1000]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields : One or more custom fields do not exist', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'folders' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body folders is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'folders' => [100000]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body folders : One or more folders do not exist or are out of perimeter', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'tags'    => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body tags is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'tags'    => [100000]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body tags : One or more tags do not exist', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'senders' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body senders is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'senders' => ['wrong format']
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body senders[0] is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'senders' => [['type' => 'alien']]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body senders[0] type is not valid', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'senders' => [['type' => 'user', 'id' => 1000]]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body senders[0] id does not exist', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'recipients' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body recipients is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'recipients' => ['wrong format']
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body recipients[0] is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'recipients' => [['type' => 'alien']]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body recipients[0] type is not valid', $responseBody['errors']);
+
+        $body = [
+            'doctype' => 102,
+            'modelId' => 1,
+            'status'  => 'NEW',
+            'recipients' => [['type' => 'user', 'id' => 1000]]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body recipients[0] id does not exist', $responseBody['errors']);
+
+        $body = [
+            'doctype'      => 102,
+            'modelId'      => 1,
+            'status'       => 'NEW',
+            'documentDate' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body documentDate is not a date', $responseBody['errors']);
+
+        $dateInTheFuture = new \DateTime('tomorrow');
+        $dateInTheFuture->add(new \DateInterval('P10D'));
+        $dateInTheFuture = $dateInTheFuture->format('d-m-Y');
+        
+        $body = [
+            'doctype'      => 102,
+            'modelId'      => 1,
+            'status'       => 'NEW',
+            'documentDate' => $dateInTheFuture
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body documentDate is not a valid date', $responseBody['errors']);
+
+        $body = [
+            'doctype'     => 102,
+            'modelId'     => 1,
+            'status'      => 'NEW',
+            'arrivalDate' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body arrivalDate is not a date', $responseBody['errors']);
+
+        $body = [
+            'doctype'     => 102,
+            'modelId'     => 1,
+            'status'      => 'NEW',
+            'arrivalDate' => $dateInTheFuture
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body arrivalDate is not a valid date', $responseBody['errors']);
+
+        $body = [
+            'doctype'       => 102,
+            'modelId'       => 1,
+            'status'        => 'NEW',
+            'departureDate' => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body departureDate is not a date', $responseBody['errors']);
+
+        $body = [
+            'doctype'       => 102,
+            'modelId'       => 1,
+            'status'        => 'NEW',
+            'documentDate'  => '2020-02-01',
+            'departureDate' => '2020-01-01'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body departureDate is not a valid date', $responseBody['errors']);
+
+        $GLOBALS['login'] = 'bbain';
+        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
+        $GLOBALS['id'] = $userInfo['id'];
+
+        $body = [
+            'modelId'       => 1,
             'status'        => 'NEW',
-            'encodedFile'   => $encodedFile,
-            'format'        => 'txt',
             'confidentiality'   => false,
             'documentDate'  => '2019-01-01 17:18:47',
             'arrivalDate'   => '2019-01-01 17:18:47',
@@ -122,16 +489,18 @@ class ResControllerTest extends TestCase
             'subject'       => 'Breaking News : Superman is alive - PHP unit',
             'typist'        => 19,
             'priority'      => 'poiuytre1357nbvc',
-            'tags'          => [1, 2],
-            'folders'       => [1, 2],
+            'senders'       => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
+            'diffusionList' => [
+                ['id' => 19, 'mode' => 'dest']
+            ]
         ];
 
-        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
 
         $response     = $resController->create($fullRequest, new \Slim\Http\Response());
-        $responseBody = json_decode((string)$response->getBody());
-
-        $this->assertSame('Body modelId is empty or not an integer', $responseBody->errors);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body initiator does not belong to your entities', $responseBody['errors']);
 
         $GLOBALS['login'] = 'ddur';
         $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
@@ -252,7 +621,6 @@ class ResControllerTest extends TestCase
         ]);
 
         $aArgs = [
-            'modelId'          => 1,
             'status'           => 'NEW',
             'encodedFile'      => $encodedFile,
             'format'           => 'txt',
@@ -277,7 +645,6 @@ class ResControllerTest extends TestCase
         $this->assertSame(204, $response->getStatusCode());
 
         $aArgs = [
-            'modelId'          => 1,
             'status'           => 'NEW',
             'encodedFile'      => $encodedFile,
             'format'           => 'txt',
@@ -318,7 +685,6 @@ class ResControllerTest extends TestCase
         $request        = \Slim\Http\Request::createFromEnvironment($environment);
 
         $aArgs = [
-            'modelId'          => 1,
             'status'           => 'NEW',
             'encodedFile'      => $encodedFile,
             'confidentiality'  => true,
@@ -369,6 +735,429 @@ class ResControllerTest extends TestCase
         $responseBody = json_decode((string)$response->getBody(), true);
         $this->assertSame('Route resId is not an integer',  $responseBody['errors']);
 
+        // Errors from ResourceControlControllers->controlUpdateResource
+        $body = [];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body is not set or empty', $responseBody['errors']);
+
+        \Resource\models\ResModel::update([
+            'set'   => ['status' => ''],
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+
+        $body = [
+            'doctype'  => 102
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Resource status is empty. It can not be modified', $responseBody['errors']);
+
+        \Resource\models\ResModel::update([
+            'set'   => ['status' => 'TMP'],
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+
+        $body = [
+            'doctype'  => 102
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Resource can not be modified because of status', $responseBody['errors']);
+
+        \Resource\models\ResModel::update([
+            'set'   => ['status' => 'NEW'],
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+
+        $body = [
+            'doctype'  => 102000
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body doctype does not exist', $responseBody['errors']);
+
+        $body = [
+            'encodedFile' => ''
+        ];
+        $queryParams = ['onlyDocument' => true ];
+        $fullRequest = $request->withQueryParams($queryParams);
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $fullRequest);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body encodedFile is not set or empty', $responseBody['errors']);
+
+        $externalId = ['signatureBookId' => 42];
+        \Resource\models\ResModel::update([
+            'set'   => ['external_id' => json_encode($externalId)],
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+
+        $body = [
+            'encodedFile' => $encodedFile
+        ];
+        $queryParams = ['onlyDocument' => true ];
+        $fullRequest = $request->withQueryParams($queryParams);
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $fullRequest);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Resource is in external signature book, file can not be modified', $responseBody['errors']);
+
+
+        $externalId = [];
+        \Resource\models\ResModel::update([
+            'set'   => ['external_id' => json_encode($externalId)],
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+        \Convert\models\AdrModel::createDocumentAdr([
+            'resId'         => self::$id,
+            'type'          => 'SIGN',
+            'docserverId'   => 'docserver_id',
+            'path'          => 'directory',
+            'filename'      => 'file_destination_name',
+            'version'       => 2,
+            'fingerprint'   => '1'
+        ]);
+
+        $body = [
+            'encodedFile' => $encodedFile
+        ];
+        $queryParams = ['onlyDocument' => true ];
+        $fullRequest = $request->withQueryParams($queryParams);
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $fullRequest);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Resource is signed, file can not be modified', $responseBody['errors']);
+
+        \Convert\models\AdrModel::deleteDocumentAdr([
+            'where' => ['res_id = ?', 'type = ?'],
+            'data' => [self::$id, 'SIGN']
+        ]);
+
+        \Resource\models\ResModel::update([
+            'set'   => ['format' => 'css'],
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+
+        $body = [
+            'encodedFile' => $encodedFile
+        ];
+        $queryParams = ['onlyDocument' => true ];
+        $fullRequest = $request->withQueryParams($queryParams);
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $fullRequest);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Resource is not convertible, file can not be modified', $responseBody['errors']);
+
+        \Resource\models\ResModel::update([
+            'set'   => ['format' => 'txt'],
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+
+        $body = [
+            'doctype' => 102,
+            'tags'    => 'wrong format'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body tags is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype'   => 102,
+            'initiator' => 10000
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body priority is not set', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'initiator'        => 10000,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body initiator does not exist', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'initiator'        => 10,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body initiator does not belong to your entities', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body documentDate is not a date', $responseBody['errors']);
+
+        // test control custom fields
+        \IndexingModel\models\IndexingModelFieldModel::create([
+            'model_id'   => 1,
+            'identifier' => 'indexingCustomField_1',
+            'mandatory'  => 'true',
+            'unit'       => 'mail'
+        ]);
+        \IndexingModel\models\IndexingModelFieldModel::create([
+            'model_id'   => 1,
+            'identifier' => 'indexingCustomField_2',
+            'mandatory'  => 'false',
+            'unit'       => 'mail'
+        ]);
+        \IndexingModel\models\IndexingModelFieldModel::create([
+            'model_id'   => 1,
+            'identifier' => 'indexingCustomField_3',
+            'mandatory'  => 'false',
+            'unit'       => 'mail'
+        ]);
+        \IndexingModel\models\IndexingModelFieldModel::create([
+            'model_id'   => 1,
+            'identifier' => 'indexingCustomField_4',
+            'mandatory'  => 'false',
+            'unit'       => 'mail'
+        ]);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[1] is empty', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [1 => 'wrong format']
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[1] is not a date', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [
+                1 => '2029-01-01',
+                3 => 'Mail printed with Paper form Dunder Mifflin Paper Company Inc.'
+            ]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[3] has wrong value', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [
+                1 => '2029-01-01',
+                4 => 42 // wrong format
+            ]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[4] is not a string', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [
+                1 => '2029-01-01',
+                2 => ['wrong format']
+            ]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[2] is not an array', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [
+                1 => '2029-01-01',
+                2 => [['address' => 'yes']]
+            ]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[2] longitude is empty', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [
+                1 => '2029-01-01',
+                2 => [
+                    [
+                        'longitude' => '1'
+                    ]
+                ]
+            ]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[2] latitude is empty', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [
+                1 => '2029-01-01',
+                2 => [
+                    [
+                        'longitude' => '1',
+                        'latitude' => '1'
+                    ]
+                ]
+            ]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[2] addressTown is empty', $responseBody['errors']);
+
+        $body = [
+            'doctype'          => 102,
+            'priority'         => 'poiuytre1357nbvc',
+            'documentDate'     => 'wrong format',
+            'arrivalDate'      => 'wrong format',
+            'subject'          => 'Permit to expend Slaughter house in  Schrute Farms',
+            'senders'          => [['type' => 'contact', 'id' => 1]],
+            'destination'      => 15,
+            'processLimitDate' => '2029-01-01',
+            'customFields'     => [
+                1 => '2029-01-01',
+                2 => [
+                    [
+                        'longitude'   => '1',
+                        'latitude'    => '1',
+                        'addressTown' => '1'
+                    ]
+                ]
+            ]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Body customFields[2] addressPostcode is empty', $responseBody['errors']);
+
         $GLOBALS['login'] = 'ddur';
         $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
         $GLOBALS['id'] = $userInfo['id'];
@@ -386,6 +1175,11 @@ class ResControllerTest extends TestCase
             'where' => ['id = ?'],
             'data'  => [$folder]
         ]);
+
+        \IndexingModel\models\IndexingModelFieldModel::delete([
+            'where' => ['identifier in (?)', 'model_id = ?'],
+            'data'  => [['indexingCustomField_1', 'indexingCustomField_2', 'indexingCustomField_3', 'indexingCustomField_4'], 1]
+        ]);
     }
       
     public function testGetOriginalContent()
@@ -1192,12 +1986,21 @@ class ResControllerTest extends TestCase
 
         \Resource\models\ResModel::delete([
             'where' => ['res_id = ?'],
-            'data' => [self::$id2]
+            'data'  => [self::$id2]
         ]);
 
         $res = \Resource\models\ResModel::getById(['resId' => self::$id2, 'select' => ['*']]);
         $this->assertIsArray($res);
         $this->assertEmpty($res);
+
+        \Resource\models\ResModel::delete([
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id3]
+        ]);
+
+        $res = \Resource\models\ResModel::getById(['resId' => self::$id3, 'select' => ['*']]);
+        $this->assertIsArray($res);
+        $this->assertEmpty($res);
     }
 
     public function testCreateMultipleDocument()
@@ -1269,4 +2072,42 @@ class ResControllerTest extends TestCase
         $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
         $GLOBALS['id'] = $userInfo['id'];
     }
+
+    public function testGetBytesSizeFromPhpIni()
+    {
+        $size = '1K';
+        $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
+        $this->assertSame(1024, $byteSize );
+
+        $size = '1M';
+        $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
+        $this->assertSame(1048576, $byteSize );
+
+        $size = '1G';
+        $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
+        $this->assertSame(1073741824, $byteSize );
+
+        $size = 1;
+        $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
+        $this->assertSame(1, $byteSize );
+    }
+
+    public function testGetFormattedSizeFromBytes()
+    {
+        $size = 1073741824 + 1;
+        $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
+        $this->assertSame(round($size / 1073741824) . ' Go', $formatted );
+
+        $size = 1048576 + 1;
+        $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
+        $this->assertSame(round($size / 1048576) . ' Mo', $formatted );
+
+        $size = 1024 + 1;
+        $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
+        $this->assertSame(round($size / 1024) . ' Ko', $formatted );
+
+        $size = 1;
+        $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
+        $this->assertSame('1 o', $formatted );
+    }
 }
diff --git a/test/unitTests/app/resource/ResourceListControllerTest.php b/test/unitTests/app/resource/ResourceListControllerTest.php
index 0eac70819cc..196a2de8703 100644
--- a/test/unitTests/app/resource/ResourceListControllerTest.php
+++ b/test/unitTests/app/resource/ResourceListControllerTest.php
@@ -13,10 +13,39 @@ class ResourceListControllerTest extends TestCase
 {
     public function testGet()
     {
+        $listDisplay = \Basket\models\GroupBasketModel::get([
+            'select' => ['list_display'],
+            'where' => ['basket_id = ?', 'group_id = ?'],
+            'data'  => ['MyBasket', 'AGENT']
+        ]);
+        $listDisplay = json_decode($listDisplay[0]['list_display'], true);
+        $listDisplay[] = ['value' => 'getVisaWorkflow', 'cssClasses' => ['align_leftData'], 'icon' => 'fa-list-ol'];
+        $listDisplay[] = ['value' => 'getSignatories', 'cssClasses' => ['align_leftData'], 'icon' => 'fa-list-ol'];
+        $listDisplay[] = ['value' => 'getParallelOpinionsNumber', 'cssClasses' => ['align_leftData'], 'icon' => 'fa-list-ol'];
+
+        \Basket\models\GroupBasketModel::update([
+            'set'   => ['list_display' => json_encode($listDisplay)],
+            'where' => ['basket_id = ?', 'group_id = ?'],
+            'data'  => ['MyBasket', 'AGENT']
+        ]);
+
+        $userInfo = \User\models\UserModel::getByLogin(['login' => 'bbain', 'select' => ['id']]);
+
+        \Entity\models\ListInstanceModel::create([
+            'res_id'              => $GLOBALS['resources'][0],
+            'sequence'            => 0,
+            'item_id'             => $userInfo['id'],
+            'item_type'           => 'user_id',
+            'item_mode'           => 'dest',
+            'added_by_user'       => $GLOBALS['id'],
+            'viewed'              => 0,
+            'difflist_type'       => 'VISA_CIRCUIT',
+            'requested_signature' => true,
+        ]);
+
         $GLOBALS['login'] = 'bbain';
-        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
         $GLOBALS['id'] = $userInfo['id'];
-        $myBasket = \Basket\models\BasketModel::getByBasketId(['basketId' => 'MyBasket', 'select' => ['id']]);
+        $myBasket = \Basket\models\BasketModel::getByBasketId(['basketId' => 'MyBasket', 'select' => ['id', 'basket_id']]);
 
         $resListController = new \Resource\controllers\ResourceListController();
 
@@ -181,6 +210,31 @@ class ResourceListControllerTest extends TestCase
         $this->assertIsArray($responseBody->statuses);
         $this->assertIsArray($responseBody->entitiesChildren);
 
+        $aArgs = [
+            'priorities'       => 'poiuytre1379nbvc,poiuytre1391nbvc',
+            'categories'       => 'incoming',
+            'entitiesChildren' => 'PJS',
+            'doctypes' => 102,
+            'entities' => 'PJS',
+            'folders' => '1'
+        ];
+        $fullRequest = $request->withQueryParams($aArgs);
+
+        $response     = $resListController->getFilters($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => $myBasket['id']]);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertIsArray($responseBody->entities);
+        $this->assertIsArray($responseBody->priorities);
+        $this->assertIsArray($responseBody->categories);
+        $this->assertIsArray($responseBody->statuses);
+        $this->assertIsArray($responseBody->entitiesChildren);
+
+        // Errors
+        $response     = $resListController->getFilters($request, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => $myBasket['id'] * 1000]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Group or basket does not exist', $responseBody['errors']);
+
         $GLOBALS['login'] = 'superadmin';
         $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
         $GLOBALS['id'] = $userInfo['id'];
@@ -199,11 +253,201 @@ class ResourceListControllerTest extends TestCase
         $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
         $request        = \Slim\Http\Request::createFromEnvironment($environment);
 
-        $response     = $resListController->getActions($request, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => $myBasket['id']]);
+        $queryParams = ['resId' => $GLOBALS['resources'][0]];
+        $fullRequest = $request->withQueryParams($queryParams);
+        $response     = $resListController->getActions($fullRequest, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => $myBasket['id']]);
+        $this->assertSame(200, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+
+        $this->assertIsArray($responseBody['actions']);
+        $this->assertNotNull($responseBody['actions']);
+
+        // Errors
+        $response     = $resListController->getActions($request, new \Slim\Http\Response(), ['userId' => 19, 'groupId' => 2, 'basketId' => $myBasket['id'] * 1000]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Group or basket does not exist', $responseBody['errors']);
+
+        $GLOBALS['login'] = 'superadmin';
+        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
+        $GLOBALS['id'] = $userInfo['id'];
+    }
+
+    public function testSetAction()
+    {
+        $GLOBALS['login'] = 'bbain';
+        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
+        $GLOBALS['id'] = $userInfo['id'];
+
+        $resListController = new \Resource\controllers\ResourceListController();
+        $myBasket = \Basket\models\BasketModel::getByBasketId(['basketId' => 'MyBasket', 'select' => ['id']]);
+
+        // GET
+        // ERROR
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response     = $resListController->setAction($request, new \Slim\Http\Response(), []);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Data resources is empty or not an array', $responseBody['errors']);
+
+
+        $body = [
+            'resources' => [1]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->setAction($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 10000 ]);
+        $this->assertSame(403, $response->getStatusCode());
         $responseBody = json_decode((string)$response->getBody());
+        $this->assertSame('Group or basket does not exist', $responseBody->errors);
 
-        $this->assertIsArray($responseBody->actions);
-        $this->assertNotNull($responseBody->actions);
+        $body = [
+            'resources' => [1]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->setAction($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 1 ]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody());
+        $this->assertSame('Group is not linked to this user', $responseBody->errors);
+
+        $body = [
+            'resources' => [1]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->setAction($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 2, 'actionId' => 2]);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody());
+        $this->assertSame('Action is not linked to this group basket', $responseBody->errors);
+
+        $body = [
+            'resources' => [1]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->setAction($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 2, 'actionId' => 400]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody());
+        $this->assertSame('Resources out of perimeter', $responseBody->errors);
+
+        // Success
+        \Resource\models\ResModel::update([
+            'set'   => ['status' => 'NEW'],
+            'where' => ['res_id = ?'],
+            'data'  => [$GLOBALS['resources'][2]]
+        ]);
+
+        $body = [
+            'resources' => [$GLOBALS['resources'][2]]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->setAction($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 2, 'actionId' => '20']);
+        $this->assertSame(204, $response->getStatusCode());
+
+        \Resource\models\ResModel::update([
+            'set'   => ['status' => 'NEW'],
+            'where' => ['res_id = ?'],
+            'data'  => [$GLOBALS['resources'][2]]
+        ]);
+
+        $GLOBALS['login'] = 'superadmin';
+        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
+        $GLOBALS['id'] = $userInfo['id'];
+    }
+
+    public function testLock()
+    {
+        $GLOBALS['login'] = 'bbain';
+        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
+        $GLOBALS['id'] = $userInfo['id'];
+
+        $resListController = new \Resource\controllers\ResourceListController();
+        $myBasket = \Basket\models\BasketModel::getByBasketId(['basketId' => 'MyBasket', 'select' => ['id']]);
+
+        // GET
+        // ERROR
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response     = $resListController->lock($request, new \Slim\Http\Response(), []);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Data resources is empty or not an array', $responseBody['errors']);
+
+        $body = [
+            'resources' => [1]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->lock($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 10000 ]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Group or basket does not exist', $responseBody['errors']);
+
+        $response     = $resListController->lock($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 2 ]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Resources out of perimeter', $responseBody['errors']);
+
+        // Success
+        $body = [
+            'resources' => [$GLOBALS['resources'][1]]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->lock($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 2 ]);
+        $this->assertSame(200, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+
+        $this->assertSame(0, $responseBody['countLockedResources']);
+        $this->assertIsArray($responseBody['lockers']);
+        $this->assertEmpty($responseBody['lockers']);
+        $this->assertIsArray($responseBody['resourcesToProcess']);
+        $this->assertNotEmpty($responseBody['resourcesToProcess']);
+        $this->assertSame($GLOBALS['resources'][1], $responseBody['resourcesToProcess'][0]);
+
+        $GLOBALS['login'] = 'superadmin';
+        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
+        $GLOBALS['id'] = $userInfo['id'];
+    }
+
+    public function testUnLock()
+    {
+        $GLOBALS['login'] = 'bbain';
+        $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
+        $GLOBALS['id'] = $userInfo['id'];
+
+        $resListController = new \Resource\controllers\ResourceListController();
+        $myBasket = \Basket\models\BasketModel::getByBasketId(['basketId' => 'MyBasket', 'select' => ['id']]);
+
+        // GET
+        // ERROR
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response     = $resListController->unlock($request, new \Slim\Http\Response(), []);
+        $this->assertSame(400, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Data resources is empty or not an array', $responseBody['errors']);
+
+        $body = [
+            'resources' => [1]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->unlock($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 10000 ]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Group or basket does not exist', $responseBody['errors']);
+
+        $response     = $resListController->unlock($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 2 ]);
+        $this->assertSame(403, $response->getStatusCode());
+        $responseBody = json_decode((string)$response->getBody(), true);
+        $this->assertSame('Resources out of perimeter', $responseBody['errors']);
+
+        // Success
+        $body = [
+            'resources' => [$GLOBALS['resources'][1]]
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($body, $request);
+        $response     = $resListController->unlock($fullRequest, new \Slim\Http\Response(), ['userId' => $GLOBALS['id'], 'basketId' => $myBasket['id'], 'groupId' => 2 ]);
+        $this->assertSame(204, $response->getStatusCode());
 
         $GLOBALS['login'] = 'superadmin';
         $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
-- 
GitLab