From c9570ee3ad18cbebc253e70958a8d0c7e3b1d077 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Tue, 21 Aug 2012 15:16:42 +0000
Subject: [PATCH] CommSigb: fin refacto

---
 library/Class/CommSigb.php                    |  58 ----------
 library/Class/NoticeHtml.php                  |   5 +-
 library/Class/Users.php                       |  17 +--
 .../admin/controllers/UsersControllerTest.php |   2 +-
 .../AbonneControllerNewslettersTest.php       |   2 +-
 .../opac/controllers/AbonneVSmartTest.php     |   2 +-
 .../controllers/AbonneControllerTest.php      |   4 +-
 .../controllers/IndexControllerTest.php       |   2 +-
 tests/bootstrap.php                           |   3 +
 tests/library/Class/CommSigbTest.php          | 109 ++++--------------
 tests/library/Class/NoticeHtmlTest.php        |   2 +-
 11 files changed, 38 insertions(+), 168 deletions(-)

diff --git a/library/Class/CommSigb.php b/library/Class/CommSigb.php
index 566d641b3b2..7079f6bb69b 100644
--- a/library/Class/CommSigb.php
+++ b/library/Class/CommSigb.php
@@ -19,31 +19,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
  */
 class Class_CommSigb {
-	const COM_PERGAME = 1;
-	const COM_OPSYS = 2;
-	const COM_VSMART = 4;
-	const COM_KOHA = 5;
-	const COM_CARTHAME = 6;
-	const COM_NANOOK = 7;
-	const COM_ORPHEE = 8;
-	const COM_MICROBIB = 9;
-	const COM_BIBLIXNET = 10;
-
-
-
-	private $COM_CLASSES = array(self::COM_PERGAME => 'Class_WebService_SIGB_Pergame',
-															 self::COM_OPSYS => 'Class_WebService_SIGB_Opsys',
-															 self::COM_VSMART => 'Class_WebService_SIGB_VSmart',
-															 self::COM_KOHA => 'Class_WebService_SIGB_Koha',
-															 self::COM_CARTHAME => 'Class_WebService_SIGB_Carthame',
-															 self::COM_NANOOK => 'Class_WebService_SIGB_Nanook',
-															 self::COM_ORPHEE => 'Class_WebService_SIGB_Orphee',
-															 self::COM_MICROBIB => 'Class_WebService_SIGB_Microbib',
-															 self::COM_BIBLIXNET => 'Class_WebService_SIGB_BiblixNet');
-
 	protected static $_instance;
 
-	private $mode_comm;								// memo de modes de comm pour les bibs
 	private $msg_erreur_comm;					// Message d'erreur pour la connexion au service de communication
 	private $_translate;
 
@@ -66,16 +43,6 @@ class Class_CommSigb {
 	}
 
 
-	/**
-	 * @param int $id_bib
-	 * @return int
-	 */
-	public function getTypeComm($id_bib) {
-		$comm = $this->getModeComm($id_bib);
-		return $comm['type'];
-	}
-
-
 	/**
 	 * @param array $exemplaires_to_check
 	 * @return array
@@ -223,29 +190,4 @@ class Class_CommSigb {
 
 		return $closure($user, $sigb);
 	}
-
-
-	/**
-	 * @param int $id_bib
-	 * @return array
-	 */
-	public function getModeComm($id_bib){
-		$ret = ['type' => 0, 'id_bib' => 0];
-		if ($bib = Class_IntBib::find($id_bib))
-			$ret = $bib->getModeComm();
-
-		$this->mode_comm[$id_bib] = $ret;
-		return $ret;
-	}
-
-
-	/**
-	 * @param array $mode_comm
-	 * @return Class_WebService_SIGB_AbstractService
-	 */
-	private function getSIGBComm($mode_comm) {
-		if ($bib = Class_IntBib::find($mode_comm['id_bib']))
-			return $bib->getSIGBComm();
-		return false;
-	}
 }
\ No newline at end of file
diff --git a/library/Class/NoticeHtml.php b/library/Class/NoticeHtml.php
index c160e4019c9..8e20ae822bf 100644
--- a/library/Class/NoticeHtml.php
+++ b/library/Class/NoticeHtml.php
@@ -898,13 +898,11 @@ class NoticeReservationRenderer {
 	const HOLD_IMG = 'resa.gif';
 
 	protected $_bib;
-	protected $_commClass;
 	protected $_holdLabel;
 	
 	public static function newWith($bib, $commClass, $holdLabel) {
 		$instance = new NoticeReservationRenderer();
 		$instance->_bib = $bib;
-		$instance->_commClass = $commClass;
 		$instance->_holdLabel = $holdLabel;
 		return $instance;
 	}
@@ -921,8 +919,7 @@ class NoticeReservationRenderer {
 		if (1 == $this->_bib['INTERDIRE_RESA'])
 			return $html .= '&nbsp;</td>';
 
-		$type_comm = (null != $this->_commClass) ? $this->_commClass->getTypeComm($ex['id_bib']) : '';
-		
+		$type_comm = ($int_bib = Class_IntBib::find($ex['id_bib'])) ? $int_bib->getCommSigb() : 0;
 		if (!$type_comm)
 			return $this->_renderStandardOn($ex, $html);
 
diff --git a/library/Class/Users.php b/library/Class/Users.php
index b8d7ddfb7b3..4118e725477 100644
--- a/library/Class/Users.php
+++ b/library/Class/Users.php
@@ -807,22 +807,15 @@ class Class_Users extends Storm_Model_Abstract {
 		if (isset($this->_fiche_sigb))
 			return $this->_fiche_sigb;
 
-		$cls_comm = new Class_CommSigb();
-		$type_comm = $cls_comm->getTypeComm($user->ID_SITE);
-
-		if ($type_comm) {
-			if ($user->IDABON) {
-				$ret=$cls_comm->ficheAbonne($user);
-			} else {
-				$ret["message"] = $this->_translate->_("Vous devez vous connecter en tant qu'abonné de la bibliothèque pour obtenir plus d'informations.");
-			}
-		}
+		if (!$user->getIdabon())
+			$ret = ["message" => $this->_translate->_("Vous devez vous connecter en tant qu'abonné de la bibliothèque pour obtenir plus d'informations.")];
+		else
+			$ret = (new Class_CommSigb())->ficheAbonne($user);
 
 		if (!isset($ret['fiche']))
 			$ret['fiche'] = Class_WebService_SIGB_Emprunteur::nullInstance();
 
 		$ret["nom_aff"] = $this->getNomAff($user->ID_USER, true);
-		$ret["type_comm"] = $type_comm;
 
 		$this->_fiche_sigb = $ret;
 		return $ret;
@@ -861,7 +854,7 @@ class Class_Users extends Storm_Model_Abstract {
 		if (!isset($this->_fiche_sigb)) return;
 
 		$fiche = $this->_fiche_sigb;
-		if ($fiche['type_comm'] != Class_CommSigb::COM_OPSYS)
+		if ($fiche['type_comm'] != Class_IntBib::COM_OPSYS)
 			return;
 
 		$emprunteur = $fiche['fiche'];
diff --git a/tests/application/modules/admin/controllers/UsersControllerTest.php b/tests/application/modules/admin/controllers/UsersControllerTest.php
index 868fc779d0f..9d9008196e1 100644
--- a/tests/application/modules/admin/controllers/UsersControllerTest.php
+++ b/tests/application/modules/admin/controllers/UsersControllerTest.php
@@ -296,7 +296,7 @@ class UsersControllerPostValidDataWithCommOpsysTest extends UsersControllerWithM
 		$this->emprunteur = new Class_WebService_SIGB_Emprunteur('2341', 'Marcus');
 		$this->emprunteur->setService($this->opsys_service);
 
-		$this->marcus->setFicheSIGB(array('type_comm' => Class_CommSigb::COM_OPSYS,
+		$this->marcus->setFicheSIGB(array('type_comm' => Class_IntBib::COM_OPSYS,
 																			'fiche' => $this->emprunteur,
 																			'nom_aff' => 'Marcus'));
 
diff --git a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php
index 7fd8c9e8d22..b67bd5b6036 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php
@@ -353,7 +353,7 @@ class AbonneControllerNewsletterOpsysCommunicationTest extends AbonneControllerW
 		$this->emprunteur = new Class_WebService_SIGB_Emprunteur('00123', 'Marcus');
 		$this->emprunteur->setService($this->opsys_service);
 
-		$this->marcus->setFicheSIGB(array('type_comm' => Class_CommSigb::COM_OPSYS,
+		$this->marcus->setFicheSIGB(array('type_comm' => Class_IntBib::COM_OPSYS,
 																			'fiche' => $this->emprunteur,
 																			'nom_aff' => 'Marcus'));
 
diff --git a/tests/application/modules/opac/controllers/AbonneVSmartTest.php b/tests/application/modules/opac/controllers/AbonneVSmartTest.php
index d70f66a9493..ab3cfc4b5d5 100644
--- a/tests/application/modules/opac/controllers/AbonneVSmartTest.php
+++ b/tests/application/modules/opac/controllers/AbonneVSmartTest.php
@@ -67,7 +67,7 @@ abstract class AbonneVSmartTestCase extends AbstractControllerTestCase {
 			->setPseudo('manoune')
 			->setDateDebut(null)
 			->setPassword('gaga')
-			->setFicheSIGB(array('type_comm' => Class_CommSigb::COM_VSMART, 
+			->setFicheSIGB(array('type_comm' => Class_IntBib::COM_VSMART, 
 													 'nom_aff' => 'Marcus',
 													 'fiche' => $emprunteur))
 			->setRole('abonne_sigb')
diff --git a/tests/application/modules/telephone/controllers/AbonneControllerTest.php b/tests/application/modules/telephone/controllers/AbonneControllerTest.php
index c0a9f951130..e920072092a 100644
--- a/tests/application/modules/telephone/controllers/AbonneControllerTest.php
+++ b/tests/application/modules/telephone/controllers/AbonneControllerTest.php
@@ -52,12 +52,12 @@ abstract class AbonneControllerTelephoneTestCase extends TelephoneAbstractContro
 
 		$this->_user = Class_Users::getLoader()->getIdentity()
 			->setIdabon(23)
-			->setFicheSIGB(array('type_comm' => Class_CommSigb::COM_VSMART,
+			->setFicheSIGB(array('type_comm' => Class_IntBib::COM_VSMART,
 													 'fiche' => $emprunteur));
 
 		Class_IntBib::getLoader()->newInstanceWithId($this->_user->getIdSite())
 			->setCommParams(array())
-			->setCommSigb(Class_CommSigb::COM_VSMART);
+			->setCommSigb(Class_IntBib::COM_VSMART);
 	}
 }
 
diff --git a/tests/application/modules/telephone/controllers/IndexControllerTest.php b/tests/application/modules/telephone/controllers/IndexControllerTest.php
index c1c61d25aa7..775f50265d5 100644
--- a/tests/application/modules/telephone/controllers/IndexControllerTest.php
+++ b/tests/application/modules/telephone/controllers/IndexControllerTest.php
@@ -316,7 +316,7 @@ class IndexControllerTelephoneWithModulesAndUserLoggedTest extends AbstractIndex
 			->setNom('Bros')
 			->setPrenom('Mario')
 			->setIdabon(23)
-			->setFicheSIGB(array('type_comm' => Class_CommSigb::COM_NANOOK,
+			->setFicheSIGB(array('type_comm' => Class_IntBib::COM_NANOOK,
 													 'fiche' => $emprunteur));
 		
 		parent::setUp();
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 99ddb33b793..065071b13f0 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -54,8 +54,11 @@ setupOpac();
 Zend_Registry::get('cache')->setOption('caching', true);
 $cfg = new Zend_Config(Zend_Registry::get('cfg')->toArray(), true);
 $cfg->amber = new Zend_Config(array('deploy' => false));
+
 Zend_Registry::set('cfg', $cfg);
+Zend_Registry::get('translate')->setLocale('fr');
 
 $_SERVER['SERVER_NAME'] = 'localhost';
 
+
 ?>
diff --git a/tests/library/Class/CommSigbTest.php b/tests/library/Class/CommSigbTest.php
index 3fd27185f71..02e4e8495c4 100644
--- a/tests/library/Class/CommSigbTest.php
+++ b/tests/library/Class/CommSigbTest.php
@@ -296,19 +296,12 @@ class CommSigbAstrolabeOpsysTest extends CommSigbTestCase {
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_OPSYS() {
-		$this->assertEquals(Class_CommSigb::COM_OPSYS,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://astrolabe.com/opsys.wsdl',
-															"type" => 2,
+															"type" => Class_IntBib::COM_OPSYS,
 															"id_bib" => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_astro->getModeComm(5));
 	}
 }
 
@@ -319,7 +312,7 @@ class CommSigbMoulinsVSmartTest extends CommSigbTestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->bib_astro = Class_IntBib::getLoader()
+		$this->bib_moulins = Class_IntBib::getLoader()
 			->newInstanceWithId(5)
 			->setCommParams(array("url_serveur" => 'http://vpn.agglo-moulins.fr/production/'))
 			->setCommSigb(4);
@@ -328,19 +321,12 @@ class CommSigbMoulinsVSmartTest extends CommSigbTestCase {
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_VSMART() {
-		$this->assertEquals(Class_CommSigb::COM_VSMART,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://vpn.agglo-moulins.fr/production/',
-															"type" => 4,
+															"type" => Class_IntBib::COM_VSMART,
 															'id_bib' => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_moulins->getModeComm(5));
 	}
 }
 
@@ -361,19 +347,12 @@ class CommSigbMeuseKohaTest extends CommSigbTestCase {
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_KOHA() {
-		$this->assertEquals(Class_CommSigb::COM_KOHA,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl',
-															"type" => 5,
+															"type" => Class_IntBib::COM_KOHA,
 															'id_bib' => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_koha->getModeComm(5));
 	}
 }
 
@@ -383,29 +362,22 @@ class CommSigbLocalNanookTest extends CommSigbTestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->bib_koha = Class_IntBib::getLoader()
+		$this->bib_pontault = Class_IntBib::getLoader()
 			->newInstanceWithId(5)
 			->setCommParams(array("url_serveur" => 'http://192.168.2.3:9080/afi_Nanook-0.7.5/ilsdi/'))
-			->setCommSigb(Class_CommSigb::COM_NANOOK);
+			->setCommSigb(7);
 
 
 		Class_WebService_SIGB_Nanook::setService($this->createMockForService('Nanook'));
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_NANOOK() {
-		$this->assertEquals(Class_CommSigb::COM_NANOOK,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://192.168.2.3:9080/afi_Nanook-0.7.5/ilsdi/',
-															"type" => Class_CommSigb::COM_NANOOK,
+															"type" => Class_IntBib::COM_NANOOK,
 															'id_bib' => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_pontault->getModeComm(5));
 	}
 }
 
@@ -425,19 +397,12 @@ class CommSigbCarthameTest extends CommSigbTestCase {
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_CARTHAME() {
-		$this->assertEquals(Class_CommSigb::COM_CARTHAME,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://ifr.ro/webservices/index.php',
-															"type" => 6,
+															"type" => Class_IntBib::COM_CARTHAME,
 															'id_bib' => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_ifr->getModeComm(5));
 	}
 }
 
@@ -447,7 +412,7 @@ class CommSigbOrpheeTest extends CommSigbTestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->bib_ifr = Class_IntBib::getLoader()
+		$this->bib_stomer = Class_IntBib::getLoader()
 			->newInstanceWithId(5)
 			->setCommParams(array("url_serveur" => 'http://213.144.218.252:8080/wsOrphee/service.asmx?WSDL'))
 			->setCommSigb(8);
@@ -456,19 +421,12 @@ class CommSigbOrpheeTest extends CommSigbTestCase {
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_ORPHEE() {
-		$this->assertEquals(Class_CommSigb::COM_ORPHEE,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://213.144.218.252:8080/wsOrphee/service.asmx?WSDL',
-															"type" => 8,
+															"type" => Class_IntBib::COM_ORPHEE,
 															'id_bib' => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_stomer->getModeComm(5));
 	}
 }
 
@@ -478,7 +436,7 @@ class CommSigbMicrobibTest extends CommSigbTestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->bib_ifr = Class_IntBib::getLoader()
+		$this->bib_maze = Class_IntBib::getLoader()
 			->newInstanceWithId(5)
 			->setCommParams(array("url_serveur" => 'http://80.11.188.93/webservices/ws_maze.wsdl'))
 			->setCommSigb(9);
@@ -487,19 +445,12 @@ class CommSigbMicrobibTest extends CommSigbTestCase {
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_MICROBIB() {
-		$this->assertEquals(Class_CommSigb::COM_MICROBIB,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://80.11.188.93/webservices/ws_maze.wsdl',
-															"type" => 9,
+															"type" => Class_IntBib::COM_MICROBIB,
 															'id_bib' => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_maze->getModeComm(5));
 	}
 }
 
@@ -511,7 +462,7 @@ class CommSigbBiblixNetTest extends CommSigbTestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->bib_ifr = Class_IntBib::getLoader()
+		$this->bib_wormhout = Class_IntBib::getLoader()
 			->newInstanceWithId(5)
 			->setCommParams(array("url_serveur" => 'http://mediathequewormhout.biblixnet.com/exporte_afi'))
 			->setCommSigb(10);
@@ -520,19 +471,12 @@ class CommSigbBiblixNetTest extends CommSigbTestCase {
 	}
 
 
-	/** @test */
-	public function getTypeCommShouldReturnCOM_BIBLIXNET() {
-		$this->assertEquals(Class_CommSigb::COM_BIBLIXNET,
-												$this->comm_sigb->getTypeComm(5));
-	}
-
-
 	/** @test */
 	public function getModeCommShouldReturnAnArrrayWithCommParams() {
 		$this->assertEquals(array("url_serveur" => 'http://mediathequewormhout.biblixnet.com/exporte_afi',
-															"type" => 10,
+															"type" => Class_IntBib::COM_BIBLIXNET,
 															'id_bib' => 5),
-												$this->comm_sigb->getModeComm(5));
+												$this->bib_wormhout->getModeComm(5));
 	}
 }
 
@@ -555,15 +499,6 @@ class CommSigbWithNotAbonneTest extends Storm_Test_ModelTestCase {
 			->setIdabon(3);
 	}
 
-
-	/** @test */
-	public function shouldReturnEmptyModeComm() {
-		$mode_comm = $this->comm_sigb->getModeComm(0);
-		$this->assertEquals(array('type' => 0,
-															'id_bib' => 0), 
-												$mode_comm);
-	}
-
 	/** @test */
 	public function prolongerPretShouldReturnError() {
 		$this->assertEquals(['erreur' => 'Communication SIGB indisponible'], 
diff --git a/tests/library/Class/NoticeHtmlTest.php b/tests/library/Class/NoticeHtmlTest.php
index 07c8cbfe950..970721204ab 100644
--- a/tests/library/Class/NoticeHtmlTest.php
+++ b/tests/library/Class/NoticeHtmlTest.php
@@ -160,7 +160,7 @@ abstract class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase ex
 
 		Class_IntBib::getLoader()
 			->newInstanceWithId(1)
-			->setCommSigb(Class_CommSigb::COM_MICROBIB)
+			->setCommSigb(Class_IntBib::COM_MICROBIB)
 			->setCommParams('');
 
 
-- 
GitLab