From ed8f7b5d8e4fd3c62073645a14b55ab83e304b75 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Mon, 25 Feb 2019 12:31:28 +0100
Subject: [PATCH] FEAT #9105 fix lock + unit tests

---
 .../controllers/ResourceListController.php    | 12 +++---
 .../app/action/ActionControllerTest.php       | 39 ++++++++-----------
 2 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php
index 062cb239d9a..be02c60a2ce 100644
--- a/src/app/resource/controllers/ResourceListController.php
+++ b/src/app/resource/controllers/ResourceListController.php
@@ -608,11 +608,13 @@ class ResourceListController
             }
         }
 
-        ResModel::update([
-            'set'   => ['locker_user_id' => $currentUser['id'], 'locker_time' => 'CURRENT_TIMESTAMP + interval \'1\' MINUTE'],
-            'where' => ['res_id in (?)'],
-            'data'  => [$resourcesToLock]
-        ]);
+        if (!empty($resourcesToLock)) {
+            ResModel::update([
+                'set'   => ['locker_user_id' => $currentUser['id'], 'locker_time' => 'CURRENT_TIMESTAMP + interval \'1\' MINUTE'],
+                'where' => ['res_id in (?)'],
+                'data'  => [$resourcesToLock]
+            ]);
+        }
 
         return $response->withJson(['lockedResources' => $locked]);
     }
diff --git a/test/unitTests/app/action/ActionControllerTest.php b/test/unitTests/app/action/ActionControllerTest.php
index ffb06c53427..4524de7b063 100755
--- a/test/unitTests/app/action/ActionControllerTest.php
+++ b/test/unitTests/app/action/ActionControllerTest.php
@@ -25,12 +25,12 @@ class ActionsControllerTest extends TestCase
         $request     = \Slim\Http\Request::createFromEnvironment($environment);
 
         $aArgs = [
-            'keyword'          => 'indexing',
-            'label_action'     => 'TEST-LABEL',
-            'id_status'        => '_NOSTATUS_',
-            'action_page'      => 'index_mlb',
-            'history'          => true,
-            'origin'           => 'apps',
+            'keyword'       => 'indexing',
+            'label_action'  => 'TEST-LABEL',
+            'id_status'     => '_NOSTATUS_',
+            'actionPageId'  => 'index_mlb',
+            'history'       => true,
+            'origin'        => 'apps',
         ];
         $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
 
@@ -46,7 +46,7 @@ class ActionsControllerTest extends TestCase
             'keyword'          => 'indexing',
             'label_action'     => '',
             'id_status'        => '',
-            'action_page'      => 'index_mlb',
+            'actionPageId'     => 'index_mlb',
             'history'          => true,
             'origin'           => 'apps',
         ];
@@ -57,11 +57,11 @@ class ActionsControllerTest extends TestCase
         
         $this->assertSame('Invalid Status', $responseBody->errors[0]);
         $this->assertSame('Invalid label action', $responseBody->errors[1]);
-        $this->assertSame('id_status is empty', $responseBody->errors[2]);  
-
+        $this->assertSame('id_status is empty', $responseBody->errors[2]);
     }
 
-    public function testRead(){
+    public function testRead()
+    {
         //  READ
         $environment      = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
         $request          = \Slim\Http\Request::createFromEnvironment($environment);
@@ -86,12 +86,11 @@ class ActionsControllerTest extends TestCase
         $actionController = new \Action\controllers\ActionController();
         $response         = $actionController->getById($request, new \Slim\Http\Response(), ['id' => 'gaz']);
         $responseBody     = json_decode((string)$response->getBody());
-        $this->assertSame('Id is not a numeric', $responseBody->errors);
-
+        $this->assertSame('Route id is not an integer', $responseBody->errors);
     }
 
-    public function testReadList(){
-        //  READ LIST
+    public function testReadList()
+    {
         $environment  = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
         $request      = \Slim\Http\Request::createFromEnvironment($environment);
 
@@ -111,7 +110,7 @@ class ActionsControllerTest extends TestCase
             'keyword'          => '',
             'label_action'     => 'TEST-LABEL_UPDATED',
             'id_status'        => 'COU',
-            'action_page'      => 'process',
+            'actionPageId'     => 'process',
             'history'          => false,
             'origin'           => 'apps',
         ];
@@ -128,7 +127,7 @@ class ActionsControllerTest extends TestCase
             'keyword'          => '',
             'label_action'     => 'TEST-LABEL_UPDATED',
             'id_status'        => 'COU',
-            'action_page'      => 'process',
+            'actionPageId'     => 'process',
             'history'          => false,
             'origin'           => 'apps',
         ];
@@ -138,7 +137,6 @@ class ActionsControllerTest extends TestCase
         $response         = $actionController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'gaz']);
         $responseBody     = json_decode((string)$response->getBody());
         $this->assertSame('Id is not a numeric', $responseBody->errors[0]);
-
     }
 
     public function testDelete()
@@ -166,8 +164,7 @@ class ActionsControllerTest extends TestCase
         $response         = $actionController->delete($request, new \Slim\Http\Response(), ['id' => 'gaz']);
         $responseBody     = json_decode((string)$response->getBody());
 
-        $this->assertSame('Id is not a numeric', $responseBody->errors);
-
+        $this->assertSame('Route id is not an integer', $responseBody->errors);
     }
 
     public function testGetInitAction()
@@ -183,9 +180,7 @@ class ActionsControllerTest extends TestCase
         $this->assertNotNull($responseBody->action);
         $this->assertNotNull($responseBody->categoriesList);
         $this->assertNotNull($responseBody->statuses);
-        $this->assertNotNull($responseBody->action_pagesList);
+        $this->assertNotNull($responseBody->actionPages);
         $this->assertNotNull($responseBody->keywordsList);
-
     }
-
 }
-- 
GitLab