From 7a65b54debfb0573fee133d02aa2b90d098b6ea7 Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Tue, 24 Feb 2015 12:05:24 +0100
Subject: [PATCH] rel #21462 : use default values when retreiving profil
 cfg_notice

---
 .../controllers/ModulesnoticeController.php   |  23 ++--
 library/Class/Exemplaire.php                  |   8 +-
 library/Class/Profil.php                      |   6 +-
 library/Class/Systeme/ModulesNotice.php       |  35 +++---
 .../NoticeAjaxControllerPergameTest.php       | 114 ++++++++++++++++++
 5 files changed, 144 insertions(+), 42 deletions(-)
 create mode 100644 tests/application/modules/opac/controllers/NoticeAjaxControllerPergameTest.php

diff --git a/application/modules/admin/controllers/ModulesnoticeController.php b/application/modules/admin/controllers/ModulesnoticeController.php
index 723ca18efd4..a3729d1cfe2 100644
--- a/application/modules/admin/controllers/ModulesnoticeController.php
+++ b/application/modules/admin/controllers/ModulesnoticeController.php
@@ -46,7 +46,6 @@ class Admin_ModulesnoticeController extends ZendAfi_Controller_Action {
 
 		$cfg = $profil->getCfgNoticeAsArray();
 		$preferences=$cfg[$this->type_module];
-		if(!$preferences) $preferences=$module->getValeursParDefaut($this->type_module);
 
 		// Variables de vue
 		$this->view->titre_module=$def_module["libelle"];
@@ -61,27 +60,19 @@ class Admin_ModulesnoticeController extends ZendAfi_Controller_Action {
 			Zend_Layout::startMvc();
 	}
 
-//------------------------------------------------------------------------------------------------------
-// Proprietés : EXEMPLAIRES
-//------------------------------------------------------------------------------------------------------
-	function exemplairesAction(){
+
+	function exemplairesAction() {
 		$this->view->titre = $this->view->_('Propriété du bloc des exemplaires');
 
-		// Retour du formulaire
-		if ($this->_request->isPost())
-		{
+		if ($this->_request->isPost()) {
 			$enreg=$_POST;
-			if($enreg["grouper"]==0)
-			{
-				$enreg["section"]=0;
-				$enreg["emplacement"]=0;
-				$enreg["annexe"]=0;
+			if (!$enreg['grouper']) {
+				$enreg['section'] = 0;
+				$enreg['emplacement'] = 0;
+				$enreg['annexe'] = 0;
 			}
 			$this->updateEtRetour($enreg);
 		}
-
-		if (!array_isset("en_pret", $this->view->preferences) || !trim($this->view->preferences["en_pret"]))
-			$this->view->preferences["en_pret"]="emprunté";
 	}
 
 //------------------------------------------------------------------------------------------------------
diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php
index 4d6e43ad537..838ce243519 100644
--- a/library/Class/Exemplaire.php
+++ b/library/Class/Exemplaire.php
@@ -55,10 +55,10 @@ class Class_Exemplaire extends Storm_Model_Abstract {
 
 
 	public function getPret() {
-		return Class_Pret::getLoader()->findFirstBy(['id_site' => $this->getIdBib(),
-																								 'id_notice_origine' => $this->getIdOrigine(),
-																								 'code_barres' => $this->getCodeBarres(),
-																								 'EN_COURS' => 1]);
+		return Class_Pret::findFirstBy(['id_site' => $this->getIdBib(),
+																		'id_notice_origine' => $this->getIdOrigine(),
+																		'code_barres' => $this->getCodeBarres(),
+																		'EN_COURS' => 1]);
 	}
 
 
diff --git a/library/Class/Profil.php b/library/Class/Profil.php
index c854c5c7b57..349e0cfd68d 100644
--- a/library/Class/Profil.php
+++ b/library/Class/Profil.php
@@ -812,7 +812,11 @@ class Class_Profil extends Storm_Model_Abstract {
 	 * @return array
 	 */
 	public function getCfgNoticeAsArray() {
-		return $this->_getCfgAsArrayNamed('Notice');
+		$cfg = $this->_getCfgAsArrayNamed('Notice');
+		$module = new Class_Systeme_ModulesNotice();
+		$cfg['exemplaires'] = array_merge($module->getValeursParDefaut('exemplaires'), $cfg['exemplaires']);
+
+		return $cfg;
 	}
 
 
diff --git a/library/Class/Systeme/ModulesNotice.php b/library/Class/Systeme/ModulesNotice.php
index fedee0b8277..822649014c4 100644
--- a/library/Class/Systeme/ModulesNotice.php
+++ b/library/Class/Systeme/ModulesNotice.php
@@ -66,30 +66,23 @@ class Class_Systeme_ModulesNotice
 		}
 	}
 
-//------------------------------------------------------------------------------------------------------
-// Valeurs par defaut module bande-annonce
-//------------------------------------------------------------------------------------------------------	
-	private function getDefautBandeAnnonce()
-	{
-		$ret["target"]="1";								// Ouvrir dans un nouvel onglet ou pas
-		$ret["url"]="http://google.fr";   // Test de proprietes
+
+	private function getDefautBandeAnnonce() {
+		$ret['target'] = '1';								// Ouvrir dans un nouvel onglet ou pas
+		$ret['url'] = 'http://google.fr';   // Test de proprietes
 		return $ret;
 	}
 
-//------------------------------------------------------------------------------------------------------
-// Valeurs par defaut module : Exemplaires
-//------------------------------------------------------------------------------------------------------
-	private function getDefautExemplaires()
-	{
-		$ret["grouper"]="0";							// Groupage
-		$ret["bib"]="1";									// Afficher la bibliotheque
-		$ret["section"]="0";							// Afficher la section
-		$ret["emplacement"]="0";					// Afficher l'emplacement
-		$ret["localisation"]="1";					// Afficher lien vers la localisation sur le plan
-		$ret["plan"]="1";									// Afficher lien vers google maps
-		$ret["resa"]="1";									// Afficher le lien de réservation
-		$ret["dispo"]="1";								// Afficher la disponibilité
 
-		return $ret;
+	private function getDefautExemplaires() {
+		return ['grouper' => '0',							// Groupage
+						'bib' => '1',									// Afficher la bibliotheque
+						'section' => '0',							// Afficher la section
+						'emplacement' => '0',					// Afficher l'emplacement
+						'localisation' => '1',				// Afficher lien vers la localisation sur le plan
+						'plan' => '1',								// Afficher lien vers google maps
+						'resa' => '1',								// Afficher le lien de réservation
+						'en_pret' => 'emprunté',      // Libéllé des exemplaires empruntés
+						'dispo' => '1'];							// Afficher la disponibilité
 	}
 }
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerPergameTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerPergameTest.php
new file mode 100644
index 00000000000..a442f5855e1
--- /dev/null
+++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerPergameTest.php
@@ -0,0 +1,114 @@
+<?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
+ */
+require_once 'AbstractControllerTestCase.php';
+
+
+/** @see http://forge.afi-sa.fr/issues/21462 */
+abstract class NoticeAjaxControllerPergameItemTestCase extends AbstractControllerTestCase {
+	protected $_exemplaire;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->fixture('Class_IntBib', ['id' => 1,
+																		'nom' => 'Site principal',
+																		'nom_court' => 'limours',
+																		'sigb' => Class_IntBib::COM_PERGAME,
+																		'comm_sigb' => Class_IntBib::COM_PERGAME,
+																		'comm_params' => 'a:3:{s:26:"Autoriser_docs_disponibles";s:0:"";s:13:"Max_par_carte";s:1:"4";s:16:"Max_par_document";s:3:"100";}']);
+
+		$this->fixture('Class_Notice', ['id' => 23,
+																		'cle_oeuvre' => 'DDD']);
+
+		$this->fixture('Class_Exemplaire', ['id' => 732494,
+																				'id_notice' => 23,
+																				'id_bib' => 1,
+																				'code_barres' => '0213689147',
+																				'cote' => 'EA WAD',
+																				'genre' => 8,
+																				'documentaire' => 0,
+																				'section' => 3,
+																				'activite' => 'En rayon',
+																				'emplacement' => 0,
+																				'annexe' => 1,
+																				'date_nouveaute' => '0000-00-00',
+																				'id_origine' => '00013313',
+																				'id_int_bib' => 1,
+																				'is_available' => 1]);
+
+		$this->fixture('Class_Pret', ['id' => 98216,
+																	'id_site' => 1,
+																	'pergame' => 291392,
+																	'id_notice_origine' => '13313',
+																	'en_cours' => 1,
+																	'date_pret' => '2015-02-17',
+																	'date_retour' => '2015-03-31',
+																	'code_barres' => '0213689147']);
+	}
+
+}
+
+
+
+class NoticeAjaxControllerPergameItemNoDefaultLabelTest
+	extends NoticeAjaxControllerPergameItemTestCase {
+	public function setUp() {
+		parent::setUp();
+				$cfg = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray();
+		$cfg['exemplaires']['grouper'] = 1;
+		unset($cfg['exemplaires']['en_pret']);
+		Class_Profil::getCurrentProfil()->setCfgNotice($cfg);
+
+		$this->dispatch('/noticeajax/exemplaires/id_notice/23', true);
+	}
+
+
+	/** @test */
+	public function availabilityLabelShouldBeEmprunte() {
+		$this->assertXPathContentContains('//td[contains(@class, "dispo")]',
+																			'emprunt',
+																			$this->_response->getBody());
+	}
+}
+
+
+
+
+class NoticeAjaxControllerPergameItemLabelConfiguredTest
+	extends NoticeAjaxControllerPergameItemTestCase {
+	public function setUp() {
+		parent::setUp();
+		$cfg = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray();
+		$cfg['exemplaires']['grouper'] = 1;
+		$cfg['exemplaires']['en_pret'] = 'En pret';
+		Class_Profil::getCurrentProfil()->setCfgNotice($cfg);
+
+		$this->dispatch('/noticeajax/exemplaires/id_notice/23', true);
+	}
+
+
+	/** @test */
+	public function availabilityLabelShouldBeEnPret() {
+		$this->assertXPathContentContains('//td[contains(@class, "dispo")]',
+																			'En pret',
+																			$this->_response->getBody());
+	}
+}
-- 
GitLab