From cce733e7e0153b041e683c9127a743309d944868 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Thu, 1 Mar 2018 18:34:35 +0100
Subject: [PATCH] FEAT #146 & #147 TU history and historyBatch

---
 core/Test/HistoryControllerTest.php           | 55 +++++++++++++++++++
 phpunit.xml                                   |  4 +-
 .../controllers/HistoryBatchController.php    |  2 +-
 3 files changed, 59 insertions(+), 2 deletions(-)
 create mode 100755 core/Test/HistoryControllerTest.php

diff --git a/core/Test/HistoryControllerTest.php b/core/Test/HistoryControllerTest.php
new file mode 100755
index 00000000000..5037ea3979d
--- /dev/null
+++ b/core/Test/HistoryControllerTest.php
@@ -0,0 +1,55 @@
+<?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.
+*
+*/
+
+use PHPUnit\Framework\TestCase;
+
+class HistoryControllerTest extends TestCase
+{
+    public function testGetHistoryByUserId()
+    {
+        $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request     = \Slim\Http\Request::createFromEnvironment($environment);
+        $history     = new \History\controllers\HistoryController();
+
+        $response = $history->getByUserId($request, new \Slim\Http\Response(), ['userSerialId' => 1]);
+
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotNull($responseBody->histories);
+    }
+
+    public function testGetHistory()
+    {
+        $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request     = \Slim\Http\Request::createFromEnvironment($environment);
+        $history     = new \History\controllers\HistoryController();
+
+        $response = $history->get($request, new \Slim\Http\Response(), ['date' => '2018-01-02']);
+
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotNull($responseBody->filters->users);
+        $this->assertNotNull($responseBody->filters->eventType);
+        $this->assertNotNull($responseBody->historyList);
+    }
+
+    public function testGetHistoryBatch()
+    {
+        $environment  = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request      = \Slim\Http\Request::createFromEnvironment($environment);
+        $historyBatch = new \History\controllers\HistoryBatchController();
+
+        $response = $historyBatch->get($request, new \Slim\Http\Response(), ['date' => '2018-01-02']);
+
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotNull($responseBody->filters->modules);
+        $this->assertNotNull($responseBody->historyList);
+    }
+}
diff --git a/phpunit.xml b/phpunit.xml
index a3540525d8e..c008de4e66c 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -6,9 +6,9 @@
             <file>core/Test/ActionControllerTest.php</file>
             <file>core/Test/BasketControllerTest.php</file>
             <file>core/Test/ContactControllerTest.php</file>
+            <file>core/Test/DoctypeControllerTest.php</file>
             <file>core/Test/EntityControllerTest.php</file>
             <file>core/Test/ListTemplateControllerTest.php</file>
-            <file>core/Test/DoctypeControllerTest.php</file>
             <file>core/Test/NotificationControllerTest.php</file>
             <file>core/Test/NotificationScheduleControllerTest.php</file>
             <file>core/Test/ParameterControllerTest.php</file>
@@ -21,6 +21,8 @@
             <file>modules/convert/Test/ProcessFulltextTest.php</file>
             <file>modules/convert/Test/ProcessManageConvertTest.php</file>
             <file>modules/convert/Test/ProcessThumbnailsTest.php</file>
+            <!-- The last one should be history -->
+            <file>core/Test/HistoryControllerTest.php</file>
         </testsuite>
     </testsuites>
     <filter>
diff --git a/src/app/history/controllers/HistoryBatchController.php b/src/app/history/controllers/HistoryBatchController.php
index 7c1e488da48..5e37cc736be 100644
--- a/src/app/history/controllers/HistoryBatchController.php
+++ b/src/app/history/controllers/HistoryBatchController.php
@@ -14,7 +14,7 @@
 
 namespace History\controllers;
 
-use Core\Models\ServiceModel;
+use Group\models\ServiceModel;
 use History\models\HistoryBatchModel;
 use Slim\Http\Request;
 use Slim\Http\Response;
-- 
GitLab