From d888e412064bb6bcf545864ad3e1860a5d62e643 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Thu, 1 Nov 2018 18:52:48 +0100
Subject: [PATCH] FEAT Add TU

---
 modules/folder/xml/services.xml               |   1 +
 phpunit.xml                                   |   1 +
 .../controllers/PriorityController.php        |   2 +-
 .../priorities-administration.component.ts    |   2 +-
 .../app/entity/ListTemplateControllerTest.php |  16 +++
 .../app/group/GroupControllerTest.php         |  46 ++++++-
 .../unitTests/app/home/HomeControllerTest.php |  33 +++++
 .../app/priority/PriorityControllerTest.php   |  21 ++-
 .../app/status/StatusControllerTest.php       |  23 +++-
 .../unitTests/app/user/UserControllerTest.php | 129 +++++++++++++++++-
 test/unitTests/core/CoreControllerTest.php    |  26 ++++
 11 files changed, 289 insertions(+), 11 deletions(-)
 create mode 100644 test/unitTests/app/home/HomeControllerTest.php

diff --git a/modules/folder/xml/services.xml b/modules/folder/xml/services.xml
index 309665b7529..06ba39de238 100755
--- a/modules/folder/xml/services.xml
+++ b/modules/folder/xml/services.xml
@@ -14,6 +14,7 @@
     <SERVICE>
         <id>view_folder_tree</id>
         <name>_VIEW_FOLDER_TREE</name>
+        <comment>_VIEW_FOLDER_TREE</comment>
         <servicepage>index.php?page=search_folder_tree&amp;module=folder</servicepage>
         <servicetype>menu</servicetype>
         <system_service>false</system_service>
diff --git a/phpunit.xml b/phpunit.xml
index 3c14ca419ad..0a247f9b5da 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -3,6 +3,7 @@
     <testsuites>
         <testsuite name="Maarch Test Suite">
             <!--directory>test</directory-->
+            <file>test/unitTests/app/home/HomeControllerTest.php</file>
             <file>test/unitTests/app/action/ActionControllerTest.php</file>
             <file>test/unitTests/core/AutocompleteControllerTest.php</file>
             <file>test/unitTests/core/AuthenticationControllerTest.php</file>
diff --git a/src/app/priority/controllers/PriorityController.php b/src/app/priority/controllers/PriorityController.php
index 6aee379ed02..1cfd802ab99 100644
--- a/src/app/priority/controllers/PriorityController.php
+++ b/src/app/priority/controllers/PriorityController.php
@@ -140,7 +140,7 @@ class PriorityController
             'orderBy'   => ['"order" NULLS LAST']
         ]);
 
-        return $response->withJson(['priotities' => $priorities]);
+        return $response->withJson(['priorities' => $priorities]);
     }
 
     public function updateSort(Request $request, Response $response)
diff --git a/src/frontend/app/administration/priority/priorities-administration.component.ts b/src/frontend/app/administration/priority/priorities-administration.component.ts
index b3f36c536bf..9591a8bbcb4 100644
--- a/src/frontend/app/administration/priority/priorities-administration.component.ts
+++ b/src/frontend/app/administration/priority/priorities-administration.component.ts
@@ -65,7 +65,7 @@ export class PrioritiesAdministrationComponent implements OnInit {
                 this.loading = false;
                 this.http.get(this.coreUrl + "rest/sortedPriorities")
                     .subscribe((data: any) => {
-                        this.prioritiesOrder = data['priotities'];
+                        this.prioritiesOrder = data['priorities'];
                     }, () => {
                         location.href = "index.php";
                     });
diff --git a/test/unitTests/app/entity/ListTemplateControllerTest.php b/test/unitTests/app/entity/ListTemplateControllerTest.php
index e505cca14d2..f8ba260f989 100644
--- a/test/unitTests/app/entity/ListTemplateControllerTest.php
+++ b/test/unitTests/app/entity/ListTemplateControllerTest.php
@@ -201,4 +201,20 @@ class ListTemplateControllerTest extends TestCase
 
         $this->assertSame('List template not found', $responseBody->errors);
     }
+
+    public function testGetTypesRoles()
+    {
+        $listTemplateController = new \Entity\controllers\ListTemplateController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $response       = $listTemplateController->getTypeRoles($request, new \Slim\Http\Response(), ['typeId' => 'entity_id']);
+        $responseBody   = json_decode((string)$response->getBody());
+
+        foreach ($responseBody->roles as $value) {
+            $this->assertNotEmpty($value->id);
+            $this->assertNotEmpty($value->label);
+            $this->assertInternalType("bool", $value->available);
+        }
+    }
 }
diff --git a/test/unitTests/app/group/GroupControllerTest.php b/test/unitTests/app/group/GroupControllerTest.php
index a80eb0f910e..f3c5a699116 100644
--- a/test/unitTests/app/group/GroupControllerTest.php
+++ b/test/unitTests/app/group/GroupControllerTest.php
@@ -9,7 +9,6 @@
 
 use PHPUnit\Framework\TestCase;
 
-
 class GroupControllerTest extends TestCase
 {
     private static $id = null;
@@ -100,6 +99,50 @@ class GroupControllerTest extends TestCase
         $this->assertSame(true, $responseBody->group->canAdminBaskets);
     }
 
+    public function testGetById()
+    {
+        $groupController = new \Group\controllers\GroupController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response     = $groupController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotEmpty($responseBody->group);
+
+        $this->assertSame(self::$id, (string)$responseBody->group->id);
+        $this->assertSame('TEST-JusticeLeague', $responseBody->group->group_id);
+        $this->assertSame('Beyond the darkness #2', $responseBody->group->group_desc);
+        $this->assertSame('Y', $responseBody->group->enabled);
+
+        // ERROR
+        $response     = $groupController->getById($request, new \Slim\Http\Response(), ['id' => '123456789']);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('Group not found', $responseBody->errors);
+    }
+
+    public function testGet()
+    {
+        $groupController = new \Group\controllers\GroupController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response     = $groupController->get($request, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotEmpty($responseBody->groups);
+
+        foreach ($responseBody->groups as $value) {
+            $this->assertNotEmpty($value->group_id);
+            $this->assertNotEmpty($value->group_desc);
+            $this->assertNotNull($value->users);
+            $this->assertInternalType("int", $value->id);
+        }
+    }
+
     public function testDelete()
     {
         $groupController = new \Group\controllers\GroupController();
@@ -121,5 +164,4 @@ class GroupControllerTest extends TestCase
 
         $this->assertSame('Group not found', $responseBody->errors);
     }
-
 }
diff --git a/test/unitTests/app/home/HomeControllerTest.php b/test/unitTests/app/home/HomeControllerTest.php
new file mode 100644
index 00000000000..d4ee53e6d18
--- /dev/null
+++ b/test/unitTests/app/home/HomeControllerTest.php
@@ -0,0 +1,33 @@
+<?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.
+
+*
+* @brief   HomeControllerTest
+*
+* @author  dev <dev@maarch.org>
+* @ingroup core
+*/
+use PHPUnit\Framework\TestCase;
+
+class HomeControllerTest extends TestCase
+{
+    private static $id = null;
+
+    public function testGet()
+    {
+        $homeController = new \Home\controllers\HomeController();
+
+        $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response = $homeController->get($request, new \Slim\Http\Response());
+        $responseBody = json_decode((string) $response->getBody());
+        
+        $this->assertNotNull($responseBody->regroupedBaskets);
+        $this->assertNotNull($responseBody->assignedBaskets);
+        $this->assertNotEmpty($responseBody->homeMessage);
+    }
+}
diff --git a/test/unitTests/app/priority/PriorityControllerTest.php b/test/unitTests/app/priority/PriorityControllerTest.php
index 57f3e3677bd..4cc47d03001 100644
--- a/test/unitTests/app/priority/PriorityControllerTest.php
+++ b/test/unitTests/app/priority/PriorityControllerTest.php
@@ -13,7 +13,6 @@ class PriorityControllerTest extends TestCase
 {
     private static $id = null;
 
-
     public function testCreate()
     {
         $priorityController = new \Priority\controllers\PriorityController();
@@ -120,4 +119,24 @@ class PriorityControllerTest extends TestCase
 
         $this->assertSame('Priority not found', $responseBody->errors);
     }
+
+    public function testGetSorted()
+    {
+        $priorityController = new \Priority\controllers\PriorityController();
+
+        //  GET
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $response       = $priorityController->getSorted($request, new \Slim\Http\Response());
+        $responseBody   = json_decode((string)$response->getBody());
+
+        $this->assertInternalType('array', $responseBody->priorities);
+        $this->assertNotEmpty($responseBody->priorities);
+        
+        foreach ($responseBody->priorities as $value) {
+            $this->assertNotEmpty($value->id);
+            $this->assertNotEmpty($value->label);
+            $this->assertInternalType('int', $value->order);
+        }
+    }
 }
diff --git a/test/unitTests/app/status/StatusControllerTest.php b/test/unitTests/app/status/StatusControllerTest.php
index 0762340d6b6..431a3782538 100644
--- a/test/unitTests/app/status/StatusControllerTest.php
+++ b/test/unitTests/app/status/StatusControllerTest.php
@@ -75,6 +75,25 @@ class StatusControllerTest extends TestCase
         $this->assertSame('Invalid label_status value', $responseBody->errors[0]);
     }
 
+    public function testGetById()
+    {
+        $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request     = \Slim\Http\Request::createFromEnvironment($environment);
+        $status      = new \Status\controllers\StatusController();
+
+        $response  = $status->getById($request, new \Slim\Http\Response(), ['id' => 'TEST']);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotEmpty($responseBody->status[0]);
+        $this->assertSame('TEST', $responseBody->status[0]->id);
+
+        // ERROR
+        $response  = $status->getById($request, new \Slim\Http\Response(), ['id' => 'NOTFOUNDSTATUS']);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('id not found', $responseBody->errors);
+    }
+
     public function testGetListUpdateDelete()
     {
         ########## GET LIST ##########
@@ -91,8 +110,6 @@ class StatusControllerTest extends TestCase
             $this->assertInternalType("int", $value->identifier);
         }
 
-        //$this->assertNotNull($responseBody->lang);
-
         $elem = $responseBody->statuses;
         end($elem);
         $key = key($elem);
@@ -177,7 +194,6 @@ class StatusControllerTest extends TestCase
 
         $response = $status->delete($request, new \Slim\Http\Response(), ['identifier'=> $lastIdentifier]);
 
-        //$this->assertSame((string)$response->getBody(), '[true]');
         $this->assertRegexp('/statuses/', (string)$response->getBody());
     }
 
@@ -192,6 +208,5 @@ class StatusControllerTest extends TestCase
         $responseBody = json_decode((string)$response->getBody());
 
         $this->assertNotNull($responseBody->statusImages);
-        //$this->assertNotNull($responseBody->lang);
     }
 }
diff --git a/test/unitTests/app/user/UserControllerTest.php b/test/unitTests/app/user/UserControllerTest.php
index c806711da3a..52c09378511 100644
--- a/test/unitTests/app/user/UserControllerTest.php
+++ b/test/unitTests/app/user/UserControllerTest.php
@@ -9,10 +9,10 @@
 
 use PHPUnit\Framework\TestCase;
 
-
 class UserControllerTest extends TestCase
 {
     private static $id = null;
+    private static $idEmailSignature = null;
 
 
     public function testGet()
@@ -340,6 +340,18 @@ class UserControllerTest extends TestCase
         $this->assertEmpty($responseBody->entities);
     }
 
+    public function testGetStatusByUserId()
+    {
+        $userController = new \User\controllers\UserController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $response     = $userController->getStatusByUserId($request, new \Slim\Http\Response(), ['userId' => 'TEST-CKENT']);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('OK', $responseBody->status);
+    }
+
     public function testUpdateStatus()
     {
         $userController = new \User\controllers\UserController();
@@ -367,6 +379,18 @@ class UserControllerTest extends TestCase
         $this->assertSame('ABS', $responseBody->status);
     }
 
+    public function testGetStatusByUserIdAfterUpdate()
+    {
+        $userController = new \User\controllers\UserController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $response     = $userController->getStatusByUserId($request, new \Slim\Http\Response(), ['userId' => 'TEST-CKENT']);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('ABS', $responseBody->status);
+    }
+
     public function testRead()
     {
         $userController = new \User\controllers\UserController();
@@ -413,7 +437,6 @@ class UserControllerTest extends TestCase
         $this->assertSame(20, $responseBody->quota->userQuota);
         $this->assertNotNull($responseBody->quota->actives);
         $this->assertInternalType('int', $responseBody->quota->inactives);
-
     }
 
     public function testUserQuota()
@@ -491,6 +514,108 @@ class UserControllerTest extends TestCase
         $parameterController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'user_quota']);
     }
 
+    public function testCreateEmailSignature()
+    {
+        $userController = new \User\controllers\UserController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $aArgs = [
+            'title'    => 'Titre email signature TU 12345',
+            'htmlBody' => '<p>Body Email Signature</p>'
+        ];
+        $fullRequest    = \httpRequestCustom::addContentInBody($aArgs, $request);
+        $response = $userController->createCurrentUserEmailSignature($fullRequest, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+        $this->assertNotEmpty($responseBody->emailSignatures);
+
+        $titleEmailSignature = '';
+        $htmlBodyEmailSignature = '';
+        foreach ($responseBody->emailSignatures as $value) {
+            if ($value->title == 'Titre email signature TU 12345') {
+                self::$idEmailSignature = $value->id;
+                $titleEmailSignature    = $value->title;
+                $htmlBodyEmailSignature = $value->html_body;
+            }
+        }
+        $this->assertNotEmpty(self::$idEmailSignature);
+        $this->assertInternalType('int', self::$idEmailSignature);
+        $this->assertSame('Titre email signature TU 12345', $titleEmailSignature);
+        $this->assertSame('<p>Body Email Signature</p>', $htmlBodyEmailSignature);
+
+        // ERROR
+        $aArgs = [
+            'title'    => '',
+            'htmlBody' => ''
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $response     = $userController->createCurrentUserEmailSignature($fullRequest, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('Bad Request', $responseBody->errors);
+    }
+
+    public function testUpdateEmailSignature()
+    {
+        $userController = new \User\controllers\UserController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $aArgs = [
+            'title'    => 'Titre email signature TU 12345 UPDATE',
+            'htmlBody' => '<p>Body Email Signature UPDATE</p>'
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $response     = $userController->updateCurrentUserEmailSignature($fullRequest, new \Slim\Http\Response(), ['id' => self::$idEmailSignature]);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotEmpty($responseBody->emailSignature);
+        $this->assertNotEmpty($responseBody->emailSignature->id);
+        $this->assertInternalType('int', $responseBody->emailSignature->id);
+        $this->assertSame('Titre email signature TU 12345 UPDATE', $responseBody->emailSignature->title);
+        $this->assertSame('<p>Body Email Signature UPDATE</p>', $responseBody->emailSignature->html_body);
+
+        // ERROR
+        $aArgs = [
+            'title'    => '',
+            'htmlBody' => ''
+        ];
+        $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
+
+        $response     = $userController->updateCurrentUserEmailSignature($fullRequest, new \Slim\Http\Response(), ['id' => self::$idEmailSignature]);
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertSame('Bad Request', $responseBody->errors);
+    }
+
+    public function testDeleteEmailSignature()
+    {
+        $userController = new \User\controllers\UserController();
+
+        //  DELETE
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $response       = $userController->deleteCurrentUserEmailSignature($request, new \Slim\Http\Response(), ['id' => self::$idEmailSignature]);
+        $responseBody   = json_decode((string)$response->getBody());
+
+        $this->assertNotEmpty($responseBody->emailSignatures);
+
+        $titleEmailSignature = '';
+        $htmlBodyEmailSignature = '';
+        foreach ($responseBody->emailSignatures as $value) {
+            if ($value->title == 'Titre email signature TU 12345 UPDATE') {
+                // Check If Signature Really Deleted
+                $titleEmailSignature    = $value->title;
+                $htmlBodyEmailSignature = $value->html_body;
+            }
+        }
+        $this->assertSame('', $titleEmailSignature);
+        $this->assertSame('', $htmlBodyEmailSignature);
+    }
+
     public function testDelete()
     {
         $userController = new \User\controllers\UserController();
diff --git a/test/unitTests/core/CoreControllerTest.php b/test/unitTests/core/CoreControllerTest.php
index ee7f89e4add..df1a7ca3dde 100644
--- a/test/unitTests/core/CoreControllerTest.php
+++ b/test/unitTests/core/CoreControllerTest.php
@@ -39,6 +39,32 @@ class CoreControllerTest extends TestCase
     //     $this->assertNotEmpty($responseBody->scriptsToinject);
     // }
 
+    public function testGetHeader()
+    {
+        $coreController = new \SrcCore\controllers\CoreController();
+
+        $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request     = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response     = $coreController->getHeader($request, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+        $this->assertNotEmpty($responseBody->user);
+        $this->assertInternalType('int', $responseBody->user->id);
+        $this->assertSame("superadmin", $responseBody->user->user_id);
+        $this->assertSame("Super", $responseBody->user->firstname);
+        $this->assertSame("Admin", $responseBody->user->lastname);
+        $this->assertInternalType('array', $responseBody->user->groups);
+        $this->assertInternalType('array', $responseBody->user->entities);
+        $this->assertInternalType('array', $responseBody->user->indexingGroups);
+        $this->assertNotEmpty($responseBody->menu);
+
+        foreach ($responseBody->menu as $value) {
+            $this->assertNotEmpty($value->id);
+            $this->assertNotEmpty($value->name);
+            $this->assertNotEmpty($value->comment);
+        }
+    }
+
     public function testGetAdministration()
     {
         $coreController = new \SrcCore\controllers\CoreController();
-- 
GitLab