From bec8b1edf00a9303f00887763215ee4049757030 Mon Sep 17 00:00:00 2001
From: pbarroca <pbarroca@afi-sa.fr>
Date: Wed, 4 Nov 2015 18:22:32 +0100
Subject: [PATCH] rel #31316: fix record title in loans list, prefer title from
 Bokeh's record if present

---
 VERSIONS_HOTLINE/31316                        |  1 +
 library/Class/Users.php                       | 15 ++---
 library/Class/WebService/SIGB/Exemplaire.php  | 12 ++--
 .../controllers/AbonneControllerPretsTest.php | 66 ++++++++++++++++++-
 .../opac/controllers/petites_mains.mrc        |  1 +
 5 files changed, 76 insertions(+), 19 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/31316
 create mode 100644 tests/application/modules/opac/controllers/petites_mains.mrc

diff --git a/VERSIONS_HOTLINE/31316 b/VERSIONS_HOTLINE/31316
new file mode 100644
index 00000000000..a15578e9c67
--- /dev/null
+++ b/VERSIONS_HOTLINE/31316
@@ -0,0 +1 @@
+ - ticket #31316 : SIGB Nanook : Correction d'affichage du titre des périodiques dans les prêts en cours du compte lecteur
\ No newline at end of file
diff --git a/library/Class/Users.php b/library/Class/Users.php
index 78458c16c8c..af72472fa66 100644
--- a/library/Class/Users.php
+++ b/library/Class/Users.php
@@ -1114,13 +1114,11 @@ class Class_Users extends Storm_Model_Abstract {
       $user = $this; // compatibilité
 
     if (isset($this->_fiche_sigb))
-      $ret = $this->_fiche_sigb;
-    else {
-      if (!$user->getIdabon())
-        $ret = ["message" => $this->_("Vous devez vous connecter en tant qu'abonné de la bibliothèque pour obtenir plus d'informations.")];
-      else
-        $ret = (new Class_CommSigb())->ficheAbonne($user);
-    }
+      return $this->_fiche_sigb;
+
+    $ret = $user->getIdabon()
+      ? Class_CommSigb::getInstance()->ficheAbonne($user)
+      : ['message' => $this->_("Vous devez vous connecter en tant qu'abonné de la bibliothèque pour obtenir plus d'informations.")];
 
     if (!isset($ret['fiche']))
       $ret['fiche'] = Class_WebService_SIGB_Emprunteur::nullInstance();
@@ -1128,8 +1126,7 @@ class Class_Users extends Storm_Model_Abstract {
     if (!isset($ret['nom_aff']))
       $ret["nom_aff"] = $this->getNomAff($user->ID_USER, true);
 
-    $this->_fiche_sigb = $ret;
-    return $ret;
+    return $this->_fiche_sigb = $ret;
   }
 
 
diff --git a/library/Class/WebService/SIGB/Exemplaire.php b/library/Class/WebService/SIGB/Exemplaire.php
index ff0149583b3..d9c6a3d276f 100644
--- a/library/Class/WebService/SIGB/Exemplaire.php
+++ b/library/Class/WebService/SIGB/Exemplaire.php
@@ -144,15 +144,13 @@ class Class_WebService_SIGB_Exemplaire {
   }
 
 
-  public function getTitre(){
-    if (!$this->titre  and ($notice = $this->getNoticeOPAC()))
-      $this->titre = $notice->getTitrePrincipal();
-
-    return $this->titre;
+  public function getTitre() {
+    return ($notice = $this->getNoticeOPAC())
+      ? $notice->getTitrePrincipal() : $this->titre;
   }
 
 
-  public function setTitre($titre){
+  public function setTitre($titre) {
     $this->titre=$titre;
     return $this;
   }
@@ -169,7 +167,7 @@ class Class_WebService_SIGB_Exemplaire {
   }
 
 
-  public function setBibliotheque($bibliotheque){
+  public function setBibliotheque($bibliotheque) {
     $this->bibliotheque = $bibliotheque;
     return $this;
   }
diff --git a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
index a58f7cebdd4..bc7a7b8d788 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
@@ -18,7 +18,6 @@
  * 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';
 
 abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerTestCase {
   protected
@@ -37,8 +36,10 @@ abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerT
   public function setUp() {
     parent::setUp();
 
-    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users')->whenCalled('save')->answers(true);
-    $this->florence = Class_Users::getLoader()->newInstanceWithId('123456');
+    $this->florence = $this->fixture('Class_Users',
+                                     ['id' => '123456',
+                                      'login' => 'flo',
+                                      'password' => 'flo']);
 
     $this->zend_cache = Storm_Test_ObjectWrapper::mock();
     Storm_Cache::setDefaultZendCache($this->zend_cache);
@@ -553,4 +554,63 @@ class AbonneControllerPretsRenewSuccessThreePretsTest extends AbonneControllerPr
   public function popupContentShouldContainsPatronNotFound() {
     $this->assertEquals(utf8_encode('Votre prêt a bien été prolongé.'), $this->json->content);
   }
+}
+
+
+
+/** @see http://forge.afi-sa.fr/issues/31316 */
+class AbonneControllerPretsPeriodicalTitleTest extends AbstractAbonneControllerPretsTestCase {
+  protected $_sigb;
+
+  public function setUp() {
+    parent::setUp();
+    $this->zend_cache->whenCalled('test')->answers(false);
+
+    $identity = Class_Users::getIdentity();
+    $patron = new Class_WebService_SIGB_Emprunteur($identity->getId(), 'FloFlo');
+
+    $item = (new Class_WebService_SIGB_Exemplaire(12387))
+      ->setTitre('Avril-mai-juin 2013')
+      ->setDateRetour('30-12-2015')
+      ->setNoNotice(13340)
+      ->setBibliotheque('Espace Culturel François-Mitterrand');
+
+    $loan = new Class_WebService_SIGB_Emprunt(12387, $item);
+
+    $patron->empruntsAdd($loan);
+
+    Class_CommSigb::setInstance($this->mock()
+                                ->whenCalled('ficheAbonne')
+                                ->answers(['fiche' => $patron]));
+
+    $record = $this->fixture('Class_Notice',
+                             ['id' => 889,
+                              'unimarc' => file_get_contents(__DIR__.'/petites_mains.mrc')]);
+
+    $z995 = [['clef' => 'a', 'valeur' => 'Espace Culturel'],
+             ['clef' => 'f', 'valeur' => '0720028863'],
+             ['clef' => 'k', 'valeur' => 'J-REV 10-N°90']];
+
+    $this->fixture('Class_Exemplaire',
+                   ['id' => 967,
+                    'id_origine' => 13340,
+                    'zone995' => serialize($z995),
+                    'notice' => $record]);
+
+    $identity->setIdabon('007');
+
+    $this->dispatch('/opac/abonne/prets', true);
+  }
+
+
+  public function tearDown() {
+    Class_CommSigb::setInstance(null);
+    parent::tearDown();
+  }
+
+
+  /** @test */
+  public function titleShouldBePetitesMains90() {
+    $this->assertXPathContentContains('//a', utf8_encode('Petites mains n° 90'));
+  }
 }
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/petites_mains.mrc b/tests/application/modules/opac/controllers/petites_mains.mrc
new file mode 100644
index 00000000000..9db777f5565
--- /dev/null
+++ b/tests/application/modules/opac/controllers/petites_mains.mrc
@@ -0,0 +1 @@
+00293nas2 2200109   450 00100060000001100090000610000450001512200450006020000280010546100290013380100210016213340  d5,95  a        c          ay0frey0103    ba      a 20120407                               1 aAvril-mai-juin 2013v90  tPetites mainsv90018640  bB.M. d'Herbignac
\ No newline at end of file
-- 
GitLab