From e76a4fe17bd83a81ef3884a339180b5b0493ec2a Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Wed, 24 Jan 2018 11:21:54 +0100
Subject: [PATCH] [REFACTORING] test right + res tu

---
 core/Test/ResControllerTest.php               | 304 ------------------
 .../resource/controllers/ResController.php    |   4 +-
 2 files changed, 3 insertions(+), 305 deletions(-)

diff --git a/core/Test/ResControllerTest.php b/core/Test/ResControllerTest.php
index 3ad8a0b5a38..b68eb5ca293 100755
--- a/core/Test/ResControllerTest.php
+++ b/core/Test/ResControllerTest.php
@@ -1,7 +1,5 @@
 <?php
 
-namespace MaarchTest;
-
 /**
 * Copyright Maarch since 2008 under licence GPLv3.
 * See LICENCE.txt file at the root folder for more details.
@@ -9,311 +7,9 @@ namespace MaarchTest;
 *
 */
 
-namespace MaarchTest;
 use PHPUnit\Framework\TestCase;
 
 class ResControllerTest extends TestCase
 {
 
-    public function testPrepareStorage()
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $data = [];
-
-        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 = [
-            'data'        => $data,
-            'docserverId' => 'FASTHD_MAN',
-            'status'      => 'new',
-            'fileFormat'  => 'pdf',
-        ];
-
-        $response = $action->prepareStorage($aArgs);
-        
-        $this->assertArrayHasKey('column', $response[0]);
-    }
-
-    public function testStoreResource()
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $path = $_SESSION['config']['tmppath'] . '/test/';
-
-        if (!is_dir($path)) {
-            mkdir($path);
-        }
-
-        $fileSource = 'test_source.txt';
-
-        if (file_exists($path . $fileSource)) {
-            unlink($path . $fileSource);
-        }
-
-        $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);
-        
-        $this->assertGreaterThanOrEqual(0, $response[0]);
-    }
-
-    public function testDelete()
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $environment = \Slim\Http\Environment::mock(
-            [
-                'REQUEST_METHOD' => 'DELETE',
-            ]
-        );
-
-        $resId = \Core\Models\ResModel::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 testCreate()
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $environment = \Slim\Http\Environment::mock(
-            [
-                'REQUEST_METHOD' => 'POST',
-            ]
-        );
-
-        $path = $_SESSION['config']['tmppath'] . '/test/';
-
-        if (!is_dir($path)) {
-            mkdir($path);
-        }
-
-        $fileSource = 'test_source.txt';
-
-        if (file_exists($path . $fileSource)) {
-            unlink($path . $fileSource);
-        }
-
-        $fp = fopen($path . $fileSource, 'a');
-        fwrite($fp, 'a unit test');
-        fclose($fp);
-
-        $fileContent = file_get_contents($path . $fileSource, FILE_BINARY);
-        $encodedFile = base64_encode($fileContent);
-        //echo $encodedFile . PHP_EOL;exit;
-        
-        $data = [];
-
-        array_push(
-            $data,
-            array(
-                'column' => 'subject',
-                'value' => 'UNIT TEST from slim',
-                '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',
-            )
-        );
-        //print_r(json_encode($data));
-        //sample in json : [{"column":"subject","value":"UNIT T
-        //EST from slim","type":"string"},{"column":"type_id","value":110,"type":"integer"},
-        //{"column":"custom_t1","value":"TES
-        //T","type":"string"},{"column":"custom_t10","value":"lgi@maarch.org","type":"string"}]
-
-        $aArgs = [
-            'encodedFile'   => $encodedFile,
-            'data'          => $data,
-            'collId'        => 'letterbox_coll',
-            'table'         => 'res_letterbox',
-            'fileFormat'    => 'txt',
-            'status'        => 'new',
-        ];
-
-        $request = \Slim\Http\Request::createFromEnvironment($environment);
-        $response = new \Slim\Http\Response();
-        $response = $action->create($request, $response, $aArgs);
-        
-        $this->assertGreaterThan(1, json_decode($response->getBody())->resId);
-    }
-
-    public function testDeleteRes()
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $resId = \Core\Models\ResModel::getLastId(['select' => ['res_id']]);
-
-        $aArgs = [
-            'id'=> $resId[0]['res_id']
-        ];
-
-        $response = $action->deleteRes($aArgs);
-
-        $this->assertTrue($response);
-    }
-
-    public function testUpdate()
-    {
-        $action = new \Core\Controllers\ResController();
-
-        $environment = \Slim\Http\Environment::mock(
-            [
-                'REQUEST_METHOD' => 'POST',
-            ]
-        );
-        
-        $data = [];
-
-        array_push(
-            $data,
-            array(
-                'column' => 'status',
-                'value' => 'NEW',
-                'type' => 'string',
-            )
-        );
-
-        $resId = \Core\Models\ResModel::getLastId(['select' => ['res_id']]);
-
-        $aArgs = [
-            'table'         => 'res_letterbox',
-            'res_id'        => $resId[0]['res_id'],
-            'data'          => $data,
-        ];
-
-        $request = \Slim\Http\Request::createFromEnvironment($environment);
-        $response = new \Slim\Http\Response();
-        $response = $action->update($request, $response, $aArgs);
-        //print_r(json_decode($response->getBody())[0]->res_id);exit;
-        $this->assertGreaterThan(1, json_decode($response->getBody())[0]->res_id);
-    }
-
-    public function testUpdateResource()
-    {
-        $action = new \Core\Controllers\ResController();
-        
-        $data = [];
-
-        array_push(
-            $data,
-            array(
-                'column' => 'status',
-                'value' => 'NEW',
-                'type' => 'string',
-            )
-        );
-
-        $resId = \Core\Models\ResModel::getLastId(['select' => ['res_id']]);
-
-        $aArgs = [
-            'table'         => 'res_letterbox',
-            'res_id'        => $resId[0]['res_id'],
-            'data'          => $data,
-        ];
-
-        $response = $action->updateResource($aArgs);
-        //print_r($response);exit;
-        $this->assertGreaterThan(1, $response);
-    }
 }
diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php
index c011358a18c..420d695d54d 100755
--- a/src/app/resource/controllers/ResController.php
+++ b/src/app/resource/controllers/ResController.php
@@ -171,7 +171,9 @@ class ResController
         ValidatorModel::stringType($aArgs, ['userId']);
         ValidatorModel::intVal($aArgs, ['resId']);
 
-
+        if ($aArgs['userId'] == 'superadmin') {
+            return true;
+        }
         $groups = UserModel::getGroupsByUserId(['userId' => $aArgs['userId']]);
         $groupsClause = '';
         foreach ($groups as $key => $group) {
-- 
GitLab