From e4545235aa4e431555d63be2d17ab8107a7a89f1 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Tue, 1 Dec 2015 17:16:58 +0100
Subject: [PATCH] dev#30973 pnb_backoffice_table

fix loan pnb fetch for a user
---
 library/Class/Loan/Pnb.php                    |  5 ++-
 .../controllers/AbonneControllerPretsTest.php | 31 +++++++++++++++++--
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/library/Class/Loan/Pnb.php b/library/Class/Loan/Pnb.php
index 2b49c9ee73e..2a22690a715 100644
--- a/library/Class/Loan/Pnb.php
+++ b/library/Class/Loan/Pnb.php
@@ -21,7 +21,10 @@
 
 class Class_Loan_PnbLoader extends Storm_Model_Loader {
   public function findAllOngoingOfUser($user) {
-    $loans = $this->findAllOngoingBy(['user_id' => $user->getId()]);
+    $loans =
+      array_merge(
+                  $this->findAllOngoingBy(['subscriber_id' => $user->getIdabon()]),
+                  $this->findAllOngoingBy(['user_id' => $user->getId()]));
 
     (new Class_WebService_BibNumerique_Dilicom_Hub())
       ->updateLoansReturnDate($loans);
diff --git a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
index 15ee9fcca23..5c02eebb486 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
@@ -43,6 +43,7 @@ abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerT
     $this->florence = $this->fixture('Class_Users',
                                      ['id' => '123456',
                                       'login' => 'flo',
+                                      'idabon' => 'x234',
                                       'password' => 'flo']);
 
     $this->zend_cache = Storm_Test_ObjectWrapper::mock();
@@ -70,6 +71,9 @@ abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerT
                         ->with('test-gln', 'test-gln-pass')
                         ->answers(null)
 
+                        ->whenCalled('open_url')
+                        ->answers('')
+
                         ->whenCalled('open_url')
                         ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5')
                         ->answers(DilicomFixtures::getEndedLoansResponse())
@@ -150,7 +154,7 @@ abstract class AbonneControllerPretsListThreePretsTestCase extends AbstractAbonn
 
     $this->fixture('Class_Loan_Pnb',
                    ['id' => 5,
-                    'user_id' => $this->florence->getId(),
+                    'subscriber_id' => $this->florence->getIdabon(),
                     'ongoing' => true,
                     'expected_return_date' => '2022-05-02T18:14:14+02:00',
                     'album' => $this->fixture('Class_Album',
@@ -160,6 +164,20 @@ abstract class AbonneControllerPretsListThreePretsTestCase extends AbstractAbonn
                                                'titre' => 'Pinocchio'])->addAuthor('Collodi')
                    ]);
 
+
+    $this->fixture('Class_Loan_Pnb',
+                   ['id' => 6,
+                    'user_id' => $this->florence->getId(),
+                    'ongoing' => true,
+                    'expected_return_date' => '2020-01-01T18:14:14+02:00',
+                    'album' => $this->fixture('Class_Album',
+                                              ['id' => 5,
+                                               'notice_id' => 6,
+                                               'id_origine' => 'Dilicom-88817217',
+                                               'titre' => 'Peter Pan'])
+                   ]);
+
+
     $this->florence
       ->setFicheSigb(['type_comm' => 2, //OPSYS
                       'fiche' => $emprunteur,
@@ -366,14 +384,23 @@ class AbonneControllerPretsListThreePretsTest extends AbonneControllerPretsListT
 
 
   /** @test */
-  public function pinocchioPnbLoanReturnDateShouldBeAsExpected() {
+  public function pinocchioPnbLoanReturnDateShouldBe2022() {
     $this->assertXPathContentContains('//tbody//td[@class="date_retour"]',
                                       '2022-05-02T18:14:14+02:00');
   }
+
+
+  /** @test */
+  public function peterPanPnbLoanReturnDateShouldBe2020() {
+    $this->assertXPathContentContains('//tbody//td[@class="date_retour"]',
+                                      '2020-01-01T18:14:14+02:00');
+  }
 }
 
 
 
+
+
 class AbonneControllerPretsListThreePretsPnbEarlyReturnTest extends AbonneControllerPretsListThreePretsTestCase {
   public function setUp() {
     parent::setUp();
-- 
GitLab