From 3a7f877fa15880c801c37a0d2f4b6937e64adf34 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Thu, 6 Dec 2018 18:11:18 +0100
Subject: [PATCH] FEAT #8931 badge nb document

---
 phpunit.xml                                   |  1 +
 src/core/models/AuthenticationModel.php       |  2 +-
 .../app/sidebar/sidebar.component.html        |  4 +--
 .../unitTests/core/PasswordControllerTest.php | 35 +++++++++++++++++++
 4 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100755 test/unitTests/core/PasswordControllerTest.php

diff --git a/phpunit.xml b/phpunit.xml
index e2199f1ff6..952987b764 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -3,6 +3,7 @@
     <testsuites>
         <testsuite name="Maarch Test Suite">
             <file>test/unitTests/core/AuthenticationControllerTest.php</file>
+            <file>test/unitTests/core/PasswordControllerTest.php</file>
             <file>test/unitTests/app/user/UserControllerTest.php</file>
             <file>test/unitTests/app/document/DocumentControllerTest.php</file>
         </testsuite>
diff --git a/src/core/models/AuthenticationModel.php b/src/core/models/AuthenticationModel.php
index 52ba155e73..f982f49c36 100755
--- a/src/core/models/AuthenticationModel.php
+++ b/src/core/models/AuthenticationModel.php
@@ -117,7 +117,7 @@ class AuthenticationModel
             'lang'      => empty($previousCookie['lang']) ? CoreConfigModel::getLanguage() : $previousCookie['lang'],
             'cookieKey' => $cookieKey
         ]);
-        setcookie('maarchParapheurAuth', base64_encode($cookieData), $cookieTime, $cookiePath, '', false, false);
+        @setcookie('maarchParapheurAuth', base64_encode($cookieData), $cookieTime, $cookiePath, '', false, false);
 
         return true;
     }
diff --git a/src/frontend/app/sidebar/sidebar.component.html b/src/frontend/app/sidebar/sidebar.component.html
index f03dc1b90b..43bcf428fb 100755
--- a/src/frontend/app/sidebar/sidebar.component.html
+++ b/src/frontend/app/sidebar/sidebar.component.html
@@ -13,8 +13,8 @@
     <header class="sidebar-header">
     </header>
     <section class="sidebar-btn">
-      <button class="btn btn-xs blue filter" [ngClass]="[mode == 'NOTE' ? 'active' : '']" (click)="filter('NOTE')">Annotation <span class="badgeNbDocument">{{signaturesService.documentsListCount["NOTE"]}}</span></button>
-      <button class="btn btn-xs blue filter" [ngClass]="[mode == 'SIGN' ? 'active' : '']" (click)="filter('SIGN')">Paraphe <span class="badgeNbDocument">{{signaturesService.documentsListCount["SIGN"]}}</span></button>
+      <button class="btn btn-xs blue filter" [ngClass]="[mode == 'NOTE' ? 'active' : '']" (click)="filter('NOTE')">Annotation <span *ngIf="signaturesService.documentsListCount['NOTE']" class="badgeNbDocument">{{signaturesService.documentsListCount["NOTE"]}}</span></button>
+      <button class="btn btn-xs blue filter" [ngClass]="[mode == 'SIGN' ? 'active' : '']" (click)="filter('SIGN')">Paraphe <span *ngIf="signaturesService.documentsListCount['SIGN']" class="badgeNbDocument">{{signaturesService.documentsListCount["SIGN"]}}</span></button>
     </section>
   </div>
   <ul #listContent class="nav" detect-scroll (onScroll)="handleScroll($event)" [bottomOffset]="1" [topOffset]="1">
diff --git a/test/unitTests/core/PasswordControllerTest.php b/test/unitTests/core/PasswordControllerTest.php
new file mode 100755
index 0000000000..115228cc20
--- /dev/null
+++ b/test/unitTests/core/PasswordControllerTest.php
@@ -0,0 +1,35 @@
+<?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 PasswordControllerTest extends TestCase
+{
+    public function testGet()
+    {
+        $passwordController = new \SrcCore\controllers\PasswordController();
+
+        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
+        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+
+        $response     = $passwordController->get($request, new \Slim\Http\Response());
+        $responseBody = json_decode((string)$response->getBody());
+
+        $this->assertNotEmpty($responseBody->rules);
+
+        foreach ($responseBody->rules as $value) {
+            $this->assertNotEmpty($value->id);
+            $this->assertInternalType('int', $value->id);
+            $this->assertNotEmpty($value->label);
+            $this->assertInternalType('int', $value->value);
+            $this->assertInternalType('boolean', $value->enabled);
+        }
+
+    }
+}
-- 
GitLab