From b48e12ba6666994e32a58602ddeac994ca4bf9a5 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Wed, 7 Feb 2018 16:05:27 +0100
Subject: [PATCH] FEAT #63 TU notification

---
 core/Test/NotificationsControllerTest.php     | 362 ++++++++++--------
 phpunit.xml                                   |  15 +-
 .../controllers/NotificationController.php    | 128 ++++++-
 3 files changed, 325 insertions(+), 180 deletions(-)

diff --git a/core/Test/NotificationsControllerTest.php b/core/Test/NotificationsControllerTest.php
index e6240921314..bc5c5fbd6cd 100644
--- a/core/Test/NotificationsControllerTest.php
+++ b/core/Test/NotificationsControllerTest.php
@@ -1,237 +1,297 @@
 <?php
-
 /**
 * 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.
-*
-*/
-
-namespace MaarchTest;
 
-//use Core\Models\DatabaseModel;
+* @brief   NotificationsControllerTest
+* @author  dev <dev@maarch.org>
+* @ingroup core
+*/
 
 use PHPUnit\Framework\TestCase;
 
 class NotificationControllerTest extends TestCase
 {
     private static $id = null;
-    public function testReadAll()
-    {
-        //  TEST GET // READ // NEED TO HAVE RED IN BDD 
-        $NotificationController = new \Notification\controllers\NotificationController();
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
-        $response     = $NotificationController->get($request, new \Slim\Http\Response());
-        $responseBody = json_decode((string)$response->getBody());
-        $this->assertSame('RED', $responseBody->notifications[6]->notification_id);
-    }
-
 
     public function testCreate()
     {
-        //  CREATE
         $NotificationController = new \Notification\controllers\NotificationController();
+
+        //  CREATE
         $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
         $request        = \Slim\Http\Request::createFromEnvironment($environment);
 
         $aArgs = [
-            'notification_id'    => 'warning5',
-            'description' => 'Alerte aux gogoles',
-            'is_enabled'  => 'Y',
-            'event_id'  => 'users%',
-            'notification_mode'  => 'EMAIL',
-            'template_id'  => '4',
-            'rss_url_template'  => 'http://localhost/maarch_entreprise',
-            'diffusion_type'  => 'group',
-            'diffusion_properties'  => ['ADMINISTRATEUR','ARCHIVISTE','DIRECTEUR'],
-            'attachfor_type'  => 'entity',
-            'attachfor_properties'  => ['COU','PJS'] 
-
+            'notification_id'      => 'testcreatetu',
+            'description'          => 'description de la notification',
+            'is_enabled'           => 'Y',
+            'event_id'             => 'users%',
+            'notification_mode'    => 'EMAIL',
+            'template_id'          =>  4,
+            'diffusion_type'       => 'group',
+            'diffusion_properties' => ['ADMINISTRATEUR','ARCHIVISTE','DIRECTEUR'],
+            'attachfor_type'       => 'entity',
+            'attachfor_properties' => ['COU','PJS']
         ];
-        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $fullRequest  = \httpRequestCustom::addContentInBody($aArgs, $request);
         $response     = $NotificationController->create($fullRequest, new \Slim\Http\Response());
         $responseBody = json_decode((string)$response->getBody());
+
         $this->assertInternalType("int", $responseBody->notification_sid);
-        $notification_sid = $responseBody->notification_sid;
-        self::$id = $notification_sid;
-        unset($responseBody->notification_sid);
-        $aCompare = json_decode(json_encode($compare), false);
+        self::$id = $responseBody->notification_sid;
 
-        $this->assertSame('warning5', $responseBody->notification_id);
-        $this->assertSame('Alerte aux gogoles', $responseBody->description);
+        $this->assertSame('testcreatetu', $responseBody->notification_id);
+        $this->assertSame('description de la notification', $responseBody->description);
         $this->assertSame('Y', $responseBody->is_enabled);
         $this->assertSame('users%', $responseBody->event_id);
         $this->assertSame('EMAIL', $responseBody->notification_mode);
         $this->assertSame(4, $responseBody->template_id);
-        $this->assertSame('http://localhost/maarch_entreprise', $responseBody->rss_url_template);
         $this->assertSame('group', $responseBody->diffusion_type);
         $this->assertSame('ADMINISTRATEUR,ARCHIVISTE,DIRECTEUR', $responseBody->diffusion_properties);
         $this->assertSame('entity', $responseBody->attachfor_type);
         $this->assertSame('COU,PJS', $responseBody->attachfor_properties);
-
     }
 
     public function testCreateFail1()
     {
         //Fail Create 1
         $NotificationController = new \Notification\controllers\NotificationController();
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
 
         $aArgs = [
-            'notification_id'    => '',
-            'description' => 'Alerte aux gogoles',
-            'is_enabled'  => 'Y',
-            'event_id'  => 'users%',
-            'notification_mode'  => 'EMAIL',
-            'template_id'  => '4',
-            'rss_url_template'  => 'http://localhost/maarch_entreprise',
-            'diffusion_type'  => 'user',
-            'diffusion_properties'  => 'superadmin',
-            'attachfor_type'  => 'zz',
-            'attachfor_properties'  => 'cc' 
-
+            'notification_id'      => '',
+            'description'          => 'description de la notification',
+            'is_enabled'           => 'Y',
+            'event_id'             => '',
+            'notification_mode'    => 'EMAIL',
+            'template_id'          => '',
+            'rss_url_template'     => 'http://localhost/maarch_entreprise',
+            'diffusion_type'       => 'user',
+            'diffusion_properties' => 'superadmin',
+            'attachfor_type'       => 'zz',
+            'attachfor_properties' => 'cc'
         ];
-        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $fullRequest  = \httpRequestCustom::addContentInBody($aArgs, $request);
         $response     = $NotificationController->create($fullRequest, new \Slim\Http\Response());
         $responseBody = json_decode((string)$response->getBody());
-        $this->assertSame('Notification error : notification_id is empty', $responseBody->errors);
+
+        $this->assertSame('notification_id is empty', $responseBody->errors[0]);
+        $this->assertSame('wrong format for template_id', $responseBody->errors[1]);
     }
 
     public function testCreateFail2()
     {
         //Fail Create 2
         $NotificationController = new \Notification\controllers\NotificationController();
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
 
         $aArgs = [
-            'notification_id'    => 'warning5',
-            'description' => 'Alerte aux gogoles',
-            'is_enabled'  => 'Y',
-            'event_id'  => 'users%',
-            'notification_mode'  => 'EMAIL',
-            'template_id'  => '4',
-            'rss_url_template'  => 'http://localhost/maarch_entreprise',
-            'diffusion_type'  => 'user',
-            'diffusion_properties'  => 'superadmin',
-            'attachfor_type'  => 'zz',
-            'attachfor_properties'  => 'cc' 
-
+            'notification_id'      => 'testcreatetu',
+            'description'          => 'description de la notification',
+            'is_enabled'           => 'Y',
+            'event_id'             => 'users%',
+            'notification_mode'    => 'EMAIL',
+            'template_id'          => 4,
+            'rss_url_template'     => 'http://localhost/maarch_entreprise',
+            'diffusion_type'       => 'user',
+            'diffusion_properties' => 'superadmin',
+            'attachfor_type'       => 'zz',
+            'attachfor_properties' => 'cc'
         ];
-        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $fullRequest  = \httpRequestCustom::addContentInBody($aArgs, $request);
         $response     = $NotificationController->create($fullRequest, new \Slim\Http\Response());
         $responseBody = json_decode((string)$response->getBody());
         $this->assertSame('Erreur sur la Notification:  identifiant déjà existant', $responseBody->errors);
     }
 
+    public function testRead()
+    {
+        //READ
+        $NotificationController = new \Notification\controllers\NotificationController();
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
+        $response               = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => self::$id]);
+        $responseBody           = json_decode((string)$response->getBody());
+
+        $this->assertSame(self::$id, $responseBody->notification->notification_sid);
+        $this->assertSame('testcreatetu', $responseBody->notification->notification_id);
+        $this->assertSame('description de la notification', $responseBody->notification->description);
+        $this->assertSame('Y', $responseBody->notification->is_enabled);
+        $this->assertSame('users%', $responseBody->notification->event_id);
+        $this->assertSame('EMAIL', $responseBody->notification->notification_mode);
+        $this->assertSame(4, $responseBody->notification->template_id);
+        $this->assertSame('group', $responseBody->notification->diffusion_type);
+    }
+
+    public function testReadFail()
+    {
+        $NotificationController = new \Notification\controllers\NotificationController();
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
+        $response               = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => 'test']);
+        $responseBody           = json_decode((string)$response->getBody());
+        $this->assertSame('Id is not a numeric', $responseBody->errors);
+    }
+
+    public function testReadFail2()
+    {
+        //I CANT READ BECAUSE NO EXIST
+        $NotificationController = new \Notification\controllers\NotificationController();
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
+        $response               = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => '9999999999']);
+        $responseBody           = json_decode((string)$response->getBody());
+        $this->assertSame('Notification not found', $responseBody->errors);
+    }
+
+    public function testReadAll()
+    {
+        $NotificationController = new \Notification\controllers\NotificationController();
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
+        $response               = $NotificationController->get($request, new \Slim\Http\Response());
+        $responseBody           = json_decode((string)$response->getBody());
+
+        $this->assertNotNull($responseBody->notifications);
+    }
 
     public function testUpdate()
     {
         //  UPDATE
         $NotificationController = new \Notification\controllers\NotificationController();
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
         $aArgs = [
-            'notification_id'    => 'warning5',
-            'description' => 'BOUBOUP',
-            'is_enabled'  => 'Y',
-            'event_id'  => 'users%',
-            'notification_mode'  => 'EMAIL',
-            'template_id'  => '4',
-            'rss_url_template'  => 'http://localhost/maarch_entreprise',
-            'diffusion_type'  => 'group',
-            'diffusion_properties'  => ['ADMINISTRATEUR','ARCHIVISTE','DIRECTEUR'],
-            'attachfor_type'  => 'entity',
-            'attachfor_properties'  => ['COU','PJS'] 
+            'notification_id'      => 'testcreatetu',
+            'description'          => 'nouvelle description',
+            'is_enabled'           => 'N',
+            'event_id'             => 'users%',
+            'notification_mode'    => 'EMAIL',
+            'template_id'          => 3,
+            'diffusion_type'       => 'group',
+            'diffusion_properties' => ['ADMINISTRATEUR','ARCHIVISTE','DIRECTEUR'],
+            'attachfor_type'       => 'entity',
+            'attachfor_properties' => ['COU','PJS']
         ];
-        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $fullRequest  = \httpRequestCustom::addContentInBody($aArgs, $request);
         $response     = $NotificationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
         $responseBody = json_decode((string)$response->getBody());
-        //$this->assertSame(_NOTIFICATION_UPDATED, $responseBody->success);
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
-        $response     = $NotificationController->getById($request, new \Slim\Http\Response(), ['id' => 'warning5']);
-        $responseBody = json_decode((string)$response->getBody());
-        var_dump(self::$id);
-        var_dump($responseBody->notifications);
-        $this->assertSame(self::$id, $responseBody->notifications->notification_sid);
-        $this->assertSame('warning5', $responseBody->notifications->notification_id);
-        $this->assertSame('BOUBOUP', $responseBody->notifications->description);
-        $this->assertSame('Y', $responseBody->notifications->is_enabled);
-        $this->assertSame('users%', $responseBody->notifications->event_id);
-        $this->assertSame('EMAIL', $responseBody->notifications->notification_mode);
-        $this->assertSame(4, $responseBody->notifications->template_id);
-        $this->assertSame('group', $responseBody->notifications->diffusion_type);
-        //$this->assertSame('ADMINISTRATEUR,ARCHIVISTE,DIRECTEUR', $responseBody->diffusion_properties);
-        //$this->assertSame('entity', $responseBody->attachfor_type);
-        //$this->assertSame('COU,PJS', $responseBody->attachfor_properties);
 
+        $this->assertSame(self::$id, $responseBody->notification->notification_sid);
+        $this->assertSame('testcreatetu', $responseBody->notification->notification_id);
+        $this->assertSame('nouvelle description', $responseBody->notification->description);
+        $this->assertSame('N', $responseBody->notification->is_enabled);
+        $this->assertSame('users%', $responseBody->notification->event_id);
+        $this->assertSame('EMAIL', $responseBody->notification->notification_mode);
+        $this->assertSame(3, $responseBody->notification->template_id);
+        $this->assertSame('group', $responseBody->notification->diffusion_type);
+        $this->assertSame('ADMINISTRATEUR,ARCHIVISTE,DIRECTEUR', $responseBody->notification->diffusion_properties);
+        $this->assertSame('entity', $responseBody->notification->attachfor_type);
+        $this->assertSame('COU,PJS', $responseBody->notification->attachfor_properties);
     }
 
-
-    public function testRead(){
-        //READ
+    public function testUpdateFail()
+    {
+        //  UPDATE
         $NotificationController = new \Notification\controllers\NotificationController();
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
-        $response     = $NotificationController->getById($request, new \Slim\Http\Response(), ['id' => 'warning5']);
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
+        $aArgs = [
+            'notification_id'      => 'testcreatetu',
+            'description'          => '',
+            'is_enabled'           => 'N',
+            'event_id'             => 'users%',
+            'notification_mode'    => 'EMAIL',
+            'template_id'          => '',
+            'diffusion_type'       => 'group',
+            'diffusion_properties' => ['ADMINISTRATEUR','ARCHIVISTE','DIRECTEUR'],
+            'attachfor_type'       => 'entity',
+            'attachfor_properties' => ['COU','PJS']
+        ];
+        $fullRequest  = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $response     = $NotificationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
         $responseBody = json_decode((string)$response->getBody());
 
-        $this->assertSame(self::$id, $responseBody->notifications->notification_sid);
-        $this->assertSame('warning5', $responseBody->notifications->notification_id);
-        $this->assertSame('BOUBOUP', $responseBody->notifications->description);
-        $this->assertSame('Y', $responseBody->notifications->is_enabled);
-        $this->assertSame('users%', $responseBody->notifications->event_id);
-        $this->assertSame('EMAIL', $responseBody->notifications->notification_mode);
-        $this->assertSame(4, $responseBody->notifications->template_id);
-        $this->assertSame('group', $responseBody->notifications->diffusion_type);
+        $this->assertSame('wrong format for description', $responseBody->errors[0]);
+        $this->assertSame('wrong format for template_id', $responseBody->errors[1]);
     }
 
-    // public function testReadFail(){
-    //     //I CANT READ BECAUSE NO ID
-    //     $NotificationController = new \Notification\controllers\NotificationController();
-    //     $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
-    //     $request        = \Slim\Http\Request::createFromEnvironment($environment);
-    //     $response     = $NotificationController->getById($request, new \Slim\Http\Response(), ['id' => '']);
-    //     $responseBody = json_decode((string)$response->getBody());
-    //     $this->assertSame('notification_id is empty', $responseBody->errors);
-    // }
-
-    public function testReadFail2(){
-        //I CANT READ BECAUSE NO EXIST
+    public function testUpdateFail2()
+    {
+        //  UPDATE
         $NotificationController = new \Notification\controllers\NotificationController();
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
-        $response     = $NotificationController->getById($request, new \Slim\Http\Response(), ['id' => 'BamBam']);
+        $environment            = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request                = \Slim\Http\Request::createFromEnvironment($environment);
+        $aArgs = [
+            'notification_id'      => 'testcreatetu',
+            'description'          => 'description',
+            'is_enabled'           => 'N',
+            'event_id'             => 'users%',
+            'notification_mode'    => 'EMAIL',
+            'template_id'          => 4,
+            'diffusion_type'       => 'group',
+            'diffusion_properties' => ['ADMINISTRATEUR','ARCHIVISTE','DIRECTEUR'],
+            'attachfor_type'       => 'entity',
+            'attachfor_properties' => ['COU','PJS']
+        ];
+        $fullRequest  = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $response     = $NotificationController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'fail']);
         $responseBody = json_decode((string)$response->getBody());
-        $this->assertSame('Notification not found', $responseBody->errors);
-    }
 
-    // public function testDeleteFail()
-    // {
-    //     $NotificationController = new \Notification\controllers\NotificationController();
-
-    //     //  DELETE
-    //     $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
-    //     $request        = \Slim\Http\Request::createFromEnvironment($environment);
-    //     $response       = $NotificationController->deleteNotification($request, new \Slim\Http\Response(), ['id' => '2245']);
-    //     $responseBody   = json_decode((string)$response->getBody());
-    //     var_dump($responseBody);
-    //     //$this->assertSame(_DELETED_NOTIFICATION, $responseBody->success);
-    // }
+        $this->assertSame('notification_sid is not a numeric', $responseBody->errors[0]);
+        $this->assertSame('notification does not exists', $responseBody->errors[1]);
+    }
 
     public function testDelete()
     {
         $NotificationController = new \Notification\controllers\NotificationController();
 
         //  DELETE
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
-        $response       = $NotificationController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
-        $responseBody   = json_decode((string)$response->getBody());
-        $this->assertSame(_DELETED_NOTIFICATION, $responseBody->success);
+        $environment  = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
+        $request      = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response         = $NotificationController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
+        $responseBody     = json_decode((string)$response->getBody());
+
+        $this->assertNotNull($responseBody->notifications[0]);
+
+        $environment  = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request      = \Slim\Http\Request::createFromEnvironment($environment);
+        $response     = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => self::$id]);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNull($responseBody->notifications[0]);
+
+        // FAIL DELETE
+        $response         = $NotificationController->delete($request, new \Slim\Http\Response(), ['id' => 'gaz']);
+        $responseBody     = json_decode((string)$response->getBody());
+
+        $this->assertSame('Id is not a numeric', $responseBody->errors);
+    }
+
+    public function testGetInitNotification()
+    {
+        // InitAction
+        $environment  = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request      = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $NotificationController = new \Notification\controllers\NotificationController();
+        $response         = $NotificationController->initNotification($request, new \Slim\Http\Response());
+        $responseBody     = json_decode((string)$response->getBody());
+
+        $this->assertNotNull($responseBody->notification->data->event);
+        $this->assertNotNull($responseBody->notification->data->template);
+        $this->assertNotNull($responseBody->notification->data->diffusionType);
+        $this->assertNotNull($responseBody->notification->data->groups);
+        $this->assertNotNull($responseBody->notification->data->users);
+        $this->assertNotNull($responseBody->notification->data->entities);
+        $this->assertNotNull($responseBody->notification->data->status);
+
     }
-        
 }
diff --git a/phpunit.xml b/phpunit.xml
index dac176c5432..cbf6a106336 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -4,17 +4,18 @@
         <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/UserControllerTest.php</file>
             <file>core/Test/BasketControllerTest.php</file>
+            <file>core/Test/NotificationTestControllerTest.php</file>
+            <file>core/Test/ParameterControllerTest.php</file>
             <file>core/Test/PriorityControllerTest.php</file>
-            <file>core/Test/StatusControllerTest.php</file>
             <file>core/Test/ReportControllerTest.php</file>
-            <file>core/Test/ParameterControllerTest.php</file>
+            <file>core/Test/ResControllerTest.php</file>
+            <file>core/Test/StatusControllerTest.php</file>
+            <file>core/Test/UserControllerTest.php</file>
             <file>modules/convert/Test/ProcessConvertTest.php</file>
             <file>modules/convert/Test/ProcessFulltextTest.php</file>
-            <file>modules/convert/Test/ProcessThumbnailsTest.php</file>
             <file>modules/convert/Test/ProcessManageConvertTest.php</file>
+            <file>modules/convert/Test/ProcessThumbnailsTest.php</file>
         </testsuite>
     </testsuites>
     <filter>
@@ -23,9 +24,7 @@
           <directory suffix=".php">src</directory>
           <directory suffix=".php">core/Controllers</directory>
           <directory suffix=".php">core/Models</directory>
-          <directory suffix=".php">apps/maarch_entreprise/Models</directory>
-          <directory suffix=".php">modules/notifications/Controllers</directory>
-          <directory suffix=".php">modules/notifications/Models</directory>          
+          <directory suffix=".php">apps/maarch_entreprise/Models</directory>         
           <directory suffix=".php">modules/visa/Controllers</directory>
           <directory suffix=".php">modules/visa/Models</directory>          
           <directory suffix=".php">modules/attachments/Controllers</directory>
diff --git a/src/app/notification/controllers/NotificationController.php b/src/app/notification/controllers/NotificationController.php
index 7cf72230ff0..b35c6fe2baa 100644
--- a/src/app/notification/controllers/NotificationController.php
+++ b/src/app/notification/controllers/NotificationController.php
@@ -39,7 +39,16 @@ class NotificationController
             return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
         }
 
-        $notification = NotificationModel::getById(['notification_sid' => $aArgs['id'], 'select' => ['notification_sid', 'notification_id', 'description', 'is_enabled', 'event_id', 'notification_mode', 'template_id', 'diffusion_type','diffusion_properties', 'attachfor_type','attachfor_properties']]);
+        if (!Validator::intVal()->validate($aArgs['id'])) {
+            return $response
+                ->withStatus(500)
+                ->withJson(['errors' => 'Id is not a numeric']);
+        }
+
+        $notification = NotificationModel::getById(['notification_sid' => $aArgs['id']]);
+        if (empty($notification)) {
+            return $response->withStatus(400)->withJson(['errors' => 'Notification not found']);
+        }
 
         $notification['diffusion_properties'] = explode(",", $notification['diffusion_properties']);
         
@@ -55,9 +64,6 @@ class NotificationController
             unset($notification['attachfor_properties'][$key]);
         }
         
-        if (empty($notification)) {
-            return $response->withStatus(400)->withJson(['errors' => 'Notification not found']);
-        }
         $data = [];
 
         $data['event']         = NotificationModel::getEvent();
@@ -80,25 +86,16 @@ class NotificationController
         }
 
         $data = $request->getParams();
-        if (empty($data['notification_id'])) {
-            return $response->withStatus(400)->withJson(['errors' => 'Notification error : notification_id is empty']);
+
+        $errors = $this->control($data, 'create');
+        if (!empty($errors)) {
+            return $response->withStatus(500)->withJson(['errors' => $errors]);
         }
+
         $notificationInDb = NotificationModel::getByNotificationId(['notificationId' => $data['notification_id'], 'select' => ['notification_sid']]);
         
         if (Validator::notEmpty()->validate($notificationInDb)) {
             return $response->withStatus(400)->withJson(['errors' => _NOTIFICATIONS_ERROR.' '._NOTIF_ALREADY_EXIST]);
-
-        } elseif (!Validator::length(0, 254)->validate($data['description'])) {
-            return $response->withStatus(400)->withJson(['errors' => 'Description is too long']);
-
-        } elseif (!Validator::length(0, 254)->validate($data['event_id'])) {
-            return $response->withStatus(400)->withJson(['errors' => 'event_id is too long']);
-
-        } elseif (!Validator::length(0, 30)->validate($data['notification_mode'])) {
-            return $response->withStatus(400)->withJson(['errors' => 'notification_mode is too long']);
-
-        } elseif (Validator::intType()->notEmpty()->validate($data['template_id'])) {
-            return $response->withStatus(400)->withJson(['errors' => 'wrong format for template_id']);
         }
 
         if ($data['is_enabled'] == true) {
@@ -141,15 +138,26 @@ class NotificationController
         }
 
         $data = $request->getParams();
-
         $data['notification_sid']     = $aArgs['id'];
+
+        $errors = $this->control($data, 'update');
+      
+        if (!empty($errors)) {
+            return $response
+                ->withStatus(500)->withJson(['errors' => $errors]);
+        }
+
         $data['diffusion_properties'] = implode(",", $data['diffusion_properties']);
-        
         $data['attachfor_properties'] = implode(",", $data['attachfor_properties']);
 
         NotificationModel::update($data);
 
-        $notification = NotificationModel::getById(['notificationId' => $data['notification_id']]);
+        $notification = NotificationModel::getById(['notification_sid' => $data['notification_sid']]);
+
+        // if (PHP_OS == "Linux") {
+        //     $ScheduleNotifications = new ScheduleNotifications();
+        //     $ScheduleNotifications->createScriptNotification($control['value'], $notifObj->notification_id);
+        // }
 
         HistoryController::add([
             'tableName' => 'notifications',
@@ -168,6 +176,12 @@ class NotificationController
             return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
         }
 
+        if (!Validator::intVal()->validate($aArgs['id'])) {
+            return $response
+                ->withStatus(500)
+                ->withJson(['errors' => 'Id is not a numeric']);
+        }
+
         NotificationModel::delete(['notification_sid' => $aArgs['id']]);
 
         HistoryController::add([
@@ -178,12 +192,84 @@ class NotificationController
                 'info'      => _DELETE_NOTIFICATIONS . ' : ' . $aArgs['id']
             ]);
 
+            // if (PHP_OS == "Linux") {
+            //     // delete scheduled notification
+            //     $filename = "notification";
+            //     if (isset($_SESSION['custom_override_id']) && $_SESSION['custom_override_id']<>"") {
+            //         $filename.="_".str_replace(" ", "", $_SESSION['custom_override_id']);
+            //     }
+            //     $filename.="_".$notification_sid.".sh";
+
+            //     $scheduleNotification = new ScheduleNotifications();
+            //     $cronTab = $scheduleNotification->getCrontab();
+
+            //     $flagCron = false;
+
+            //     if ($_SESSION['custom_override_id'] <> '') {
+            //         $pathToFolow = $_SESSION['config']['corepath'] . 'custom/'.$_SESSION['custom_override_id'] . '/';
+            //     } else {
+            //         $pathToFolow = $_SESSION['config']['corepath'];
+            //     }
+
+            //     foreach ($cronTab as $key => $value) {
+            //         if($value['cmd'] == $pathToFolow.'modules/notifications/batch/scripts/'.$filename){
+            //             $cronTab[$key]['state'] = 'deleted';
+            //             $flagCron = true;
+            //             break;
+            //         }
+            //     }
+
+            //     if ($flagCron) {
+            //         $scheduleNotification->saveCrontab($cronTab, true);
+            //     }
+                
+            //     unlink($pathToFolow . 'modules/notifications/batch/scripts/' . $filename);
+            // }
 
         return $response->withJson([
             'notifications' => NotificationModel::get()
         ]);
     }
 
+    protected function control($aArgs, $mode)
+    {
+        $errors = [];
+
+        if ($mode == 'update') {
+            if (!Validator::intVal()->validate($aArgs['notification_sid'])) {
+                $errors[] = 'notification_sid is not a numeric';
+            } else {
+                $obj = NotificationModel::getById(['notification_sid' => $aArgs['notification_sid']]);
+            }
+           
+            if (empty($obj)) {
+                $errors[] = 'notification does not exists';
+            }
+        }
+
+        if (!Validator::notEmpty()->validate($aArgs['notification_id'])) {
+            $errors[]= 'notification_id is empty';
+        }
+        if (!Validator::length(1, 254)->notEmpty()->validate($aArgs['description'])) {
+            $errors[]= 'wrong format for description';
+        }
+        if (!Validator::length(0, 254)->validate($dataArgsa['event_id'])) {
+            $errors[]= 'event_id is too long';
+        }
+        if (!Validator::length(0, 30)->validate($aArgs['notification_mode'])) {
+            $errors[]= 'notification_mode is too long';
+        }
+        if (!Validator::intType()->notEmpty()->validate($aArgs['template_id'])) {
+            $errors[]= 'wrong format for template_id';
+        }
+        if (!Validator::notEmpty()->validate($aArgs['is_enabled']) || ($aArgs['is_enabled'] != 'Y' && $aArgs['is_enabled'] != 'N')) {
+            $errors[]= 'Invalid is_enabled value';
+        }
+
+        return $errors;
+
+    }
+
     public function initNotification(Request $request, Response $response)
     {
         if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) {
-- 
GitLab