From 6ef042c4a5f21aa2856c2a08168979d173dfd753 Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@git-test.afi-sa.fr>
Date: Wed, 5 Jun 2013 10:11:27 +0000
Subject: [PATCH] Liens Vodeclic, CVS et Numilog statiques

---
 .gitattributes                                |  3 +
 .../opac/controllers/ModulesController.php    | 55 +++++++++++
 library/Class/CVSLink.php                     |  4 +
 library/Class/NumilogLink.php                 |  5 +
 library/Class/Systeme/ModulesMenu/CVS.php     |  7 +-
 library/Class/Systeme/ModulesMenu/Numilog.php |  7 +-
 .../Class/Systeme/ModulesMenu/Vodeclic.php    |  7 +-
 library/Class/VodeclicLink.php                |  4 +
 .../controllers/ModulesControllerTest.php     | 97 +++++++++++++++++++
 tests/library/Class/NumilogLinkTest.php       | 71 ++++++++++++++
 .../library/Class/Systeme/ModulesMenuTest.php | 68 ++++++++-----
 11 files changed, 299 insertions(+), 29 deletions(-)
 create mode 100644 application/modules/opac/controllers/ModulesController.php
 create mode 100644 tests/application/modules/opac/controllers/ModulesControllerTest.php
 create mode 100644 tests/library/Class/NumilogLinkTest.php

diff --git a/.gitattributes b/.gitattributes
index 67959683a61..4be8e222e14 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -683,6 +683,7 @@ application/modules/opac/controllers/EtagereController.php -text
 application/modules/opac/controllers/FormulaireController.php -text
 application/modules/opac/controllers/IndexController.php -text
 application/modules/opac/controllers/JavaController.php -text
+application/modules/opac/controllers/ModulesController.php -text
 application/modules/opac/controllers/NoticeajaxController.php -text
 application/modules/opac/controllers/OaiController.php -text
 application/modules/opac/controllers/PanierController.php -text
@@ -5701,6 +5702,7 @@ tests/application/modules/opac/controllers/FormulaireControllerTest.php -text
 tests/application/modules/opac/controllers/IndexControllerTest.php -text
 tests/application/modules/opac/controllers/IndexControllerTranslationTest.php -text
 tests/application/modules/opac/controllers/JavaControllerTest.php -text
+tests/application/modules/opac/controllers/ModulesControllerTest.php -text
 tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php -text
 tests/application/modules/opac/controllers/OAI-PMH.xsd -text
 tests/application/modules/opac/controllers/OAIControllerGetRecordTest.php -text
@@ -5812,6 +5814,7 @@ tests/library/Class/Notice/simpledc20021212.xsd -text
 tests/library/Class/NoticeHtmlTest.php -text
 tests/library/Class/NoticeOAITest.php -text
 tests/library/Class/NoticeTest.php -text
+tests/library/Class/NumilogLinkTest.php -text
 tests/library/Class/OpdsCatalogTest.php -text
 tests/library/Class/PanierNoticeTest.php -text
 tests/library/Class/ProfilI18nStringExtractorTest.php -text
diff --git a/application/modules/opac/controllers/ModulesController.php b/application/modules/opac/controllers/ModulesController.php
new file mode 100644
index 00000000000..23e8a338de1
--- /dev/null
+++ b/application/modules/opac/controllers/ModulesController.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+//////////////////////////////////////////////////////////////////////////////////////////
+// OPAC3 - Controleur UTILISATEURS
+//
+//@TODO@ :- faire tri sur les entetes de colonnes
+//				-	Faire une recherche par noms
+//////////////////////////////////////////////////////////////////////////////////////////
+
+class ModulesController extends Zend_Controller_Action {
+	private $user;
+	function init() {
+				$this->user = ZendAfi_Auth::getInstance()->getIdentity();
+	}
+
+
+
+
+	public function cvsAction() {
+		$cvs = new Class_Systeme_ModulesMenu_CVS();
+		$this->_redirect($cvs->getDynamiqueUrl());
+		
+	}
+
+	public function numilogAction() {
+		$numilog = new Class_Systeme_ModulesMenu_Numilog();
+		$this->_redirect($numilog->getDynamiqueUrl());
+		
+	}
+
+	public function vodeclicAction() {
+		$vodeclic = new Class_Systeme_ModulesMenu_Vodeclic();
+		$this->_redirect($vodeclic->getDynamiqueUrl());
+		
+	}
+
+}
\ No newline at end of file
diff --git a/library/Class/CVSLink.php b/library/Class/CVSLink.php
index 5815c895096..cd52df13f2f 100644
--- a/library/Class/CVSLink.php
+++ b/library/Class/CVSLink.php
@@ -35,6 +35,10 @@ class Class_CVSLink extends Class_WebService_Abstract {
 		$this->_user = $user;
 	}
 
+	public static function staticLink() {
+		return BASE_URL.'/modules/cvs';
+	}
+
 
 	public function baseUrl() {
 		return 'http://stream.cvs-mediatheques.com/api/partners.php';
diff --git a/library/Class/NumilogLink.php b/library/Class/NumilogLink.php
index 298b4776080..5d099b932ab 100644
--- a/library/Class/NumilogLink.php
+++ b/library/Class/NumilogLink.php
@@ -36,6 +36,11 @@ class Class_NumilogLink extends Class_WebService_Abstract {
 	}
 
 
+	public static function staticLink() {
+		return 'opac/modules/numilog';
+	}
+
+
 	public function getBaseUrl() {
 		return Class_AdminVar::get('NUMILOG_URL');
 	}
diff --git a/library/Class/Systeme/ModulesMenu/CVS.php b/library/Class/Systeme/ModulesMenu/CVS.php
index 1ad7e377da7..970da04537d 100644
--- a/library/Class/Systeme/ModulesMenu/CVS.php
+++ b/library/Class/Systeme/ModulesMenu/CVS.php
@@ -38,11 +38,16 @@ class Class_Systeme_ModulesMenu_CVS extends Class_Systeme_ModulesMenu_Null {
 
 
 	public function getUrl($preferences=[]) {
+		return Class_CVSLink::staticLink();
+	}
+
+
+	public function getDynamiqueUrl() {
 		return ($user = Class_Users::getIdentity())
 		   ? $this->getCVSUrlForUser($user)
 		   : BASE_URL.'/auth/login';
-	}
 
+	}
 
 	public function shouldOpenInNewWindow($preferences) {
 		return null != Class_Users::getIdentity();
diff --git a/library/Class/Systeme/ModulesMenu/Numilog.php b/library/Class/Systeme/ModulesMenu/Numilog.php
index 64e31b8d8a9..ba52605fcb0 100644
--- a/library/Class/Systeme/ModulesMenu/Numilog.php
+++ b/library/Class/Systeme/ModulesMenu/Numilog.php
@@ -36,12 +36,15 @@ class Class_Systeme_ModulesMenu_Numilog extends Class_Systeme_ModulesMenu_Null {
 	}
 
 	public function getUrl($preferences=[]) {
-		return ($user = Class_Users::getIdentity())
+		return BASE_URL.'/modules/numilog';
+	}
+
+	public function getDynamiqueUrl() {
+	return ($user = Class_Users::getIdentity())
 			? $this->getNumilogUrlForUser($user)
 			: Class_AdminVar::get('NUMILOG_URL');
 	}
 
-
 	public function shouldOpenInNewWindow($preferences) {
 		return null != Class_Users::getIdentity();
 	}
diff --git a/library/Class/Systeme/ModulesMenu/Vodeclic.php b/library/Class/Systeme/ModulesMenu/Vodeclic.php
index f5448679e21..ae6d21d7e65 100644
--- a/library/Class/Systeme/ModulesMenu/Vodeclic.php
+++ b/library/Class/Systeme/ModulesMenu/Vodeclic.php
@@ -37,12 +37,15 @@ class Class_Systeme_ModulesMenu_Vodeclic extends Class_Systeme_ModulesMenu_Null
 	}
 
 
-	public function getUrl($preferences=[]) {
+	public function getDynamiqueUrl() {
 		return ($user = Class_Users::getIdentity())
 		   ? $this->getVodeclicUrlForUser($user)
 		   : BASE_URL . '/auth/login';
 	}
-
+	
+	public function getUrl($preferences=[]) {
+		return Class_VodeclicLink::staticUrl();
+	}
 
 	public function shouldOpenInNewWindow($preferences) {
 		return null != Class_Users::getIdentity();
diff --git a/library/Class/VodeclicLink.php b/library/Class/VodeclicLink.php
index 1ab424af55b..b4d7300cfbe 100644
--- a/library/Class/VodeclicLink.php
+++ b/library/Class/VodeclicLink.php
@@ -36,6 +36,10 @@ class Class_VodeclicLink {
 		return "https://biblio.vodeclic.com/auth/biblio/sso";
 	}
 
+	public static function staticUrl() {
+		return BASE_URL.'/modules/vodeclic';
+	}
+
 
 	public function url() {
 		$hash = Class_Hash::sha256WithKey(Class_AdminVar::get('VODECLIC_KEY'));
diff --git a/tests/application/modules/opac/controllers/ModulesControllerTest.php b/tests/application/modules/opac/controllers/ModulesControllerTest.php
new file mode 100644
index 00000000000..4c2f140acc7
--- /dev/null
+++ b/tests/application/modules/opac/controllers/ModulesControllerTest.php
@@ -0,0 +1,97 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+require_once 'AbstractControllerTestCase.php';
+
+class ModulesControllerCVSTest extends AbstractControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+
+
+		Class_AdminVar::newInstanceWithId('VODECLIC_KEY', ['valeur' => 1234]);
+		Class_AdminVar::newInstanceWithId('VODECLIC_ID', ['valeur' => 'afi']);
+		Class_AdminVar::newInstanceWithId('VODECLIC_BIB_ID', ['valeur' => '12']);
+		Class_AdminVar::newInstanceWithId('MULTIMEDIA_KEY', ['valeur' => 'zork']);
+		Class_AdminVar::newInstanceWithId('CVS_BMKEY',['valeur' => '22222']);
+		Class_AdminVar::newInstanceWithId('CVS_BMID',['valeur' => '22222']);
+		Class_AdminVar::newInstanceWithId('CVS_SOURCENAME',['valeur' => '22222']);
+		Class_AdminVar::newInstanceWithId('CVS_SOURCEID',['valeur' => '22222']);
+		Class_AdminVar::newInstanceWithId('CVS_SOURCEKEY',['valeur' => '22222']);
+		Class_AdminVar::newInstanceWithId('CVS_SOURCEPASSWORD',['valeur' => '22222']);
+	}
+
+
+
+
+	/** @test */
+	public function cvsUrlWithoutUserShouldBeLoginPage() {
+		ZendAfi_Auth::getInstance()->clearIdentity();
+		$this->dispatch('/opac/modules/cvs');
+		$this->assertRedirectTo(BASE_URL.'/auth/login');
+	
+	}
+
+
+}
+
+
+
+class ModulesControllerVodeclicTest extends AbstractControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+		Class_AdminVar::newInstanceWithId('VODECLIC_KEY', ['valeur' => 1234]);
+		Class_AdminVar::newInstanceWithId('VODECLIC_ID', ['valeur' => 'afi']);
+		Class_AdminVar::newInstanceWithId('VODECLIC_BIB_ID', ['valeur' => '12']);
+	}
+
+
+
+
+	/** @test */
+	public function vodeclicUrlWithoutUserShouldBeLoginPage() {
+		ZendAfi_Auth::getInstance()->clearIdentity();
+		$this->dispatch('/opac/modules/vodeclic');
+		$this->assertRedirectTo(BASE_URL.'/auth/login');
+	
+	}
+
+
+}
+
+
+class ModulesControllerNumilogTest extends AbstractControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		Class_AdminVar::newInstanceWithId('NUMILOG_URL',['valeur' => 'http://numilogurl/action']);
+	}
+
+
+	/** @test */
+	public function numilogUrlWithoutUserShouldBeLoginPage() {
+		ZendAfi_Auth::getInstance()->clearIdentity();
+		$this->dispatch('/opac/modules/numilog');
+		$this->assertRedirectTo('http://numilogurl/action');
+	
+	}
+
+
+
+}
\ No newline at end of file
diff --git a/tests/library/Class/NumilogLinkTest.php b/tests/library/Class/NumilogLinkTest.php
new file mode 100644
index 00000000000..1065c25948c
--- /dev/null
+++ b/tests/library/Class/NumilogLinkTest.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+abstract class NumilogLinkTestCase extends Storm_Test_ModelTestCase {
+	public function setUp() {
+		parent::setUp();
+		Class_AdminVar::newInstanceWithId('NUMILOG_URL',['valeur' => 'http://urlnumilog/action']);
+
+	}
+}
+
+
+
+ class NumilogLinkWithAbonTest extends NumilogLinkTestCase {
+	protected 
+		$_http_client,
+		$_jerry;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->_jerry = Class_Users::getLoader()
+			->newInstanceWithId(4)
+			->setIdabon(34)
+			->setLogin(34)
+			->setPrenom('Jerry')
+			->setNom('Khan')
+			->setMail('feu@essence.fr')
+			->setDateFin('2023-09-02');
+
+		$this->_numilog = Class_NumilogLink::forUser($this->_jerry);
+
+		$this->_http_client = Storm_Test_ObjectWrapper::mock();
+
+		Class_NumilogLink::setDefaultHttpClient($this->_http_client);
+
+	}
+
+
+	/** @test */
+	public function urlForJerryShouldBeNumilogSSO() {
+		$this->assertEquals('http://urlnumilog/action',
+												$this->_numilog->getBaseUrl());
+	}
+
+  /** @test */
+	public function numilogUrlShouldReturnUrlWithTicket() {
+		$this->assertEquals('http://urlnumilog/action?ticket='.md5( Zend_Session::getId()), 
+												$this->_numilog->url());
+	}
+
+}
+?>
\ No newline at end of file
diff --git a/tests/library/Class/Systeme/ModulesMenuTest.php b/tests/library/Class/Systeme/ModulesMenuTest.php
index 65dfbf99e7b..f24aa0e6778 100644
--- a/tests/library/Class/Systeme/ModulesMenuTest.php
+++ b/tests/library/Class/Systeme/ModulesMenuTest.php
@@ -33,7 +33,7 @@ class ModulesMenuTest extends Storm_Test_ModelTestCase {
 		Class_AdminVar::newInstanceWithId('CVS_SOURCEID',['valeur' => '22222']);
 		Class_AdminVar::newInstanceWithId('CVS_SOURCEKEY',['valeur' => '22222']);
 		Class_AdminVar::newInstanceWithId('CVS_SOURCEPASSWORD',['valeur' => '22222']);
-
+		Class_AdminVar::newInstanceWithId('NUMILOG_URL',['valeur' => 'http://numilogurl/action']);
 
 		$this->module_menu = new Class_Systeme_ModulesMenu();
 	}
@@ -56,19 +56,21 @@ class ModulesMenuTest extends Storm_Test_ModelTestCase {
 	}
 
 
+
 	/** @test */
-	public function vodeclicUrlWithoutUserShouldBeLoginPage() {
+	public function cvsUrlShouldBeStaticPage() {
 		ZendAfi_Auth::getInstance()->clearIdentity();
-		$this->assertEquals(array('url' => BASE_URL.'/auth/login', 'target' => ''), 
-												$this->module_menu->getUrl('VODECLIC', array()));
+		$this->assertEquals(['url' => BASE_URL.'/modules/cvs', 'target' => ''], 
+												$this->module_menu->getUrl('CVS', array()));
 	}
 
 
+
 	/** @test */
-	public function cvsUrlWithoutUserShouldBeLoginPage() {
+	public function numilogUrlShouldBeStaticPage() {
 		ZendAfi_Auth::getInstance()->clearIdentity();
-		$this->assertEquals(array('url' => BASE_URL.'/auth/login', 'target' => ''), 
-												$this->module_menu->getUrl('CVS', array()));
+		$this->assertEquals(['url' => BASE_URL.'/modules/numilog', 'target' => ''], 
+												$this->module_menu->getUrl('NUMILOG', array()));
 	}
 
 
@@ -95,48 +97,66 @@ class ModulesMenuTest extends Storm_Test_ModelTestCase {
 			->beAbonneSIGB()
 			->setDateDebut('1999-02-10')
 			->setDateFin('2025-09-12');
+		$vodeclic= new Class_Systeme_ModulesMenu_Vodeclic();
 		
-		$menu_url = $this->module_menu->getUrl('VODECLIC', array());
-		$this->assertContains('vodeclic', $menu_url['url']);
-		$this->assertEquals('_blank', $menu_url['target']);
+		$url = $vodeclic->getDynamiqueUrl();
+		$this->assertContains('vodeclic', $url);
+
 	}
 
 
 	/** @test */
 	public function vodeclicUrlWithAbonnementInvalidShouldBeJSAlertAbonnementInvalid() {
 		$this->_logUserGaston();
+		$vodeclic= new Class_Systeme_ModulesMenu_Vodeclic();
+		
+		$url = $vodeclic->getDynamiqueUrl();
+
+		$this->assertContains('javascript:alert(\\\'Votre abonnement est terminé\\\')', $url);
+
+	}
+
+
+
+ 
+/** @test */
+	public function cvsUrlWithUserNotValidShouldReturnJsAlert() {
+		$this->_logUserGaston()
+			->beAbonneSIGB()
+			->setDateDebut('1999-02-10')
+			->setDateFin('2025-09-12');
+		$cvs = new Class_Systeme_ModulesMenu_CVS();
 
-		$menu_url = $this->module_menu->getUrl('VODECLIC', array());
-		$this->assertContains('javascript:alert(\\\'Votre abonnement est terminé\\\')', $menu_url['url']);
-		$this->assertEquals('_blank', $menu_url['target']);
+
+		$menu_url = $cvs->getDynamiqueUrl();
+		$this->assertContains('javascript:alert("Merci de contacter la médiathèque pour obtenir un accès.")', $menu_url);
 	}
 
 
 	/** @test */
 	public function cvsUrlWithAbonnementInvalidShouldBeJSAlertAbonnementInvalid() {
 		$this->_logUserGaston();
+		$cvs = new Class_Systeme_ModulesMenu_CVS();
+		$menu_url = $cvs->getDynamiqueUrl();
+		$this->assertContains('javascript:alert("Votre abonnement est terminé")', $menu_url);
 
-		$menu_url = $this->module_menu->getUrl('CVS', array());
-		$this->assertContains('javascript:alert("Votre abonnement est terminé")', $menu_url['url']);
-		$this->assertEquals('_blank', $menu_url['target']);
 	}
 
 
 
 	/** @test */
-	public function cvsUrlWithUserNotValidShouldReturnJsAlert() {
-		$this->_logUserGaston()
-			->beAbonneSIGB()
-			->setDateDebut('1999-02-10')
-			->setDateFin('2025-09-12');
-		
-		$menu_url = $this->module_menu->getUrl('CVS', array());
-		$this->assertContains('javascript:alert("Merci de contacter la médiathèque pour obtenir un accès.")', $menu_url['url']);
+	public function numilogUrlWithAbonnementInvalidShouldReturnDefaultNumilogUrl() {
+		$this->_logUserGaston();
+		$numilog = new Class_Systeme_ModulesMenu_Numilog();
+		$url = $numilog->getDynamiqueUrl();
+		$this->assertContains('http://numilogurl/action', $url);
+
 	}
 
 
 
 
+
 	/** @test */
 	public function reserverPosteUrlShouldBeAbonneReservations() {
 		$this->assertEquals(['url' => BASE_URL.'/abonne/multimedia-hold-location', 'target' => ''],
-- 
GitLab