From 7c492087e82f415cee0415521078350f368a232d Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Wed, 30 Sep 2015 11:58:39 +0200
Subject: [PATCH] dev #29524 - Add /help/cookies page which describes cookies
 use.

---
 .../opac/controllers/HelpController.php       | 29 +++++++
 .../opac/views/scripts/help/cookies.phtml     | 15 ++++
 library/Class/Cnil.php                        |  4 +-
 .../Helper/Help/GoogleAnalyticsWarning.php    | 26 ++++++
 .../modules/AbstractControllerTestCase.php    |  3 +
 .../opac/controllers/HelpControllerTest.php   | 87 +++++++++++++++++++
 .../opac/controllers/IndexControllerTest.php  |  9 +-
 7 files changed, 171 insertions(+), 2 deletions(-)
 create mode 100644 application/modules/opac/controllers/HelpController.php
 create mode 100644 application/modules/opac/views/scripts/help/cookies.phtml
 create mode 100644 library/ZendAfi/View/Helper/Help/GoogleAnalyticsWarning.php
 create mode 100644 tests/application/modules/opac/controllers/HelpControllerTest.php

diff --git a/application/modules/opac/controllers/HelpController.php b/application/modules/opac/controllers/HelpController.php
new file mode 100644
index 00000000000..8d5819dd78c
--- /dev/null
+++ b/application/modules/opac/controllers/HelpController.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+class HelpController extends ZendAfi_Controller_Action {
+  public function cookiesAction() {
+    $this->view->ga_warning = "";
+    if (Class_AdminVar::getGoogleAnalyticsId()) {
+      $this->view->ga_warning = $this->view->help_GoogleAnalyticsWarning();
+    }
+  }
+}
diff --git a/application/modules/opac/views/scripts/help/cookies.phtml b/application/modules/opac/views/scripts/help/cookies.phtml
new file mode 100644
index 00000000000..81fe0d8f1f4
--- /dev/null
+++ b/application/modules/opac/views/scripts/help/cookies.phtml
@@ -0,0 +1,15 @@
+<h3>Qu'est-ce qu'un cookie ?</h3>
+
+<p>Un cookie est un fichier texte déposé, sous réserve de vos choix, sur votre ordinateur lors de la visite d'un site ou de la consultation d'une publicité. Il a pour but de collecter des informations relatives à votre navigation et de vous adresser des services adaptés à votre terminal (ordinateur, mobile ou tablette).
+
+Les cookies sont gérés par votre navigateur internet et seul l’émetteur d’un cookie est susceptible de lire ou de modifier les informations qui y sont contenues.</p>
+
+<h3>A quoi servent les cookies émis sur notre site ?</h3>
+
+<p>Nous utilisons uniquement des cookies visant à faciliter votre navigation. Il s'agit notamment des cookies suivants:
+<ul>
+ <li>les cookies de session utilisés pour le maintient de l'authentification.</li>
+ <li>les cookies permettent d'identifier les services et rubriques que l'utilisateur a visités.</li>
+</ul>
+
+<?php echo $this->ga_warning; ?>
diff --git a/library/Class/Cnil.php b/library/Class/Cnil.php
index bb1b8a4cc1e..01f3324dbf6 100644
--- a/library/Class/Cnil.php
+++ b/library/Class/Cnil.php
@@ -61,8 +61,10 @@ class Class_Cnil {
 
 
   protected function _displayMessage() {
+    $read_more = Class_Url::absolute(['controller' => 'help',
+                                      'action' => 'cookies']);
     Class_ScriptLoader::getInstance()
-      ->notify($this->_('En poursuivant votre navigation sur ce site, vous acceptez l\'utilisation de cookies.'),
+      ->notify($this->_('En poursuivant votre navigation sur ce site, vous acceptez l\'utilisation de cookies. <a href="'.$read_more.'">En savoir plus</a>'),
                false);
   }
 
diff --git a/library/ZendAfi/View/Helper/Help/GoogleAnalyticsWarning.php b/library/ZendAfi/View/Helper/Help/GoogleAnalyticsWarning.php
new file mode 100644
index 00000000000..0cedc0e9dc0
--- /dev/null
+++ b/library/ZendAfi/View/Helper/Help/GoogleAnalyticsWarning.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+class ZendAfi_View_Helper_Help_GoogleAnalyticsWarning extends Zend_View_Helper_HtmlElement {
+  public function help_googleAnalyticsWarning() {
+    return $this->view->tag('p', $this->view->_('Pour les mesures de trafic dites de “Webanalytics”, 
+notre site utilise les services de Google Analytics. Pour bloquer l’utilisation des données par Google Analytics : https://tools.google.com/dlpage/gaoptout'));
+  }
+}
diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php
index f4405305b0c..fc563cbebf1 100644
--- a/tests/application/modules/AbstractControllerTestCase.php
+++ b/tests/application/modules/AbstractControllerTestCase.php
@@ -152,6 +152,9 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe
 
     if($this->_storm_default_to_volatile)
       Storm_Model_Loader::defaultToVolatile();
+
+    $this->fixture('Class_AdminVar', ['id' => 'CNIL_CONSENT_ENABLE',
+                                      'valeur' => false]);
   }
 
 
diff --git a/tests/application/modules/opac/controllers/HelpControllerTest.php b/tests/application/modules/opac/controllers/HelpControllerTest.php
new file mode 100644
index 00000000000..98b8746cf23
--- /dev/null
+++ b/tests/application/modules/opac/controllers/HelpControllerTest.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+class HelpControlleriCnilComplianceTest extends AbstractControllerTestCase {
+  public function setUp() {
+    parent::setUp();
+
+    $this->dispatch('/help/cookies', true);
+  }
+
+
+  /** @test */
+  public function pageShouldContainTitleQuEstCeQuUnCookie() {
+    $this->assertXPathContentContains('//h3', "Qu'est-ce qu'un cookie ?");
+  }
+
+
+  /** @test */
+  public function pageShouldExplainQuEstCeQuUnCookie() {
+    $this->assertXPathContentContains('//p', 'Un cookie est un fichier texte déposé, sous réserve de vos choix');
+  }
+
+
+  /** @test */
+  public function pageShouldContainTitleAQuoiServentLesCookiesEmisSurNotreSite() {
+    $this->assertXPathContentContains('//h3', "A quoi servent les cookies émis sur notre site ?");
+  }
+
+
+  /** @test */
+  public function pageShouldNotWarnAboutGoogleAnalytic() {
+    $this->assertNotXPathContentContains('//p', 'utilise les services de Google Analytics');
+  }
+}
+
+
+
+class HelpControlleriCnilComplianceWithGoogleAnalyticsTest extends AbstractControllerTestCase {
+
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->fixture('Class_AdminVar', ['id' =>'JS_STAT',
+                                      'valeur' => "<script> var _gaq = _gaq ||
+                                                  []; _gaq.push(['_setAccount',
+                                                  'UA-41754005-1']);
+                                                  _gaq.push(['_trackPageview']);
+                                                  (function() { var ga =
+                                                  document.createElement('script');
+                                                  ga.type = 'text/javascript'; ga.async =
+                                                  true; ga.src = ('https:' ==
+                                                  document.location.protocol ?
+                                                  'https://ssl' : 'http://www') +
+                                                  '.google-analytics.com/ga.js'; var
+                                                  s =
+                                                  document.getElementsByTagName('script')[
+                                                  0]; s.parentNode.insertBefore(ga, s);
+                                                  })(); </script>"]);
+    $this->dispatch('/help/cookies', true);
+  }
+
+
+  /** @test */
+  public function pageShouldNotWarnAboutGoogleAnalytic() {
+    $this->assertXPathContentContains('//p', 'utilise les services de Google Analytics');
+  }
+}
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php
index 46202796e82..36d8996037f 100644
--- a/tests/application/modules/opac/controllers/IndexControllerTest.php
+++ b/tests/application/modules/opac/controllers/IndexControllerTest.php
@@ -320,6 +320,7 @@ abstract class IndexControllerCnilTrackingTestCase extends AbstractControllerTes
   protected $_expected_message = 'showNotification({"message":"En poursuivant votre navigation sur ce site, vous acceptez l\'utilisation de cookies.","autoClose":false';
   protected $_cookie_jar;
 
+
   public function setUp() {
     parent::setUp();
 
@@ -338,6 +339,7 @@ abstract class IndexControllerCnilTrackingTestCase extends AbstractControllerTes
                              ->answers(null));
   }
 
+
   public function tearDown() {
     Class_Cnil::setCookieJar(null);
     Class_Cnil::setTimeSource(null);
@@ -350,6 +352,7 @@ abstract class IndexControllerCnilTrackingTestCase extends AbstractControllerTes
 class IndexControllerCnilTrackingFirstVisitTest
   extends IndexControllerCnilTrackingTestCase {
 
+
   public function setUp() {
     parent::setUp();
 
@@ -359,7 +362,7 @@ class IndexControllerCnilTrackingFirstVisitTest
 
   /** @test */
   public function shouldDisplayCnilMessage() {
-    $this->assertXPathContentContains('//script', $this->_expected_message);
+    $this->assertXPath('//script[contains(text(), "En poursuivant votre navigation")][contains(text(), "\/help\/cookies")][contains(text(), "En savoir plus")]', $this->_response->getBody());
   }
 
 
@@ -374,6 +377,7 @@ class IndexControllerCnilTrackingFirstVisitTest
 class IndexControllerCnilTrackingFirstVisitWithAdminVarDisabledTest
   extends IndexControllerCnilTrackingTestCase {
 
+
   public function setUp() {
     parent::setUp();
 
@@ -394,6 +398,7 @@ class IndexControllerCnilTrackingFirstVisitWithAdminVarDisabledTest
 class IndexControllerCnilTrackingSecondVisitTest
   extends IndexControllerCnilTrackingTestCase {
 
+
   public function setUp() {
     parent::setUp();
     $this->dispatch('/', true);
@@ -402,6 +407,7 @@ class IndexControllerCnilTrackingSecondVisitTest
     $this->dispatch('/', true);
   }
 
+
   /** @test */
   public function shouldNotDisplayCnilMessageOf() {
     $this->assertNotXPathContentContains('//script', $this->_expected_message);
@@ -413,6 +419,7 @@ class IndexControllerCnilTrackingSecondVisitTest
 class IndexControllerCnilTrackingExistingCookieVisitTest
   extends IndexControllerCnilTrackingTestCase {
 
+
   /** @test */
   public function shouldNotDisplayCnilMessage() {
     $_COOKIE['cnil' . md5(BASE_URL)] = 1;
-- 
GitLab