From d22571bce9a49d6839f1646cf99f61258053d075 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Tue, 30 Jan 2018 11:28:21 +0100
Subject: [PATCH] FEAT #8 Update status unit test

---
 core/Models/UserModelAbstract.php            | 446 ++++++++++---------
 core/Test/ResControllerTest.php              | 131 ++++++
 core/Test/ResExtControllerTest.php           | 420 -----------------
 package-lock.json                            |  19 +-
 phpunit.xml                                  |   3 +-
 src/app/resource/models/ResModelAbstract.php |  21 +-
 6 files changed, 380 insertions(+), 660 deletions(-)
 delete mode 100755 core/Test/ResExtControllerTest.php

diff --git a/core/Models/UserModelAbstract.php b/core/Models/UserModelAbstract.php
index 72b94f7bdac..164ee79e272 100755
--- a/core/Models/UserModelAbstract.php
+++ b/core/Models/UserModelAbstract.php
@@ -4,11 +4,11 @@
  * Copyright Maarch since 2008 under licence GPLv3.
  * See LICENCE.txt file at the root folder for more details.
  * This file is part of Maarch software.
+ *
  */
 
 /**
  * @brief User Model
- *
  * @author dev@maarch.org
  * @ingroup core
  */
@@ -25,10 +25,10 @@ class UserModelAbstract
         ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']);
 
         $aUsers = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table' => ['users'],
-            'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
-            'data' => empty($aArgs['data']) ? [] : $aArgs['data'],
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['users'],
+            'where'     => empty($aArgs['where']) ? [] : $aArgs['where'],
+            'data'      => empty($aArgs['data']) ? [] : $aArgs['data']
         ]);
 
         return $aUsers;
@@ -40,10 +40,10 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['id']);
 
         $aUser = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table' => ['users'],
-            'where' => ['id = ?'],
-            'data' => [$aArgs['id']],
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['users'],
+            'where'     => ['id = ?'],
+            'data'      => [$aArgs['id']]
         ]);
 
         if (empty($aUser)) {
@@ -60,21 +60,21 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs['user'], ['userId', 'firstname', 'lastname', 'mail', 'initials', 'thumbprint', 'phone', 'changePassword']);
 
         DatabaseModel::insert([
-            'table' => 'users',
+            'table'         => 'users',
             'columnsValues' => [
-                'user_id' => $aArgs['user']['userId'],
-                'firstname' => $aArgs['user']['firstname'],
-                'lastname' => $aArgs['user']['lastname'],
-                'mail' => $aArgs['user']['mail'],
-                'phone' => $aArgs['user']['phone'],
-                'initials' => $aArgs['user']['initials'],
-                'thumbprint' => $aArgs['user']['thumbprint'],
-                'enabled' => 'Y',
-                'status' => 'OK',
-                'change_password' => empty($aArgs['user']['changePassword']) ? 'Y' : $aArgs['user']['changePassword'],
-                'loginmode' => 'standard',
-                'password' => SecurityModel::getPasswordHash('maarch'),
-            ],
+                'user_id'           => $aArgs['user']['userId'],
+                'firstname'         => $aArgs['user']['firstname'],
+                'lastname'          => $aArgs['user']['lastname'],
+                'mail'              => $aArgs['user']['mail'],
+                'phone'             => $aArgs['user']['phone'],
+                'initials'          => $aArgs['user']['initials'],
+                'thumbprint'        => $aArgs['user']['thumbprint'],
+                'enabled'           => 'Y',
+                'status'            => 'OK',
+                'change_password'   => empty($aArgs['user']['changePassword']) ? 'Y' : $aArgs['user']['changePassword'],
+                'loginmode'         => 'standard',
+                'password'          => SecurityModel::getPasswordHash('maarch')
+            ]
         ]);
 
         return true;
@@ -88,18 +88,18 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs['user'], ['firstname', 'lastname', 'mail', 'initials', 'thumbprint', 'phone', 'enabled']);
 
         DatabaseModel::update([
-            'table' => 'users',
-            'set' => [
-                'firstname' => $aArgs['user']['firstname'],
-                'lastname' => $aArgs['user']['lastname'],
-                'mail' => $aArgs['user']['mail'],
-                'phone' => $aArgs['user']['phone'],
-                'initials' => $aArgs['user']['initials'],
-                'enabled' => $aArgs['user']['enabled'],
-                'thumbprint' => $aArgs['user']['thumbprint'],
+            'table'     => 'users',
+            'set'       => [
+                'firstname'     => $aArgs['user']['firstname'],
+                'lastname'      => $aArgs['user']['lastname'],
+                'mail'          => $aArgs['user']['mail'],
+                'phone'         => $aArgs['user']['phone'],
+                'initials'      => $aArgs['user']['initials'],
+                'enabled'       => $aArgs['user']['enabled'],
+                'thumbprint'    => $aArgs['user']['thumbprint']
             ],
-            'where' => ['id = ?'],
-            'data' => [$aArgs['id']],
+            'where'     => ['id = ?'],
+            'data'      => [$aArgs['id']]
         ]);
 
         return true;
@@ -111,12 +111,12 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['id']);
 
         DatabaseModel::update([
-            'table' => 'users',
-            'set' => [
-                'status' => 'DEL',
+            'table'     => 'users',
+            'set'       => [
+                'status'    => 'DEL',
             ],
-            'where' => ['id = ?'],
-            'data' => [$aArgs['id']],
+            'where'     => ['id = ?'],
+            'data'      => [$aArgs['id']]
         ]);
 
         return true;
@@ -128,10 +128,10 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId']);
 
         $aUser = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table' => ['users'],
-            'where' => ['user_id = ?'],
-            'data' => [$aArgs['userId']],
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['users'],
+            'where'     => ['user_id = ?'],
+            'data'      => [$aArgs['userId']]
         ]);
 
         if (empty($aUser)) {
@@ -147,10 +147,10 @@ class UserModelAbstract
         ValidatorModel::arrayType($aArgs, ['entities']);
 
         $aUsers = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table' => ['users, users_entities'],
-            'where' => ['users.user_id = users_entities.user_id', 'users_entities.entity_id in (?)'],
-            'data' => [$aArgs['entities']],
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['users, users_entities'],
+            'where'     => ['users.user_id = users_entities.user_id', 'users_entities.entity_id in (?)'],
+            'data'      => [$aArgs['entities']]
         ]);
 
         return $aUsers;
@@ -162,11 +162,11 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['mail']);
 
         $aUser = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table' => ['users'],
-            'where' => ['mail = ? and status = ?'],
-            'data' => [$aArgs['mail'], 'OK'],
-            'limit' => 1,
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['users'],
+            'where'     => ['mail = ? and status = ?'],
+            'data'      => [$aArgs['mail'], 'OK'],
+            'limit'     => 1
         ]);
 
         return $aUser;
@@ -179,12 +179,12 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['password']);
 
         DatabaseModel::update([
-            'table' => 'users',
-            'set' => [
-                'password' => SecurityModel::getPasswordHash($aArgs['password']),
+            'table'     => 'users',
+            'set'       => [
+                'password'  => SecurityModel::getPasswordHash($aArgs['password'])
             ],
-            'where' => ['id = ?'],
-            'data' => [$aArgs['id']],
+            'where'     => ['id = ?'],
+            'data'      => [$aArgs['id']]
         ]);
 
         return true;
@@ -196,12 +196,12 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['id']);
 
         DatabaseModel::update([
-            'table' => 'users',
-            'set' => [
-                'password' => SecurityModel::getPasswordHash('maarch'),
+            'table'     => 'users',
+            'set'       => [
+                'password'  => SecurityModel::getPasswordHash('maarch')
             ],
-            'where' => ['id = ?'],
-            'data' => [$aArgs['id']],
+            'where'     => ['id = ?'],
+            'data'      => [$aArgs['id']]
         ]);
 
         return true;
@@ -214,13 +214,13 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['userSerialId']);
 
         DatabaseModel::insert([
-            'table' => 'user_signatures',
+            'table'         => 'user_signatures',
             'columnsValues' => [
-                'user_serial_id' => $aArgs['userSerialId'],
-                'signature_label' => $aArgs['signatureLabel'],
-                'signature_path' => $aArgs['signaturePath'],
-                'signature_file_name' => $aArgs['signatureFileName'],
-            ],
+                'user_serial_id'        => $aArgs['userSerialId'],
+                'signature_label'       => $aArgs['signatureLabel'],
+                'signature_path'        => $aArgs['signaturePath'],
+                'signature_file_name'   => $aArgs['signatureFileName']
+            ]
         ]);
 
         return true;
@@ -233,12 +233,12 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['signatureId', 'userSerialId']);
 
         DatabaseModel::update([
-            'table' => 'user_signatures',
-            'set' => [
-                'signature_label' => $aArgs['label'],
+            'table'     => 'user_signatures',
+            'set'       => [
+                'signature_label'   => $aArgs['label']
             ],
-            'where' => ['user_serial_id = ?', 'id = ?'],
-            'data' => [$aArgs['userSerialId'], $aArgs['signatureId']],
+            'where'     => ['user_serial_id = ?', 'id = ?'],
+            'data'      => [$aArgs['userSerialId'], $aArgs['signatureId']]
         ]);
 
         return true;
@@ -250,9 +250,9 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['signatureId', 'userSerialId']);
 
         DatabaseModel::delete([
-            'table' => 'user_signatures',
-            'where' => ['user_serial_id = ?', 'id = ?'],
-            'data' => [$aArgs['userSerialId'], $aArgs['signatureId']],
+            'table'     => 'user_signatures',
+            'where'     => ['user_serial_id = ?', 'id = ?'],
+            'data'      => [$aArgs['userSerialId'], $aArgs['signatureId']],
         ]);
 
         return true;
@@ -264,12 +264,12 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId', 'title', 'htmlBody']);
 
         DatabaseModel::insert([
-            'table' => 'users_email_signatures',
+            'table'         => 'users_email_signatures',
             'columnsValues' => [
-                'user_id' => $aArgs['userId'],
-                'title' => $aArgs['title'],
-                'html_body' => $aArgs['htmlBody'],
-            ],
+                'user_id'   => $aArgs['userId'],
+                'title'     => $aArgs['title'],
+                'html_body' => $aArgs['htmlBody']
+            ]
         ]);
 
         return true;
@@ -277,18 +277,18 @@ class UserModelAbstract
 
     public static function updateEmailSignature(array $aArgs = [])
     {
-        ValidatorModel::notEmpty($aArgs, ['id', 'userId', 'title', 'htmlBody']);
+        ValidatorModel::notEmpty($aArgs, ['id','userId', 'title', 'htmlBody']);
         ValidatorModel::stringType($aArgs, ['userId', 'title', 'htmlBody']);
         ValidatorModel::intVal($aArgs, ['id']);
 
         DatabaseModel::update([
-            'table' => 'users_email_signatures',
-            'set' => [
-                'title' => $aArgs['title'],
+            'table'     => 'users_email_signatures',
+            'set'       => [
+                'title'     => $aArgs['title'],
                 'html_body' => $aArgs['htmlBody'],
             ],
-            'where' => ['user_id = ?', 'id = ?'],
-            'data' => [$aArgs['userId'], $aArgs['id']],
+            'where'     => ['user_id = ?', 'id = ?'],
+            'data'      => [$aArgs['userId'], $aArgs['id']]
         ]);
 
         return true;
@@ -300,9 +300,9 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId']);
 
         DatabaseModel::delete([
-            'table' => 'users_email_signatures',
-            'where' => ['user_id = ?', 'id = ?'],
-            'data' => [$aArgs['userId'], $aArgs['id']],
+            'table'     => 'users_email_signatures',
+            'where'     => ['user_id = ?', 'id = ?'],
+            'data'      => [$aArgs['userId'], $aArgs['id']]
         ]);
 
         return true;
@@ -314,11 +314,11 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['id']);
 
         $aReturn = DatabaseModel::select([
-            'select' => ['id', 'user_serial_id', 'signature_label', 'signature_path', 'signature_file_name'],
-            'table' => ['user_signatures'],
-            'where' => ['user_serial_id = ?'],
-            'data' => [$aArgs['id']],
-            'order_by' => ['id'],
+            'select'    => ['id', 'user_serial_id', 'signature_label', 'signature_path', 'signature_file_name'],
+            'table'     => ['user_signatures'],
+            'where'     => ['user_serial_id = ?'],
+            'data'      => [$aArgs['id']],
+            'order_by'  => ['id']
         ]);
 
         $docserver = [];
@@ -330,16 +330,16 @@ class UserModelAbstract
             return [];
         }
         $tmpPath = CoreConfigModel::getTmpPath();
-        $urlTmpPath = str_replace('rest/', '', \Url::coreurl()).'apps/maarch_entreprise/tmp/';
-        foreach ($aReturn as $key => $value) {
-            $pathToSignature = $docserver['path_template'].str_replace('#', '/', $value['signature_path']).$value['signature_file_name'];
+        $urlTmpPath = str_replace('rest/', '', \Url::coreurl()) . 'apps/maarch_entreprise/tmp/';
+        foreach($aReturn as $key => $value) {
+            $pathToSignature = $docserver['path_template'] . str_replace('#', '/', $value['signature_path']) . $value['signature_file_name'];
 
             $extension = explode('.', $pathToSignature);
             $extension = $extension[count($extension) - 1];
-            $fileNameOnTmp = 'tmp_file_'.$aArgs['id'].'_'.rand().'.'.strtolower($extension);
-            $filePathOnTmp = $tmpPath.$fileNameOnTmp;
+            $fileNameOnTmp = 'tmp_file_' . $aArgs['id'] . '_' . rand() . '.' . strtolower($extension);
+            $filePathOnTmp = $tmpPath . $fileNameOnTmp;
             if (file_exists($pathToSignature) && copy($pathToSignature, $filePathOnTmp)) {
-                $aReturn[$key]['pathToSignatureOnTmp'] = $urlTmpPath.$fileNameOnTmp;
+                $aReturn[$key]['pathToSignatureOnTmp'] = $urlTmpPath . $fileNameOnTmp;
             } else {
                 $aReturn[$key]['pathToSignatureOnTmp'] = '';
             }
@@ -354,13 +354,13 @@ class UserModelAbstract
     public static function getSignatureWithSignatureIdById(array $aArgs = [])
     {
         ValidatorModel::notEmpty($aArgs, ['id', 'signatureId']);
-        ValidatorModel::intVal($aArgs, ['id', 'signatureId']);
+        ValidatorModel::intVal($aArgs, ['id','signatureId']);
 
         $aReturn = DatabaseModel::select([
-            'select' => ['id', 'user_serial_id', 'signature_label'],
-            'table' => ['user_signatures'],
-            'where' => ['user_serial_id = ?', 'id = ?'],
-            'data' => [$aArgs['id'], $aArgs['signatureId']],
+            'select'    => ['id', 'user_serial_id', 'signature_label'],
+            'table'     => ['user_signatures'],
+            'where'     => ['user_serial_id = ?', 'id = ?'],
+            'data'      => [$aArgs['id'], $aArgs['signatureId']],
         ]);
 
         return $aReturn[0];
@@ -372,11 +372,11 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId']);
 
         $aReturn = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table' => ['users_email_signatures'],
-            'where' => ['user_id = ?'],
-            'data' => [$aArgs['userId']],
-            'order_by' => ['id'],
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['users_email_signatures'],
+            'where'     => ['user_id = ?'],
+            'data'      => [$aArgs['userId']],
+            'order_by'  => ['id']
         ]);
 
         return $aReturn;
@@ -389,10 +389,10 @@ class UserModelAbstract
         ValidatorModel::intVal($aArgs, ['signatureId']);
 
         $aReturn = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table' => ['users_email_signatures'],
-            'where' => ['user_id = ?', 'id = ?'],
-            'data' => [$aArgs['userId'], $aArgs['signatureId']],
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['users_email_signatures'],
+            'where'     => ['user_id = ?', 'id = ?'],
+            'data'      => [$aArgs['userId'], $aArgs['signatureId']],
         ]);
 
         return $aReturn[0];
@@ -411,7 +411,7 @@ class UserModelAbstract
 
         $labelledUser = '';
         if (!empty($rawUser)) {
-            $labelledUser = $rawUser['firstname'].' '.$rawUser['lastname'];
+            $labelledUser = $rawUser['firstname']. ' ' .$rawUser['lastname'];
         }
 
         return $labelledUser;
@@ -422,13 +422,14 @@ class UserModelAbstract
         ValidatorModel::notEmpty($aArgs, ['resId']);
         ValidatorModel::intVal($aArgs, ['resId']);
 
+
         $aReturn = DatabaseModel::select([
-            'select' => ['process_comment'],
-            'table' => ['listinstance'],
-            'where' => ['res_id = ?', 'process_date is null', 'item_mode in (?)'],
-            'data' => [$aArgs['resId'], ['visa', 'sign']],
-            'order_by' => ['listinstance_id ASC'],
-            'limit' => 1,
+            'select'    => ['process_comment'],
+            'table'     => ['listinstance'],
+            'where'     => ['res_id = ?', 'process_date is null', 'item_mode in (?)'],
+            'data'      => [$aArgs['resId'], ['visa', 'sign']],
+            'order_by'  => ['listinstance_id ASC'],
+            'limit'     => 1
         ]);
 
         if (empty($aReturn[0])) {
@@ -443,11 +444,12 @@ class UserModelAbstract
         ValidatorModel::notEmpty($aArgs, ['userId']);
         ValidatorModel::stringType($aArgs, ['userId']);
 
+
         $aGroup = DatabaseModel::select([
-            'select' => ['usergroup_content.group_id', 'usergroups.group_desc'],
-            'table' => ['usergroup_content, usergroups'],
-            'where' => ['usergroup_content.group_id = usergroups.group_id', 'usergroup_content.user_id = ?', 'usergroup_content.primary_group = ?'],
-            'data' => [$aArgs['userId'], 'Y'],
+            'select'    => ['usergroup_content.group_id', 'usergroups.group_desc'],
+            'table'     => ['usergroup_content, usergroups'],
+            'where'     => ['usergroup_content.group_id = usergroups.group_id', 'usergroup_content.user_id = ?', 'usergroup_content.primary_group = ?'],
+            'data'      => [$aArgs['userId'], 'Y']
         ]);
 
         if (empty($aGroup[0])) {
@@ -463,10 +465,10 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId']);
 
         $aEntity = DatabaseModel::select([
-            'select' => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity'],
-            'table' => ['users_entities, entities'],
-            'where' => ['users_entities.entity_id = entities.entity_id', 'users_entities.user_id = ?', 'users_entities.primary_entity = ?'],
-            'data' => [$aArgs['userId'], 'Y'],
+            'select'    => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity'],
+            'table'     => ['users_entities, entities'],
+            'where'     => ['users_entities.entity_id = entities.entity_id', 'users_entities.user_id = ?', 'users_entities.primary_entity = ?'],
+            'data'      => [$aArgs['userId'], 'Y']
         ]);
 
         if (empty($aEntity[0])) {
@@ -482,10 +484,10 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId']);
 
         $aGroups = DatabaseModel::select([
-            'select' => ['usergroup_content.group_id', 'usergroups.group_desc', 'usergroup_content.primary_group', 'usergroup_content.role', 'security.maarch_comment', 'security.where_clause'],
-            'table' => ['usergroup_content, usergroups, security'],
-            'where' => ['usergroup_content.group_id = usergroups.group_id', 'usergroup_content.user_id = ?', 'usergroups.group_id = security.group_id'],
-            'data' => [$aArgs['userId']],
+            'select'    => ['usergroup_content.group_id', 'usergroups.group_desc', 'usergroup_content.primary_group', 'usergroup_content.role', 'security.maarch_comment', 'security.where_clause'],
+            'table'     => ['usergroup_content, usergroups, security'],
+            'where'     => ['usergroup_content.group_id = usergroups.group_id', 'usergroup_content.user_id = ?','usergroups.group_id = security.group_id'],
+            'data'      => [$aArgs['userId']]
         ]);
 
         return $aGroups;
@@ -497,11 +499,11 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId']);
 
         $aEntities = DatabaseModel::select([
-            'select' => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity'],
-            'table' => ['users_entities, entities'],
-            'where' => ['users_entities.entity_id = entities.entity_id', 'users_entities.user_id = ?'],
-            'data' => [$aArgs['userId']],
-            'order_by' => ['users_entities.primary_entity DESC'],
+            'select'    => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity'],
+            'table'     => ['users_entities, entities'],
+            'where'     => ['users_entities.entity_id = entities.entity_id', 'users_entities.user_id = ?'],
+            'data'      => [$aArgs['userId']],
+            'order_by'  => ['users_entities.primary_entity DESC']
         ]);
 
         return $aEntities;
@@ -513,10 +515,10 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['userId']);
 
         $aServices = DatabaseModel::select([
-            'select' => ['usergroups_services.service_id'],
-            'table' => ['usergroup_content, usergroups_services'],
-            'where' => ['usergroup_content.group_id = usergroups_services.group_id', 'usergroup_content.user_id = ?'],
-            'data' => [$aArgs['userId']],
+            'select'    => ['usergroups_services.service_id'],
+            'table'     => ['usergroup_content, usergroups_services'],
+            'where'     => ['usergroup_content.group_id = usergroups_services.group_id', 'usergroup_content.user_id = ?'],
+            'data'      => [$aArgs['userId']]
         ]);
 
         return $aServices;
@@ -529,12 +531,12 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['status']);
 
         DatabaseModel::update([
-            'table' => 'users',
-            'set' => [
-                'status' => $aArgs['status'],
+            'table'     => 'users',
+            'set'       => [
+                'status'    => $aArgs['status']
             ],
-            'where' => ['id = ?'],
-            'data' => [$aArgs['id']],
+            'where'     => ['id = ?'],
+            'data'      => [$aArgs['id']]
         ]);
 
         return true;
@@ -565,23 +567,23 @@ class UserModelAbstract
 
         $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]);
         DatabaseModel::insert([
-            'table' => 'usergroup_content',
+            'table'         => 'usergroup_content',
             'columnsValues' => [
-                'user_id' => $user['user_id'],
-                'group_id' => $aArgs['groupId'],
-                'role' => $aArgs['role'],
-                'primary_group' => 'Y',
-            ],
+                'user_id'       => $user['user_id'],
+                'group_id'      => $aArgs['groupId'],
+                'role'          => $aArgs['role'],
+                'primary_group' => 'Y'
+            ]
         ]);
 
-        $groupInfos = GroupModel::getByGroupId(['groupId' => $aArgs['groupId']]);
+        $groupInfos = GroupModel::getById(['groupId' => $aArgs['groupId']]);
 
         HistoryController::add([
             'tableName' => 'users',
-            'recordId' => $user['user_id'],
+            'recordId'  =>$user['user_id'],
             'eventType' => 'GROUP ADD',
-            'eventId' => 'groupadded',
-            'info' => $_SESSION['user']['UserId'].' '._ADDED_USER.' '.$user['user_id'].' '._IN_GROUP.' '.$groupInfos['group_desc'],
+            'eventId'   => 'groupadded',
+            'info'       =>$_SESSION['user']['UserId'].' '._ADDED_USER.' '.$user['user_id'].' '._IN_GROUP.' '.$groupInfos['group_desc']
         ]);
 
         return true;
@@ -595,12 +597,12 @@ class UserModelAbstract
 
         $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]);
         DatabaseModel::update([
-            'table' => 'usergroup_content',
-            'set' => [
-                'role' => $aArgs['role'],
+            'table'     => 'usergroup_content',
+            'set'       => [
+                'role'      => $aArgs['role']
             ],
-            'where' => ['user_id = ?', 'group_id = ?'],
-            'data' => [$user['user_id'], $aArgs['groupId']],
+            'where'     => ['user_id = ?', 'group_id = ?'],
+            'data'      => [$user['user_id'], $aArgs['groupId']]
         ]);
 
         return true;
@@ -614,19 +616,19 @@ class UserModelAbstract
 
         $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]);
         DatabaseModel::delete([
-            'table' => 'usergroup_content',
-            'where' => ['group_id = ?', 'user_id = ?'],
-            'data' => [$aArgs['groupId'], $user['user_id']],
+            'table'     => 'usergroup_content',
+            'where'     => ['group_id = ?', 'user_id = ?'],
+            'data'      => [$aArgs['groupId'], $user['user_id']]
         ]);
 
-        $groupInfos = GroupModel::getByGroupId(['groupId' => $aArgs['groupId']]);
+        $groupInfos = GroupModel::getById(['groupId' => $aArgs['groupId']]);
 
         HistoryController::add([
             'tableName' => 'users',
-            'recordId' => $user['user_id'],
+            'recordId'  =>$user['user_id'],
             'eventType' => 'GROUP DELETED',
-            'eventId' => 'groupdeleted',
-            'info' => $_SESSION['user']['UserId'].' '._REMOVED_USER.' '.$user['user_id'].' '._FROM_GROUP.' '.$groupInfos['group_desc'],
+            'eventId'   => 'groupdeleted',
+            'info'       =>$_SESSION['user']['UserId'].' '._REMOVED_USER.' '.$user['user_id'].' '._FROM_GROUP.' '.$groupInfos['group_desc']
         ]);
 
         return true;
@@ -657,23 +659,23 @@ class UserModelAbstract
 
         $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]);
         DatabaseModel::insert([
-            'table' => 'users_entities',
+            'table'         => 'users_entities',
             'columnsValues' => [
-                'user_id' => $user['user_id'],
-                'entity_id' => $aArgs['entityId'],
-                'user_role' => $aArgs['role'],
-                'primary_entity' => $aArgs['primaryEntity'],
-            ],
+                'user_id'           => $user['user_id'],
+                'entity_id'         => $aArgs['entityId'],
+                'user_role'         => $aArgs['role'],
+                'primary_entity'    => $aArgs['primaryEntity']
+            ]
         ]);
 
         $entityInfos = EntityModel::getByID(['entityId' => $aArgs['entityId']]);
 
         HistoryController::add([
             'tableName' => 'users',
-            'recordId' => $user['user_id'],
+            'recordId'  => $user['user_id'],
             'eventType' => 'ENTITY ADD',
-            'eventId' => 'entityadded',
-            'info' => $_SESSION['user']['UserId'].' '._ADDED_USER.' '.$user['user_id'].' '._IN_ENTITY.' '.$entityInfos['entity_label'],
+            'eventId'   => 'entityadded',
+            'info'       => $_SESSION['user']['UserId'].' '._ADDED_USER.' '.$user['user_id'].' '._IN_ENTITY.' '.$entityInfos['entity_label']
         ]);
 
         return true;
@@ -687,12 +689,12 @@ class UserModelAbstract
 
         $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]);
         DatabaseModel::update([
-            'table' => 'users_entities',
-            'set' => [
-                'user_role' => $aArgs['role'],
+            'table'     => 'users_entities',
+            'set'       => [
+                'user_role'      => $aArgs['role']
             ],
-            'where' => ['user_id = ?', 'entity_id = ?'],
-            'data' => [$user['user_id'], $aArgs['entityId']],
+            'where'     => ['user_id = ?', 'entity_id = ?'],
+            'data'      => [$user['user_id'], $aArgs['entityId']]
         ]);
 
         return true;
@@ -709,23 +711,23 @@ class UserModelAbstract
         foreach ($entities as $entity) {
             if ($entity['primary_entity'] == 'Y') {
                 DatabaseModel::update([
-                    'table' => 'users_entities',
-                    'set' => [
-                        'primary_entity' => 'N',
+                    'table'     => 'users_entities',
+                    'set'       => [
+                        'primary_entity'    => 'N'
                     ],
-                    'where' => ['user_id = ?', 'entity_id = ?'],
-                    'data' => [$user['user_id'], $entity['entity_id']],
+                    'where'     => ['user_id = ?', 'entity_id = ?'],
+                    'data'      => [$user['user_id'], $entity['entity_id']]
                 ]);
             }
         }
 
         DatabaseModel::update([
-            'table' => 'users_entities',
-            'set' => [
-                'primary_entity' => 'Y',
+            'table'     => 'users_entities',
+            'set'       => [
+                'primary_entity'    => 'Y'
             ],
-            'where' => ['user_id = ?', 'entity_id = ?'],
-            'data' => [$user['user_id'], $aArgs['entityId']],
+            'where'     => ['user_id = ?', 'entity_id = ?'],
+            'data'      => [$user['user_id'], $aArgs['entityId']]
         ]);
 
         return true;
@@ -739,12 +741,12 @@ class UserModelAbstract
         $entities = EntityModel::getByUserId(['userId' => $aArgs['userId']]);
         if (!empty($entities[0])) {
             DatabaseModel::update([
-                'table' => 'users_entities',
-                'set' => [
-                    'primary_entity' => 'Y',
+                'table'     => 'users_entities',
+                'set'       => [
+                    'primary_entity'    => 'Y'
                 ],
-                'where' => ['user_id = ?', 'entity_id = ?'],
-                'data' => [$aArgs['userId'], $entities[0]['entity_id']],
+                'where'     => ['user_id = ?', 'entity_id = ?'],
+                'data'      => [$aArgs['userId'], $entities[0]['entity_id']]
             ]);
         }
 
@@ -759,19 +761,19 @@ class UserModelAbstract
 
         $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]);
         DatabaseModel::delete([
-            'table' => 'users_entities',
-            'where' => ['entity_id = ?', 'user_id = ?'],
-            'data' => [$aArgs['entityId'], $user['user_id']],
+            'table'     => 'users_entities',
+            'where'     => ['entity_id = ?', 'user_id = ?'],
+            'data'      => [$aArgs['entityId'], $user['user_id']]
         ]);
 
-        $entityInfos = EntityModel::getByID(['entityId' => $aArgs['entityId']]);
+        $entityInfos=EntityModel::getByID(['entityId' => $aArgs['entityId']]);
 
         HistoryController::add([
             'tableName' => 'users',
-            'recordId' => $user['user_id'],
+            'recordId'  =>$user['user_id'],
             'eventType' => 'ENTITY DELETE',
-            'eventId' => 'entitydeleted',
-            'info' => $_SESSION['user']['UserId'].' '._REMOVED_USER.' '.$user['user_id'].' '._FROM_ENTITY.' '.$entityInfos['entity_label'],
+            'eventId'   => 'entitydeleted',
+            'info'       =>$_SESSION['user']['UserId'].' '._REMOVED_USER.' '.$user['user_id'].' '._FROM_ENTITY.' '.$entityInfos['entity_label']
         ]);
 
         return true;
@@ -784,32 +786,32 @@ class UserModelAbstract
         ValidatorModel::stringType($aArgs, ['groupId', 'basketId', 'color']);
 
         $isPresent = DatabaseModel::select([
-            'select' => ['1'],
-            'table' => ['users_baskets'],
-            'where' => ['user_serial_id = ?', 'group_id = ?', 'basket_id = ?'],
-            'data' => [$aArgs['id'], $aArgs['groupId'], $aArgs['basketId']],
+            'select'    => ['1'],
+            'table'     => ['users_baskets'],
+            'where'     => ['user_serial_id = ?', 'group_id = ?', 'basket_id = ?'],
+            'data'      => [$aArgs['id'], $aArgs['groupId'], $aArgs['basketId']]
         ]);
 
         if (empty($isPresent)) {
             DatabaseModel::insert(
                 [
-                    'table' => 'users_baskets',
+                    'table'         => 'users_baskets',
                     'columnsValues' => [
-                        'user_serial_id' => $aArgs['id'],
-                        'basket_id' => $aArgs['basketId'],
-                        'group_id' => $aArgs['groupId'],
-                        'color' => $aArgs['color'],
-                    ],
+                        'user_serial_id'    => $aArgs['id'],
+                        'basket_id'         => $aArgs['basketId'],
+                        'group_id'          => $aArgs['groupId'],
+                        'color'             => $aArgs['color']
+                    ]
                 ]
             );
         } else {
             DatabaseModel::update([
-                'table' => 'users_baskets',
-                'set' => [
-                    'color' => $aArgs['color'],
+                'table'     => 'users_baskets',
+                'set'       => [
+                    'color'    => $aArgs['color']
                 ],
-                'where' => ['user_serial_id = ?', 'group_id = ?', 'basket_id = ?'],
-                'data' => [$aArgs['id'], $aArgs['groupId'], $aArgs['basketId']],
+                'where'     => ['user_serial_id = ?', 'group_id = ?', 'basket_id = ?'],
+                'data'      => [$aArgs['id'], $aArgs['groupId'], $aArgs['basketId']]
             ]);
         }
 
@@ -826,7 +828,7 @@ class UserModelAbstract
             [
                 'table' => 'users_baskets',
                 'where' => ['user_serial_id = ?', 'group_id = ?', 'basket_id = ?'],
-                'data' => [$aArgs['id'], $aArgs['groupId'], $aArgs['basketId']],
+                'data'  => [$aArgs['id'], $aArgs['groupId'], $aArgs['basketId']]
             ]
         );
 
diff --git a/core/Test/ResControllerTest.php b/core/Test/ResControllerTest.php
index b68eb5ca293..aff876c6e24 100755
--- a/core/Test/ResControllerTest.php
+++ b/core/Test/ResControllerTest.php
@@ -11,5 +11,136 @@ use PHPUnit\Framework\TestCase;
 
 class ResControllerTest extends TestCase
 {
+    private static $id = null;
+
+    public function testCreate()
+    {
+        $resController = new \Resource\controllers\ResController();
+
+        //  CREATE
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $fileContent = file_get_contents('modules/convert/Test/Samples/test.txt');
+        $encodedFile = base64_encode($fileContent);
+
+        $data = [
+            [
+                'column'    => 'subject',
+                'value'     => 'Breaking News : Superman is alive',
+                'type'      => 'string',
+            ],
+            [
+                'column'    => 'type_id',
+                'value'     => 102,
+                'type'      => 'integer',
+            ],
+            [
+                'column'    => 'typist',
+                'value'     => 'LLane',
+                'type'      => 'string',
+            ]
+        ];
+
+        $aArgs = [
+            'collId'        => 'letterbox_coll',
+            'table'         => 'res_letterbox',
+            'status'        => 'NEW',
+            'encodedFile'   => $encodedFile,
+            'fileFormat'    => 'txt',
+            'data'          => $data
+        ];
+
+        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $response     = $resController->create($fullRequest, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+
+        self::$id = $responseBody->resId;
+
+        $this->assertInternalType('int', self::$id);
+
+        //  READ
+        $res = \Resource\models\ResModel::getById(['resId' => self::$id]);
+
+        $this->assertInternalType('array', $res);
+
+        $this->assertSame('Breaking News : Superman is alive', $res['subject']);
+        $this->assertSame(null, $res['title']);
+        $this->assertSame(null, $res['description']);
+        $this->assertSame(102, $res['type_id']);
+        $this->assertSame('txt', $res['format']);
+        $this->assertSame('NEW', $res['status']);
+        $this->assertSame('LLane', $res['typist']);
+        $this->assertSame(null, $res['destination']);
+    }
+
+    public function testUpdateStatus()
+    {
+        $resController = new \Resource\controllers\ResController();
+
+        //  UPDATE STATUS
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $aArgs = [
+            'resId'         => self::$id,
+            'status'        => 'EVIS'
+        ];
+
+        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $response     = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('success', $responseBody->success);
+
+        //  READ
+        $res = \Resource\models\ResModel::getById(['resId' => self::$id]);
+        $this->assertInternalType('array', $res);
+        $this->assertSame('EVIS', $res['status']);
+
+        //  UPDATE WITHOUT STATUS
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $aArgs = [
+            'resId'         => self::$id
+        ];
+
+        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $response     = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('success', $responseBody->success);
+
+        //  READ
+        $res = \Resource\models\ResModel::getById(['resId' => self::$id]);
+        $this->assertInternalType('array', $res);
+        $this->assertSame('COU', $res['status']);
+    }
+
+    public function testDelete()
+    {
+        //  DELETE
+        \Resource\models\ResModel::delete(['resId' => self::$id]);
+
+        //  READ
+        $res = \Resource\models\ResModel::getById(['resId' => self::$id]);
+        $this->assertInternalType('array', $res);
+        $this->assertSame('DEL', $res['status']);
+
+        //  REAL DELETE
+        \Core\Models\DatabaseModel::delete([
+            'table' => 'res_letterbox',
+            'where' => ['res_id = ?'],
+            'data'  => [self::$id]
+        ]);
+
+        //  READ
+        $res = \Resource\models\ResModel::getById(['resId' => self::$id]);
+        $this->assertSame(null, $res);
+    }
 
 }
diff --git a/core/Test/ResExtControllerTest.php b/core/Test/ResExtControllerTest.php
deleted file mode 100755
index 36b3c4b8d4a..00000000000
--- a/core/Test/ResExtControllerTest.php
+++ /dev/null
@@ -1,420 +0,0 @@
-<?php
-
-namespace MaarchTest;
-
-/**
-* Copyright Maarch since 2008 under licence GPLv3.
-* See LICENCE.txt file at the root folder for more details.
-* This file is part of Maarch software.
-*
-*/
-
-use PHPUnit\Framework\TestCase;
-
-class ResExtControllerTest extends TestCase
-{
-    public function testCreate()
-    {
-        $resId = $this->createResArtefact();
-
-        $action = new \Core\Controllers\ResExtController();
-
-        $environment = \Slim\Http\Environment::mock(
-            [
-                'REQUEST_METHOD' => 'POST',
-            ]
-        );
-        
-        $data = [];
-
-        array_push(
-            $data,
-            array(
-                'column' => 'process_limit_date',
-                'value' => '29/03/2017',
-                'type' => 'date',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'process_notes',
-                'value' => '50,workingDay',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'category_id',
-                'value' => 'incoming',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'alt_identifier',
-                'value' => '',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'exp_contact_id',
-                'value' => 'jeanlouis.ercolani@maarch.org',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'address_id',
-                'value' => 'jeanlouis.ercolani@maarch.org',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'nature_id',
-                'value' => 'simple_mail',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'admission_date',
-                'value' => date('d/m/Y'),
-                'type' => 'date',
-            )
-        );
-
-        $aArgs = [
-            'resId'    => $resId,
-            'data'     => $data,
-            'table'    => 'mlb_coll_ext',
-            'resTable' => 'res_letterbox',
-        ];
-
-        $request = \Slim\Http\Request::createFromEnvironment($environment);
-        $response = new \Slim\Http\Response();
-        $response = $action->create($request, $response, $aArgs);
-        
-        $this->assertTrue(json_decode($response->getBody())->status);
-
-        $this->deleteResArtefact($resId);
-    }
-
-    public function testDelete()
-    {
-        $action = new \Core\Controllers\ResExtController();
-
-        $environment = \Slim\Http\Environment::mock(
-            [
-                'REQUEST_METHOD' => 'DELETE',
-            ]
-        );
-
-        $resId = \Core\Models\ResExtModel::getLastId(['select' => ['res_id']]);
-
-        $aArgs = [
-            'id'=> $resId[0]['res_id']
-        ];
-
-        $request = \Slim\Http\Request::createFromEnvironment($environment);
-        $response = new \Slim\Http\Response();
-        $response = $action->delete($request, $response, $aArgs);
-        
-        $this->assertSame((string)$response->getBody(), '[true]');
-    }
-
-    public function testPrepareStorageExt()
-    {
-        $action = new \Core\Controllers\ResExtController();
-
-        $data = [];
-
-        array_push(
-            $data,
-            array(
-                'column' => 'process_limit_date',
-                'value' => '29/03/2017',
-                'type' => 'date',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'process_notes',
-                'value' => '50,workingDay',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'category_id',
-                'value' => 'incoming',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'alt_identifier',
-                'value' => '',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'exp_contact_id',
-                'value' => 'jeanlouis.ercolani@maarch.org',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'address_id',
-                'value' => 'jeanlouis.ercolani@maarch.org',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'nature_id',
-                'value' => 'simple_mail',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'admission_date',
-                'value' => date('d/m/Y'),
-                'type' => 'date',
-            )
-        );
-
-        $aArgs = [
-            'resId' => 100,
-            'data'  => $data,
-            'table' => 'mlb_coll_ext',
-        ];
-
-        $response = $action->prepareStorageExt($aArgs);
-
-        $this->assertArrayHasKey('res_id', $response);
-    }
-
-    public function testStoreExtResource()
-    {
-        $resId = $this->createResArtefact();
-
-        $action = new \Core\Controllers\ResExtController();
-        
-        $data = [];
-
-        array_push(
-            $data,
-            array(
-                'column' => 'process_limit_date',
-                'value' => '29/03/2017',
-                'type' => 'date',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'process_notes',
-                'value' => '50,workingDay',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'category_id',
-                'value' => 'incoming',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'alt_identifier',
-                'value' => '',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'exp_contact_id',
-                'value' => 'jeanlouis.ercolani@maarch.org',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'address_id',
-                'value' => 'jeanlouis.ercolani@maarch.org',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'nature_id',
-                'value' => 'simple_mail',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'admission_date',
-                'value' => date('d/m/Y'),
-                'type' => 'date',
-            )
-        );
-
-        $aArgs = [
-            'resId'    => $resId,
-            'data'     => $data,
-            'table'    => 'mlb_coll_ext',
-            'resTable' => 'res_letterbox',
-        ];
-
-        $response = $action->storeExtResource($aArgs);
-        
-        $this->assertTrue($response);
-
-        $this->deleteResArtefact($resId);
-    }
-
-    public function testDeleteExtRes()
-    {
-        $action = new \Core\Controllers\ResExtController();
-
-        $resId = \Core\Models\ResExtModel::getLastId(['select' => ['res_id']]);
-
-        $aArgs = [
-            'id'=> $resId[0]['res_id']
-        ];
-
-        $response = $action->deleteExtRes($aArgs);
-
-        $this->assertTrue($response);
-    }
-
-    public function createResArtefact()
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $path = $_SESSION['config']['tmppath'] . '/test/';
-
-        if (!is_dir($path)) {
-            mkdir($path);
-        }
-
-        $fileSource = 'test_source.txt';
-
-        $fp = fopen($path . $fileSource, 'a');
-        fwrite($fp, 'a unit test');
-        fclose($fp);
-
-        $fileContent = file_get_contents($path . $fileSource, FILE_BINARY);
-        $encodedFile = base64_encode($fileContent);
-        
-        $data = [];
-
-        array_push(
-            $data,
-            array(
-                'column' => 'subject',
-                'value' => 'UNIT TEST',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'type_id',
-                'value' => 110,
-                'type' => 'integer',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'custom_t1',
-                'value' => 'TEST',
-                'type' => 'string',
-            )
-        );
-
-        array_push(
-            $data,
-            array(
-                'column' => 'custom_t10',
-                'value' => 'lgi@maarch.org',
-                'type' => 'string',
-            )
-        );
-
-        $aArgs = [
-            'encodedFile'   => $encodedFile,
-            'data'          => $data,
-            'collId'        => 'letterbox_coll',
-            'table'         => 'res_letterbox',
-            'fileFormat'    => 'txt',
-            'status'        => 'new',
-        ];
-
-        $response = $action->storeResource($aArgs);
-
-        return $response[0];
-    }
-
-    public function deleteResArtefact($resId)
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $aArgs = [
-            'id' => $resId
-        ];
-
-        $response = $action->deleteRes($aArgs);
-    }
-}
diff --git a/package-lock.json b/package-lock.json
index e3f1da41c5a..d56f962b81a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,9 +13,9 @@
       }
     },
     "@angular/cdk": {
-      "version": "5.0.4",
-      "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-5.0.4.tgz",
-      "integrity": "sha512-6IKDOhDrfKdywTZNTWZbM1O8Q3cTi7uIOAyFC9sXitg0JUy2SHms0UY9FdW32BABIsZp692ofMCMdMPjHDjwwA==",
+      "version": "5.1.0",
+      "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-5.1.0.tgz",
+      "integrity": "sha512-xDCVx65SvxoGDMpQhaQvfP7bZhQDuX65Uk+JntPlLTiwFr7v82a+71RnzOCzNKyaNXGoIgUGcrLZpozlyqNgFg==",
       "dev": true,
       "requires": {
         "tslib": "1.8.1"
@@ -93,9 +93,9 @@
       }
     },
     "@angular/material": {
-      "version": "5.0.4",
-      "resolved": "https://registry.npmjs.org/@angular/material/-/material-5.0.4.tgz",
-      "integrity": "sha512-xrGYPHOlNXpPkventLAvZyTjfCo2A8ZfdyJEHNR4LhFWIjw3ilwb1ihNv4dy/qG56g8L4AwQ2cONxQ0YyZfcWg==",
+      "version": "5.1.0",
+      "resolved": "https://registry.npmjs.org/@angular/material/-/material-5.1.0.tgz",
+      "integrity": "sha512-F+dM2xGbyWK3f+j5ZiWMOCBK1Jnv4RAlFRwezJVnzcWaAjwhO2YBHUQGZcnwsVJpwf5Vrihix8N+sWiPvVw+jw==",
       "dev": true,
       "requires": {
         "tslib": "1.8.1"
@@ -168,7 +168,7 @@
     "@types/jquery": {
       "version": "2.0.48",
       "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-2.0.48.tgz",
-      "integrity": "sha512-nNLzUrVjaRV/Ds1eHZLYTd7IZxs38cwwLSaqMJj8OTXY8xNUbxSK69bi9cMLvQ7dm/IBeQ1wHwQ0S1uYa0rd2w==",
+      "integrity": "sha1-PpDYzeLSkBXlWDAX94MMs5dbLu8=",
       "dev": true
     },
     "@types/node": {
@@ -2144,11 +2144,6 @@
       "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
       "integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
     },
-    "md2": {
-      "version": "0.0.29",
-      "resolved": "https://registry.npmjs.org/md2/-/md2-0.0.29.tgz",
-      "integrity": "sha512-wYy/gs92vkewX9dclSe5Q/r8hqO7qLYmduAfCNbgFYhGykrjLRuc55J/OliPeBRYpQHMs4H3RyHat8VAHPVNaQ=="
-    },
     "md5.js": {
       "version": "1.3.4",
       "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz",
diff --git a/phpunit.xml b/phpunit.xml
index 47f276214ac..da77dcd82fb 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -4,9 +4,8 @@
         <testsuite name="Maarch Core Test Suite">
             <!--directory>core/Test</directory-->
             <!--file>core/Test/ActionControllerTest.php</file-->
+            <file>core/Test/ResControllerTest.php</file>
             <file>core/Test/PriorityControllerTest.php</file>
-            <!--file>core/Test/ResControllerTest.php</file>
-            <file>core/Test/ResExtControllerTest.php</file-->
             <file>core/Test/StatusControllerTest.php</file>
             <file>core/Test/UserControllerTest.php</file>
             <file>core/Test/BasketControllerTest.php</file>
diff --git a/src/app/resource/models/ResModelAbstract.php b/src/app/resource/models/ResModelAbstract.php
index 7ef4a660802..476e4759fa0 100644
--- a/src/app/resource/models/ResModelAbstract.php
+++ b/src/app/resource/models/ResModelAbstract.php
@@ -47,10 +47,6 @@ class ResModelAbstract
             'data'      => [$aArgs['resId']]
         ]);
 
-        if (empty($aResources[0])) {
-            return [];
-        }
-
         return $aResources[0];
     }
 
@@ -120,6 +116,23 @@ class ResModelAbstract
         return true;
     }
 
+    public static function delete(array $aArgs)
+    {
+        ValidatorModel::notEmpty($aArgs, ['resId']);
+        ValidatorModel::intVal($aArgs, ['resId']);
+
+        DatabaseModel::update([
+            'table' => 'res_letterbox',
+            'set'   => [
+                'status'    => 'DEL'
+            ],
+            'where' => ['res_id = ?'],
+            'data'  => [$aArgs['resId']]
+        ]);
+
+        return true;
+    }
+
     public static function isLock(array $aArgs)
     {
         ValidatorModel::notEmpty($aArgs, ['resId', 'userId']);
-- 
GitLab