Commit 1a9345aa authored by efalcy's avatar efalcy
Browse files

dev #13615 : nanook implementation of loan history

parent c6300464
'13615' =>
['Label' => $this->_('35/55 Consultation de l'historique des prêts depuis le compte lecteur Bokeh [CCTP Agglo2b] [CCTP Concarneau]'),
'Desc' => '',
'Image' => '',
'Video' => '',
'Category' => '',
'Right' => function($feature_description, $user) {return true;},
'Wiki' => '',
'Test' => '',
'Date' => '2017-12-06'],
\ No newline at end of file
- ticket #13615 : 35/55 Consultation de l'historique des prêts depuis le compte lecteur Bokeh [CCTP Agglo2b] [CCTP Concarneau]
\ No newline at end of file
......@@ -129,8 +129,8 @@ abstract class Class_WebService_SIGB_AbstractService {
}
public function loansHistory() {
return [];
public function loansHistory($emprunteur, $page) {
return new Class_WebService_SIGB_LoansHistory();
}
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* 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
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_SIGB_Nanook_GetLoanHistoryReader {
protected
$_loans = [],
$_total_count = 0,
$_loans_history,
$_current_loan;
/**
* @param string $xml
* @return Class_WebService_SIGB_*_PatronInfoReader
*/
public function parseXML($xml) {
$this->_loans_history = new Class_WebService_SIGB_LoansHistory();
$this->_xml_parser = Class_WebService_SIGB_Nanook_XMLParser::newInstance()->setElementHandler($this);
$this->_xml_parser->parse($xml);
return $this;
}
public function startLoans($attributes) {
$this->_loans_history->setTotalCount($attributes['COUNT']);
}
public function startLoan() {
$this->_current_loan = Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire();
$this->_loans_history->addLoan($this->_current_loan);
}
public function endTitle($data) {
$this->_current_loan->setTitre($data);
}
public function endItemId($data) {
$this->_current_loan->setId($data);
$this->_current_loan->getExemplaire()->setId($data);
}
public function endBibId($data) {
$this->_current_loan->getExemplaire()->setNoNotice($data);
}
public function endAuthor($data) {
$this->_current_loan->setAuteur($data);
}
public function getHistory() {
return $this->_loans_history;
}
public function endLocationLabel($data) {
$this->_current_loan->setBibliotheque($data);
}
public function endBackDate($data) {
$date = implode('/', array_reverse(explode('-', $data)));
$this->_current_loan->getExemplaire()->setDateRetour($date);
}
}
\ No newline at end of file
......@@ -135,6 +135,19 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
: $emprunteur;
}
public function providesLoansHistory() {
return true;
}
public function loansHistory($emprunteur, $page) {
$url = $this->buildQueryURL(['service' => 'GetLoanHistory',
'patronId' => $emprunteur->getId()])
.'?pageNumber='.$page;
$xml = $this->getWebClient()->open_url($url);
return (new Class_WebService_SIGB_Nanook_GetLoanHistoryReader())->parseXML($xml)->getHistory();
}
// This method is call in Class_Suggestion->save();
// Class_Suggestion->save() always return true without considering webservice answers.
......
......@@ -587,4 +587,71 @@ class NanookFixtures {
<error>PatronNotFound</error>
</GetPickupLocation>';
}
public static function xmlGetLoanHistoryPageOne() {
return '<GetLoanHistory>
<loans count="3" pageNumber="1" pageSize="2">
<loan>
<bibId>464732
</bibId>
<itemId>231645
</itemId>
<title>La femme à droite sur la photo
</title>
<author>Valentin Musso
</author>
<locationLabel>Bressuire
</locationLabel>
<loanDate>2017-08-24
</loanDate>
<backDate>2017-09-02
</backDate>
</loan>
<loan>
<bibId>448794
</bibId>
<itemId>221545
</itemId>
<title>Le caméléon
</title>
<author>Angela Behelle
</author>
<locationLabel>Bressuire
</locationLabel>
<loanDate>2017-08-24
</loanDate>
<backDate>2017-10-07
</backDate>
</loan>
</loans>
</GetLoanHistory>';
}
public static function xmlGetLoanHistoryPageTwo() {
return '
<GetLoanHistory>
<loans count="3" pageNumber="2" pageSize="2">
<loan>
<bibId>127324
</bibId>
<itemId>110155
</itemId>
<title>Je te croquerai !
</title>
<author>Lucy Cousins
</author>
<locationLabel>Bressuire
</locationLabel>
<loanDate>2017-08-02
</loanDate>
<backDate>2017-08-24
</backDate>
</loan>
</loans>
</GetLoanHistory>';
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* 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
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_SIGB_LoansHistory {
protected $_total_count=0,
$_loans = [];
public function totalCount() {
return $this->_total_count;
}
public function getLoans() {
return $this->_loans;
}
public function setTotalCount($count) {
$this->_total_count = $count;
}
public function addLoan($loan) {
$this->_loans[] = $loan;
}
}
?>
\ No newline at end of file
......@@ -1280,3 +1280,72 @@ class NanookPickupLocationsActiveWithSiteIdTest extends NanookTestCase {
$this->assertEquals([], $this->_service->pickupLocationsFor($user, $item));
}
}
class NanookLoanHistoryTest extends NanookTestCase {
protected $loans_history,
$emprunteur;
public function setUp() {
parent::setUp();
$this->_mock_web_client
->whenCalled('open_url')
->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetLoanHistory/patronId/34?pageNumber=1')
->answers(NanookFixtures::xmlGetLoanHistoryPageOne())
->whenCalled('open_url')
->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetLoanHistory/patronId/34?pageNumber=2')
->answers(NanookFixtures::xmlGetLoanHistoryPageTwo())
->beStrict();
$this->emprunteur = new Class_WebService_SIGB_Emprunteur('34', 'harlock');
xdebug_break();
$this->loans_history = $this->_service->loansHistory($this->emprunteur,1);
}
/** @test */
public function userShouldHaveThreeLoans() {
$this->assertEquals(3, $this->loans_history->totalCount());
}
/** @test */
public function oneLoanShouldContainsTitleLeCameleon() {
$this->assertEquals("Le caméléon", $this->loans_history->getLoans()[1]->getTitre());
}
/** @test */
public function firstLoanIdShouldBe231645() {
$this->assertEquals("231645", $this->loans_history->getLoans()[0]->getId());
}
/** @test */
public function noticeNumberShouldBe464732() {
$this->assertEquals(464732, $this->loans_history->getLoans()[0]->getNoNotice());
}
/** @test */
public function authorShouldBeMusso() {
$this->assertEquals('Valentin Musso', $this->loans_history->getLoans()[0]->getAuteur());
}
/** @test */
public function bibShouldBeBressuire() {
$this->assertEquals('Bressuire', $this->loans_history->getLoans()[0]->getBibliotheque());
}
/** @test */
public function backDateShouldBeSeptember2017() {
$this->assertEquals('02/09/2017', $this->loans_history->getLoans()[0]->getDateRetour());
}
/** @test */
public function secondPageLoanTitleShouldBeJeteCroquerai() {
$this->assertEquals('Je te croquerai !', $this->_service->loansHistory($this->emprunteur,2)->getLoans()[0]->getTitre());
}
}
\ No newline at end of file
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