Commit 80ba0a9c authored by Patrick Barroca's avatar Patrick Barroca 🐧

hotline #108377 : fix Dilicom quota of guest users

parent 456d1f86
Pipeline #9743 passed with stage
in 43 minutes and 10 seconds
- ticket #108377 : Ressources numériques : Correction du calcul du quota de prêt pour les invités
\ No newline at end of file
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -21,11 +21,7 @@ ...@@ -21,11 +21,7 @@
class Class_Loan_PnbLoader extends Storm_Model_Loader { class Class_Loan_PnbLoader extends Storm_Model_Loader {
public function findAllOngoingOfUser($user) { public function findAllOngoingOfUser($user) {
$loans = $loans = $this->_ongoingOf($user);
array_unique(
array_merge(
$this->findAllOngoingBy(['subscriber_id' => $user->getIdabon()]),
$this->findAllOngoingBy(['user_id' => $user->getId()])));
(new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($loans); (new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($loans);
...@@ -37,6 +33,16 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader { ...@@ -37,6 +33,16 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader {
} }
protected function _ongoingOf($user) {
$by_user_id = $this->findAllOngoingBy(['user_id' => $user->getId()]);
if (!$user->isAbonne())
return $by_user_id;
return array_unique(array_merge($this->findAllOngoingBy(['subscriber_id' => $user->getIdabon()]),
$by_user_id));
}
public function findAllOngoingOfItem($item) { public function findAllOngoingOfItem($item) {
$loans = $this->findAllOngoingBy(['order_line_id' => $item->getOrderLineId()]); $loans = $this->findAllOngoingBy(['order_line_id' => $item->getOrderLineId()]);
(new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($loans); (new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($loans);
......
...@@ -2645,7 +2645,8 @@ class PnbDilicomBibNumeriqueControllerConsultBookWithErrorsActionTest extends Pn ...@@ -2645,7 +2645,8 @@ class PnbDilicomBibNumeriqueControllerConsultBookWithErrorsActionTest extends Pn
class PnbDilicomBibNumeriqueControllerLoanBookActionTest extends PnbDilicomBibNumeriqueControllerLoanBookActionTestCase { class PnbDilicomBibNumeriqueControllerLoanBookActionTest
extends PnbDilicomBibNumeriqueControllerLoanBookActionTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
...@@ -2781,6 +2782,115 @@ class PnbDilicomBibNumeriqueControllerLoanBookActionTwiceWithSameUserTest extend ...@@ -2781,6 +2782,115 @@ class PnbDilicomBibNumeriqueControllerLoanBookActionTwiceWithSameUserTest extend
/** @see http://forge.afi-sa.fr/issues/108377 */
abstract class PnbDilicomBibNumeriqueControllerLoanBookActionGuestTestCase
extends PnbDilicomBibNumeriqueControllerTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('DILICOM_PNB_MAX_LOAN_PER_USER', 3);
$user = $this->fixture('Class_Users',
['id' => 88,
'login' => 'guest',
'password' => 'roxor',
'id_site' => 1,
'user_groups' => [Class_UserGroup::find(20)],
'role' => ZendAfi_Acl_AdminControllerRoles::INVITE,
]);
ZendAfi_Auth::getInstance()->logUser($user);
}
}
class PnbDilicomBibNumeriqueControllerLoanBookActionGuestWithOtherGuestsLoansTest
extends PnbDilicomBibNumeriqueControllerLoanBookActionGuestTestCase {
public function setUp() {
parent::setUp();
foreach(range(1, 6) as $i)
$this->fixture('Class_Loan_Pnb',
['id' => 10000+$i,
'user_id' => 10000+$i,
'subscriber_id' => '',
'record_origin_id' => '',
'expected_return_date' => '2022-06-01']);
$this->_http
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v3/pnb-numerique/json/getEndedLoans?login=afi-bib&password=secretPassword&glnContractor=123456789&loanId%5B0%5D=10001&loanId%5B1%5D=10002&loanId%5B2%5D=10003&loanId%5B3%5D=10004&loanId%5B4%5D=10005&loanId%5B5%5D=10006',
['auth' => [ 'user' => 'afi-bib',
'password' => 'secretPassword']])
->answers(DilicomFixtures::getEndedLoansResponse())
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v3/pnb-numerique/json/getLoanStatus?login=afi-bib&password=secretPassword&glnContractor=123456789&orderLineId%5B0%5D=x321&returnEndedLoan=0',
['auth' => [ 'user' => 'afi-bib',
'password' => 'secretPassword']])
->answers(DilicomFixtures::getLoanStatusResponse())
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v3/pnb-numerique/json/loanBook?login=afi-bib&password=secretPassword&glnContractor=123456789&glnLoaner=2345889&UserInfo.year=1930&UserInfo.gender=H&DRMinfo.readerPass=MTA%3D&DRMinfo.readerHint=Votre+login+est+%22drm%22+et+votre+mot+de+passe+est+%220000%22&DRMinfo.readerId=drm&orderLineId=x321&loanId=10007&ean13=435465&accessMedium=DOWNLOAD&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200',
['auth' => [ 'user' => 'afi-bib',
'password' => 'secretPassword']])
->answers(DilicomFixtures::loanBookResponse())
;
$this->dispatch('/bib-numerique/loan-book/id/3');
}
/** @test */
public function shouldBeAbleToLoan() {
$this->assertNotNull(Class_Loan_Pnb::find(10007));
}
}
class PnbDilicomBibNumeriqueControllerLoanBookActionGuestWithExceededLoansTest
extends PnbDilicomBibNumeriqueControllerLoanBookActionGuestTestCase {
public function setUp() {
parent::setUp();
foreach(range(1, 6) as $i)
$this->fixture('Class_Loan_Pnb',
['id' => 10000+$i,
'user_id' => Class_Users::getIdentity()->getId(),
'subscriber_id' => '',
'record_origin_id' => '',
'expected_return_date' => '2022-06-01']);
$this->_http
->whenCalled('open_url')
->with('https://pnb-test.centprod.com/v3/pnb-numerique/json/getEndedLoans?login=afi-bib&password=secretPassword&glnContractor=123456789&loanId%5B0%5D=10001&loanId%5B1%5D=10002&loanId%5B2%5D=10003&loanId%5B3%5D=10004&loanId%5B4%5D=10005&loanId%5B5%5D=10006',
['auth' => [ 'user' => 'afi-bib',
'password' => 'secretPassword']])
->answers(DilicomFixtures::getEndedLoansResponse())
;
$this->dispatch('/bib-numerique/loan-book/id/3');
}
/** @test */
public function shouldNotBeAbleToLoan() {
$this->assertNull(Class_Loan_Pnb::find(10007));
}
}
abstract class PnbDilicomBibNumeriqueControllerSecondUserTestCase extends PnbDilicomBibNumeriqueControllerTestCase { abstract class PnbDilicomBibNumeriqueControllerSecondUserTestCase extends PnbDilicomBibNumeriqueControllerTestCase {
public function setUp() { public function setUp() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment