From 4db20533e37cad7614e5d6524d3d68b3049be2aa Mon Sep 17 00:00:00 2001
From: Henri-Damien LAURENT <hdlaurent@afi-sa.fr>
Date: Tue, 31 May 2022 00:52:10 +0200
Subject: [PATCH] hotline#148741 : DI : console output is more consistent

---
 VERSIONS_HOTLINE/148741                       |   1 +
 library/Class/Loan/Pnb.php                    |  27 ++-
 library/Class/TableDescription/PNBLoans.php   |   5 +-
 library/ZendAfi/View/Helper/Album/Loans.php   |   9 +-
 .../ZendAfi/View/Helper/Album/OldLoans.php    |   6 +-
 .../ZendAfi/View/Helper/Notice/Dilicom.php    |   4 +
 .../PnbDilicom/PnbDilicomAdminTest.php        | 104 ++++++---
 tests/scenarios/PnbDilicom/PnbDilicomTest.php | 218 +++++++++++++++++-
 8 files changed, 328 insertions(+), 46 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/148741

diff --git a/VERSIONS_HOTLINE/148741 b/VERSIONS_HOTLINE/148741
new file mode 100644
index 00000000000..fed4b3334f5
--- /dev/null
+++ b/VERSIONS_HOTLINE/148741
@@ -0,0 +1 @@
+ - correctif #148741 : PNB : Les login et cartes lecteurs sont intégrées dans l'export CSV des prêts Dilicom. Les 5 prêts historiques sont affichés en front en respectant le RGPD.
\ No newline at end of file
diff --git a/library/Class/Loan/Pnb.php b/library/Class/Loan/Pnb.php
index 6fd89b58030..3a179a8b78a 100644
--- a/library/Class/Loan/Pnb.php
+++ b/library/Class/Loan/Pnb.php
@@ -20,6 +20,8 @@
  */
 
 class Class_Loan_PnbLoader extends Storm_Model_Loader {
+  const
+    CNIL_DAYS_MAX_RETENTION = -122;
 
   public function findAllOngoingOfUser($user) {
     if (!$user)
@@ -81,7 +83,9 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader {
     return Class_Loan_Pnb::findAllBy(['order_line_id' => $item->getOrderLineId(),
                                       'order' => 'expected_return_date desc',
                                       'limit' => 5,
-                                      'where' => sprintf('expected_return_date <= "%s"', $this->_getDate())]);
+                                      'where' => sprintf('expected_return_date <= "%s" and expected_return_date >= "%s"',
+                                                         $this->_getDate(),
+                                                         $this->_getCNILMaxRetentionDate())]);
   }
 
 
@@ -101,9 +105,14 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader {
   }
 
 
-  protected function _getDate() {
+  protected function _getDate() :string {
     return Class_Loan_Pnb::getTimeSource()->dateFormat('Y-m-d H:i:s');
   }
+
+
+  protected function _getCNILMaxRetentionDate() :string {
+    return Class_Loan_Pnb::addDaysToCurrentDate(static::CNIL_DAYS_MAX_RETENTION);
+  }
 }
 
 
@@ -202,6 +211,20 @@ class Class_Loan_Pnb extends Storm_Model_Abstract {
   }
 
 
+  public function getUserLogin() :string {
+    if ($user = $this->getUser())
+      return $user->getLogin();
+    return '';
+  }
+
+
+  public function getUserIdabon() :string {
+    if ($user = $this->getUser())
+      return $user->getIdabon();
+    return '';
+  }
+
+
   public function getDateRetour() {
     return $this->getExpectedReturnDate();
   }
diff --git a/library/Class/TableDescription/PNBLoans.php b/library/Class/TableDescription/PNBLoans.php
index 97af36975df..9e06943066e 100644
--- a/library/Class/TableDescription/PNBLoans.php
+++ b/library/Class/TableDescription/PNBLoans.php
@@ -36,7 +36,10 @@ class Class_TableDescription_PNBLoans extends Class_TableDescription {
       ->addColumn($this->_('Genre'), 'first_kind')
       ->addColumn($this->_('Section'), 'first_section')
       ->addColumn($this->_('Catégorie'), 'category')
-      ->addColumn($this->_('Bibliothèque'), 'bibliotheque');
+      ->addColumn($this->_('Bibliothèque'), 'bibliotheque')
+      ->addColumn($this->_('Login Emprunteur'), 'user_login')
+      ->addColumn($this->_('Carte Emprunteur'), 'user_idabon')
+      ->addColumn($this->_('orderid'), 'order_line_id');
   }
 
 
diff --git a/library/ZendAfi/View/Helper/Album/Loans.php b/library/ZendAfi/View/Helper/Album/Loans.php
index 5b59a058c40..b4e85bdc12d 100644
--- a/library/ZendAfi/View/Helper/Album/Loans.php
+++ b/library/ZendAfi/View/Helper/Album/Loans.php
@@ -22,7 +22,7 @@
 
 class ZendAfi_View_Helper_Album_Loans extends ZendAfi_View_Helper_BaseHelper {
   public function Album_Loans($item) {
-    if(!$loans = Class_Loan_Pnb::findAllOngoingOfItem($item))
+    if(!$loans = $this->_getLoans($item))
       return $this->_tag('p',
                          $this->_getEmptyMessage(),
                          ['class' => 'error']);
@@ -42,7 +42,12 @@ class ZendAfi_View_Helper_Album_Loans extends ZendAfi_View_Helper_BaseHelper {
   }
 
 
-  protected function _getEmptyMessage() {
+  protected function _getLoans($item) : Array{
+    return Class_Loan_Pnb::findAllOngoingOfItem($item);
+  }
+
+
+  protected function _getEmptyMessage() : string {
     return $this->_('Aucun prêt en cours');
   }
 }
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/Album/OldLoans.php b/library/ZendAfi/View/Helper/Album/OldLoans.php
index c81f31dd45a..faf96c4fedc 100644
--- a/library/ZendAfi/View/Helper/Album/OldLoans.php
+++ b/library/ZendAfi/View/Helper/Album/OldLoans.php
@@ -26,12 +26,12 @@ class ZendAfi_View_Helper_Album_OldLoans extends ZendAfi_View_Helper_Album_Loans
   }
 
 
-  protected function _getEmptyMessage() {
-    return $this->_('Le document n\'a pas encore été emprunté');
+  protected function _getEmptyMessage() : string {
+    return $this->_('Le document n\'a pas encore été emprunté, ou les derniers prêts datent de plus de 4 mois.');
   }
 
 
-  protected function _getLoans($item) {
+  protected function _getLoans($item) : Array {
     return Class_Loan_Pnb::findLastPastLoansForItem($item);
   }
 }
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/Notice/Dilicom.php b/library/ZendAfi/View/Helper/Notice/Dilicom.php
index e2ee5434cef..2c545db6ef4 100644
--- a/library/ZendAfi/View/Helper/Notice/Dilicom.php
+++ b/library/ZendAfi/View/Helper/Notice/Dilicom.php
@@ -101,6 +101,7 @@ class ZendAfi_View_Helper_Notice_Dilicom extends ZendAfi_View_Helper_BaseHelper
     return $this->_withItemsDo(
                                function($item) {
                                  $constraints = $item->getUsageConstraints();
+                                 $usage_report = Class_Album_UsageReport::findFirstBy(['item_id' => $item->getId()]);
                                  return $this->_tag('h3', $constraints->getLoanOrderLineId())
                                    . $this->_tag('div',
                                                  $this->view->Album_UsageConstraints($constraints)
@@ -113,6 +114,9 @@ class ZendAfi_View_Helper_Notice_Dilicom extends ZendAfi_View_Helper_BaseHelper
                                                                                      $this->_tag('dt', $this->_('Prêts simultanés en cours')) . $this->_tag('dd', $item->getLoanCount())
                                                                                      .
                                                                                      $this->_tag('dt', $this->_('Prêts simultanés autorisés')) . $this->_tag('dd', $item->getLoanAllowedNumberOfUsers())
+                                                                                     .
+                                                                                     $this->_tag('dt', $this->_('Prêts historiques totaux')) . $this->_tag('dd', $usage_report->getLoanQuantityOrLocalLoanCount())
+
                                                                                      .
                                                                                      $this->_tag('dt', $this->_('Prêts simultanés restants')) . $this->_tag('dd', $item->numberOfSimultaneousLoansRemaning())
                                                                                      .
diff --git a/tests/scenarios/PnbDilicom/PnbDilicomAdminTest.php b/tests/scenarios/PnbDilicom/PnbDilicomAdminTest.php
index 78bc7932794..b32d4fbf182 100644
--- a/tests/scenarios/PnbDilicom/PnbDilicomAdminTest.php
+++ b/tests/scenarios/PnbDilicom/PnbDilicomAdminTest.php
@@ -34,33 +34,33 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
 
     RessourcesNumeriquesFixtures::activateDilicom();
 
-    $this->fixture('Class_Album',
+    $this->fixture(Class_Album::class,
                    ['id' => 23,
                     'id_origine' => 'Dilicom-36636',
                     'titre' => 'Being human being',
                     'type_doc_id' => Class_TypeDoc::DILICOM,
                    ]);
 
-    $this->fixture('Class_Album_Item',
+    $this->fixture(Class_Album_Item::class,
                    ['id' => 1,
                     'quantity' => '10',
                     'loan_count' => '2',
                     'album_id' => 23,
                     'usage_constraints' =>
                     [
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 1,
                                      'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 45,
                                                                         Class_Album_UsageConstraint::QUANTITY => 30,
                                                                         Class_Album_UsageConstraint::MAX_NB_OF_USERS => 15])]),
 
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 2,
                                      'usage_type' => Class_Album_UsageConstraint::DEVICE_SHARE_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::QUANTITY => 6])]),
 
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 3,
                                      'usage_type' => Class_Album_UsageConstraint::AVAILABILITY_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 2345,
@@ -69,7 +69,27 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
                     ]
                    ]);
 
-    $this->fixture('Class_Loan_Pnb',
+    $this->fixture(Class_Users::class,
+                   ['id' => 4077,
+                    'login' => 'ppersonne',
+                    'idabon'=> '000005',
+                    'nom' => 'Personne',
+                    'prenom' => 'Paul',
+                    'password' => 'secret'
+                   ]);
+
+
+    $this->fixture(Class_Users::class,
+                   ['id' => 4078,
+                    'login' => 'drivers',
+                    'idabon'=> '000006',
+                    'nom' => 'Rivers',
+                    'prenom' => 'Dick',
+                    'password' => 'secret'
+                   ]);
+
+
+    $this->fixture(Class_Loan_Pnb::class,
                    ['id' => 1,
                     'record_origin_id' => 'Dilicom-36636',
                     'subscriber_id' => '000005',
@@ -79,7 +99,7 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
                     'loan_link' => 'https://pnb-dilicom.centprod.com/v2//XXXXXXXX.do',
                     'order_line_id' => '12385',]);
 
-    $this->fixture('Class_Loan_Pnb',
+    $this->fixture(Class_Loan_Pnb::class,
                    ['id' => 2,
                     'record_origin_id' => 'Dilicom-36636',
                     'subscriber_id' => '000006',
@@ -90,21 +110,21 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
                     'order_line_id' => '12385',]);
 
 
-    $this->fixture('Class_Album_Item',
+    $this->fixture(Class_Album_Item::class,
                    ['id' => 2,
                     'quantity' => '20',
                     'loan_count' => '5',
                     'album_id' => 23,
                     'usage_constraints' =>
                     [
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 4,
                                      'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 20,
                                                                         Class_Album_UsageConstraint::QUANTITY => 20,
                                                                         Class_Album_UsageConstraint::MAX_NB_OF_USERS => 15])]),
 
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 5,
                                      'usage_type' => Class_Album_UsageConstraint::AVAILABILITY_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 20000,
@@ -114,27 +134,27 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
                    ]);
 
 
-    $this->fixture('Class_CodifGenre',
+    $this->fixture(Class_CodifGenre::class,
                    ['id' => 23,
                     'libelle' => 'Heavy Metal']);
 
-    $this->fixture('Class_CodifGenre',
+    $this->fixture(Class_CodifGenre::class,
                    ['id' => 24,
                     'libelle' => 'Jazz']);
 
-    $this->fixture('Class_CodifSection',
+    $this->fixture(Class_CodifSection::class,
                    ['id' => 33,
                     'libelle' => 'Espace métal']);
 
-    $this->fixture('Class_CodifSection',
+    $this->fixture(Class_CodifSection::class,
                    ['id' => 34,
                     'libelle' => 'Espace jazz']);
 
-    $fondu = $this->fixture('Class_AlbumCategorie',
+    $fondu = $this->fixture(Class_AlbumCategorie::class,
                             ['id' => 1301,
                              'libelle' => 'Fondu']);
 
-    $this->fixture('Class_Album',
+    $this->fixture(Class_Album::class,
                    ['id' => 9999,
                     'id_origine' => 'Dilicom-3663608260879',
                     'titre' => 'Hell is from here to eternity',
@@ -148,26 +168,26 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
          ->setAnnee(1992)
       ;
 
-    $this->fixture('Class_Album_Item',
+    $this->fixture(Class_Album_Item::class,
                    ['id' => 9,
                     'quantity' => 990000,
                     'loan_count' => 3,
                     'album_id' => 9999,
                     'usage_constraints' =>
                     [
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 6,
                                      'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 359,
                                                                         Class_Album_UsageConstraint::QUANTITY => 999999,
                                                                         Class_Album_UsageConstraint::MAX_NB_OF_USERS => 1])]),
 
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 7,
                                      'usage_type' => Class_Album_UsageConstraint::DEVICE_SHARE_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::QUANTITY => 6])]),
 
-                     $this->fixture('Class_Album_UsageConstraint',
+                     $this->fixture(Class_Album_UsageConstraint::class,
                                     ['id' => 8,
                                      'usage_type' => Class_Album_UsageConstraint::AVAILABILITY_CONSTRAINT,
                                      'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 999999,
@@ -176,7 +196,7 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
                     ]
                    ]);
 
-    $this->fixture('Class_Loan_Pnb',
+    $this->fixture(Class_Loan_Pnb::class,
                    ['id' => 3,
                     'record_origin_id' => 'Dilicom-3663608260879',
                     'subscriber_id' => '000005',
@@ -186,7 +206,7 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
                     'loan_link' => 'https://pnb-dilicom.centprod.com/v2//XXXXXXXX.do',
                     'order_line_id' => '584837a045ce56ef0a072a8b',]);
 
-    $this->fixture('Class_Loan_Pnb',
+    $this->fixture(Class_Loan_Pnb::class,
                    ['id' => 4,
                     'record_origin_id' => 'Dilicom-3663608260879',
                     'subscriber_id' => '000006',
@@ -204,7 +224,7 @@ abstract class PnbDilicomAdminTestCase extends Admin_AbstractControllerTestCase
 
 
     foreach(range(1, 6) as $i)
-      $this->fixture('Class_Hold_Pnb',
+      $this->fixture(Class_Hold_Pnb::class,
                      ['id' => $i,
                       'record_origin_id' => 'Dilicom-3663608260879',
                       'user_id' => $i,
@@ -830,7 +850,7 @@ class PnbDilicomAdminAlbumControllerExportLoansCsvTest extends PnbDilicomAdminTe
   public function setUp() {
     parent::setUp();
 
-    $this->fixture('Class_Users',
+    $this->fixture(Class_Users::class,
                    ['id' => 7,
                     'nom' => 'boum',
                     'login'=>'boum',
@@ -838,11 +858,21 @@ class PnbDilicomAdminAlbumControllerExportLoansCsvTest extends PnbDilicomAdminTe
                     'id_site' => 1,
                     'idabon' => '9878']);
 
-    $this->fixture('Class_Bib', ['id' => 1,
-                                 'libelle' => 'SomewhereInCode',
-                                 'gln' => '333']);
 
-    $this->fixture('Class_Loan_Pnb',
+    $this->fixture(Class_Users::class,
+                   ['id' => 12321,
+                    'nom' => 'Riri',
+                    'login'=>'Duck',
+                    'password'=>'secret',
+                    'id_site' => 1,
+                    'idabon' => '1041']);
+
+    $this->fixture(Class_Bib::class,
+                   ['id' => 1,
+                    'libelle' => 'SomewhereInCode',
+                    'gln' => '333']);
+
+    $this->fixture(Class_Loan_Pnb::class,
                    ['id' => 5,
                     'record_origin_id' => 'Dilicom-3663608260879',
                     'subscriber_id' => 9879,
@@ -852,10 +882,10 @@ class PnbDilicomAdminAlbumControllerExportLoansCsvTest extends PnbDilicomAdminTe
                     'loan_link' => 'https://pnb-dilicom.centprod.com/v2//XXXXXXXX.do',
                     'order_line_id' => '82377a045ce56ef0a072a8b']);
 
-    $this->fixture('Class_Loan_Pnb',
+    $this->fixture(Class_Loan_Pnb::class,
                    ['id' => 6,
                     'record_origin_id' => 'Dilicom-3663608260879',
-                    'subscriber_id' => 9878,
+                    'subscriber_id' => 1041,
                     'user_id' => 12321,
                     'expected_return_date' => '2020-02-20 13:57:33',
                     'loan_date' => '2020-02-06 13:57:33',
@@ -935,13 +965,13 @@ class PnbDilicomAdminAlbumControllerExportLoansCsvTest extends PnbDilicomAdminTe
 
     $this->dispatch('admin/pnb/export-loans-csv/' . $url);
 
-    $this->assertEquals('Date;Retour;Titre;"Date de commande";Auteur;Éditeur;Collection;Année;Genre;Section;Catégorie;Bibliothèque
-16/12/2016;20/01/2017;"Being human being";30/03/2015;;;;;;;"Albums non classés";
-16/12/2016;20/01/2017;"Hell is from here to eternity";30/03/2015;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;
-13/11/2017;13/12/2017;"Being human being";30/03/2015;;;;;;;"Albums non classés";
-13/11/2017;13/12/2017;"Hell is from here to eternity";30/03/2015;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;
-06/01/2020;20/01/2020;"Hell is from here to eternity";;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;SomewhereInCode
-06/02/2020;20/02/2020;"Hell is from here to eternity";;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;SomewhereInCode
+    $this->assertEquals('Date;Retour;Titre;"Date de commande";Auteur;Éditeur;Collection;Année;Genre;Section;Catégorie;Bibliothèque;"Login Emprunteur";"Carte Emprunteur";orderid
+16/12/2016;20/01/2017;"Being human being";30/03/2015;;;;;;;"Albums non classés";;ppersonne;000005;12385
+16/12/2016;20/01/2017;"Hell is from here to eternity";30/03/2015;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;;ppersonne;000005;584837a045ce56ef0a072a8b
+13/11/2017;13/12/2017;"Being human being";30/03/2015;;;;;;;"Albums non classés";;drivers;000006;12385
+13/11/2017;13/12/2017;"Hell is from here to eternity";30/03/2015;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;;drivers;000006;584837a045ce56ef0a072a8b
+06/01/2020;20/01/2020;"Hell is from here to eternity";;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;SomewhereInCode;boum;9878;82377a045ce56ef0a072a8b
+06/02/2020;20/02/2020;"Hell is from here to eternity";;"Iron Maiden";EMI;"Temple Of Rock";1992;"Heavy Metal";"Espace métal";Fondu;SomewhereInCode;Duck;1041;82377a045ce56ef0a072a8b
 ',
                         $this->_response->getBody());
   }
diff --git a/tests/scenarios/PnbDilicom/PnbDilicomTest.php b/tests/scenarios/PnbDilicom/PnbDilicomTest.php
index 2e818ad2a42..fbdb9a7c455 100644
--- a/tests/scenarios/PnbDilicom/PnbDilicomTest.php
+++ b/tests/scenarios/PnbDilicom/PnbDilicomTest.php
@@ -965,7 +965,12 @@ class PnbDilicomRechercheControllerViewnoticeWithInspectorGadgetTest extends Adm
     $book->assertSave();
     $book->index();
 
-    $this->fixture('Class_Hold_Pnb',
+    $this->fixture(Class_Album_UsageReport::class,
+                   [ 'id'=> 46,
+                    'item_id' => 1,
+                    'loan_quantity' => 4]);
+
+    $this->fixture(Class_Hold_Pnb::class,
                    ['id' => 1,
                     'user_id' => 6,
                     'record_origin_id' => $book->getIdOrigine(),
@@ -1564,3 +1569,214 @@ class PnbDilicomOffersValidityUpdateFromXmlTest extends ModelTestCase {
     $this->assertEquals('2030-10-14T14:46:15+0200',$items[0]->getUsageConstraints()->getAvailabilityEndDate());
   }
 }
+
+
+
+
+abstract class PnbDilicomLoansTestCase extends PnbDilicomHoldsTestCase {
+  protected $_html;
+
+  public function setUp(){
+    parent::setUp();
+    $this
+      ->_setupLoans();
+  }
+
+  public function tearDown(){
+    Class_Loan_Pnb::setTimeSource(null);
+    parent::tearDown();
+  }
+
+  protected function _setupLoans() {
+    $timesource = new TimeSourceForTest('2022-06-10 10:23:10');
+    Class_Loan_Pnb::setTimeSource($timesource);
+    $http = $this->mock()
+                 ->whenCalled('open_url')
+                 ->answers('');
+
+    Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($http);
+
+    $this->fixture(Class_Loan_Pnb::class,
+                   ['id' => 8,
+                    'user_id' => 6,
+                    'subscriber_id' => '',
+                    'record_origin_id' => $this->book->getIdOrigine(),
+                    'order_line_id' => 'x321',
+                    'loan_date' => '2022-03-01 20:10:00',
+                    'expected_return_date' => '2022-04-01 20:10:00']);
+
+    $this->fixture(Class_Loan_Pnb::class,
+                   ['id' => 9,
+                    'user_id' => 7,
+                    'subscriber_id' => '',
+                    'order_line_id' => 'x321',
+                    'record_origin_id' => $this->book->getIdOrigine(),
+                    'loan_date' => '2022-06-02 20:10:00',
+                    'expected_return_date' => '2022-06-24 20:10:00']);
+
+    $this->fixture(Class_Loan_Pnb::class,
+                   ['id' => 10,
+                    'user_id' => '',
+                    'subscriber_id' => 129,
+                    'order_line_id' => 'x321',
+                    'record_origin_id' => $this->book->getIdOrigine(),
+                    'loan_date' => '2022-06-01 20:10:00',
+                    'expected_return_date' => '2022-06-21 20:10:00']);
+
+    $this->fixture(Class_Loan_Pnb::class,
+                   ['id' => 11,
+                    'user_id' => 8,
+                    'subscriber_id' => '',
+                    'order_line_id' => 'x321',
+                    'record_origin_id' => $this->book->getIdOrigine(),
+                    'loan_date' => '2021-06-03 20:10:00',
+                    'expected_return_date' => '2021-08-03 20:10:00']);
+
+
+    $this->fixture(Class_Loan_Pnb::class,
+                   ['id' => 12,
+                    'user_id' => 666,
+                    'subscriber_id' => '',
+                    'order_line_id' => 'x321',
+                    'record_origin_id' => $this->book->getIdOrigine(),
+                    'loan_date' => '2021-06-06 20:10:00',
+                    'expected_return_date' => '2021-06-26 20:10:00']);
+
+    return $this;
+  }
+
+
+  public function getElements(){
+    return [
+            ['h3','thelma'],
+            ['td','2022-03-01 20:10:00'],
+            ['td','2022-04-01 20:10:00'],
+            ['h3','darryl'],
+            ['td','2021-06-03 20:10:00'],
+            ['td','2021-08-03 20:10:00'],
+            ['h3','Inconnu'],
+            ['td','2021-06-06 20:10:00'],
+            ['td','2021-06-26 20:10:00'],
+
+    ];
+  }
+
+}
+
+
+
+
+class PnbDilicomLoansPageTest extends PnbDilicomLoansTestCase{
+
+  public function setUp() {
+    parent::setUp();
+
+    $helper = (new ZendAfi_View_Helper_Album_Loans(Class_Album_Item::find(1)))
+      ->setView(new ZendAfi_Controller_Action_Helper_View());
+    $this->_html = $helper->Album_Loans(Class_Album_Item::find(1));
+  }
+
+
+  /** @test */
+  public function loansTabShould5LoansEntries() {
+    (new Storm_Test_XPath())
+      ->assertXPathCount($this->_html,
+                         '//h3',
+                         5);
+  }
+
+
+  /** @test
+      @dataProvider getElements
+   */
+  public function loansTabShouldDisplayLoans($tag, $value) {
+    (new Storm_Test_XPath())
+      ->assertXPathContentContains($this->_html,
+                         '//'.$tag,
+                         $value);
+  }
+}
+
+
+
+
+
+class PnbDilicomOldLoansPageTest extends PnbDilicomLoansTestCase{
+  public function setUp() {
+    parent::setUp();
+
+    $helper = (new ZendAfi_View_Helper_Album_OldLoans(Class_Album_Item::find(1)))
+      ->setView(new ZendAfi_Controller_Action_Helper_View());
+
+    $this->_html = $helper->Album_OldLoans(Class_Album_Item::find(1));
+
+  }
+
+
+  /** @test */
+  public function oldLoansTabShould5LoansEntries() {
+    (new Storm_Test_XPath())
+      ->assertXPathCount($this->_html,
+                         '//h3',
+                         5);
+  }
+
+
+  /** @test
+      @dataProvider getElements
+   */
+  public function oldLoansTabShouldDisplayLoans($tag, $value) {
+    (new Storm_Test_XPath())
+      ->assertXPathContentContains($this->_html,
+                         '//'.$tag,
+                         $value);
+
+  }
+}
+
+
+
+
+class PnbDilicomOldLoansQueryPageTest extends PnbDilicomLoansTestCase{
+  public function setUp() {
+    parent::setUp();
+    $this->_wrapper = $this->onLoaderOfModel(Class_Loan_Pnb::class);
+
+    $helper = (new ZendAfi_View_Helper_Album_OldLoans(Class_Album_Item::find(1)))
+      ->setView(new ZendAfi_Controller_Action_Helper_View());
+
+    $this->_html = $helper->Album_OldLoans(Class_Album_Item::find(1));
+  }
+
+
+  /** @test */
+  public function oldLoansTabShouldCallFindAllByWithExpectedParams() {
+    $this->assertEquals([['order_line_id' => 'x321',
+                          'order' => 'expected_return_date desc',
+                          'limit' => 5,
+                          'where' => 'expected_return_date <= "2022-06-10 10:23:10" and expected_return_date >= "2022-02-08"']],$this->_wrapper->getAttributesForLastCallOn('findAllBy'));
+  }
+}
+
+
+
+
+class PnbDilicomLoansQueryPageTest extends PnbDilicomLoansTestCase{
+  public function setUp() {
+    parent::setUp();
+    $this->_wrapper = $this->onLoaderOfModel(Class_Loan_Pnb::class);
+
+    $helper = (new ZendAfi_View_Helper_Album_Loans(Class_Album_Item::find(1)))
+      ->setView(new ZendAfi_Controller_Action_Helper_View());
+
+    $this->_html = $helper->Album_Loans(Class_Album_Item::find(1));
+  }
+
+
+  /** @test */
+  public function loansTabShouldCallExpectedFindAllBy() {
+    $this->assertEquals([['order_line_id' => 'x321',
+                          'where' => 'expected_return_date > "2022-06-10 10:23:10"']],
+                        $this->_wrapper->getAttributesForLastCallOn('findAllBy'));
+  }
+}
-- 
GitLab