Commit 2eeddcc6 authored by efalcy's avatar efalcy
Browse files

dev #13615 : fix error on webservice tests and introduce pagination on loans history (wip)

parent a4e60e33
Pipeline #3088 failed with stage
in 25 minutes and 40 seconds
......@@ -410,7 +410,7 @@ class AbonneController extends ZendAfi_Controller_Action {
public function loansHistoryAction() {
try {
$this->view->loans = $this->_user->getLoansHistory();
$this->view->loans = $this->_user->getLoansHistory($this->_getParam('page',1));
} catch (Class_WebService_Exception $e) {
$this->view->error = $e->getMessage();
$this->view->loans = new Storm_Collection();
......
......@@ -6,7 +6,7 @@ if ($this->error)
$this->error,
['class' => 'error']);
echo $this->abonne_Loans(($this->loans ? $this->loans : []), false);
echo $this->abonne_LoansHistory(($this->loans ? $this->loans : new Storm_Collection()));
$this->closeBoite();
echo $this->abonne_RetourFiche();
......
......@@ -1206,11 +1206,11 @@ class Class_Users extends Storm_Model_Abstract {
}
public function getLoansHistory() {
public function getLoansHistory($page = 1) {
if (!($emprunteur = $this->getEmprunteur()))
return new Storm_Collection();
$history = $emprunteur->getLoansHistory()->getLoans()
$history = $emprunteur->getLoansHistory($page)->getLoans()
->select(function($loan) {return $loan->getDateRetour();});
return Class_User_CardsOperationDecorator::decorateAll($history, $this);
......
......@@ -61,6 +61,7 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic
* @return Class_WebService_SimpleWebClient
*/
public function getWebClient() {
xdebug_break();
if (!isset($this->_web_client))
$this->_web_client = new Class_WebService_SimpleWebClient();
return $this->_web_client;
......
......@@ -448,9 +448,9 @@ class Class_WebService_SIGB_Emprunteur {
}
public function getLoansHistory() {
public function getLoansHistory($page) {
return $this->_service
? $this->_service->loansHistory($this)
? $this->_service->loansHistory($this,$page)
: new Class_WebService_SIGB_LoansHistory();
}
......
......@@ -225,6 +225,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
public function testCommunicationStatus() {
return (false !== strpos($this->test(), '<?xml version="1.0"'))
? static::COMMUNICATION_OK
: static::COMMUNICATION_ERROR;
......@@ -241,7 +242,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
->ilsdiGetRecords(1,
Class_WebService_SIGB_Nanook_GetRecordsResponseReader::newInstance());
$httpClient = $this->getWebClient()->getHttpClient();
$httpClient = $this->getWebClient();
$message = $httpClient->getLastRequest();
if ($response = $httpClient->getLastResponse())
$message .= $response->getStatus() . $response->getMessage() . $response->getBody();
......
......@@ -22,11 +22,10 @@
class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operation {
protected
$_line_no,
$_in_progress;
$_line_no;
public function abonne_Loans($loans, $in_progress = true) {
$this->_in_progress = $in_progress;
public function abonne_Loans($loans) {
$this->_operations = $loans;
Class_ScriptLoader::getInstance()->loadTableSorter();
return
......@@ -34,7 +33,7 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
. $this->_tag('table',
$this->renderHeader()
. $this->renderLoans(),
['class' => $this->_in_progress ? 'tablesorter loans' : 'tablesorter loans-history']);
['class' => 'tablesorter loans']);
}
......@@ -58,8 +57,8 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
$this->_('Vignette'),
$this->_('Titre'),
$this->_('Auteur'),
$this->_in_progress ? $this->_('Bibliothèque') : $this->_('Date d\'emprunt'),
$this->_in_progress ? $this->_('Retour prévu') : $this->_('Date de retour'),
$this->_('Bibliothèque'),
$this->_('Retour prévu'),
$this->_('Informations')];
}
......@@ -67,9 +66,6 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
protected function renderLoans() {
$html = '';
if (!$this->_in_progress)
$this->_operations = array_reverse($this->_operations->getArrayCopy());
foreach($this->_operations as $loan)
$html .= $this->renderLoan($loan);
......@@ -91,11 +87,11 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
. $this->_tag('td',
$this->_renderAuthor($loan, ['retour_abonne' => 'prets']))
. $this->_tag('td',
$this->_in_progress ? $loan->getBibliotheque() : $loan->getIssueDate())
$loan->getBibliotheque() )
. $this->_tag('td',
$loan->getDateRetour() . ' ' . $this->view->abonne_LoanAction($loan), ['class' => 'date_retour'])
. $this->_tag('td',
$loan->getType()),
($loan->isLate() && $this->_in_progress) ? ['class' => 'pret_en_retard'] : []);
($loan->isLate()) ? ['class' => 'pret_en_retard'] : []);
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, 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 ZendAfi_View_Helper_Abonne_LoansHistory extends ZendAfi_View_Helper_Abonne_Loans {
public function abonne_LoansHistory($loans) {
$this->_operations = array_reverse($loans->getArrayCopy());
Class_ScriptLoader::getInstance()->loadTableSorter();
return
$this->_tag('table',
$this->renderHeader()
. $this->renderLoans()
. $this->renderPaginator(),
['class' => 'tablesorter loans-history']);
}
protected function renderPaginator() {
$paginator = (new Zend_Paginator(new Zend_Paginator_Adapter_Null(count($this->_operations))))
->setItemCountPerPage(max(20, 1))
->setCurrentPageNumber(1);
return $this->view->paginationControl($paginator,
null,
null,
['url_link' => $reload_link,
'link_attribs' => [ 'data-ajax-reload' => 'true' ]
]);
}
protected function _tableColumns() {
return [$this->_('Emprunté par'),
$this->_('Support'),
$this->_('Vignette'),
$this->_('Titre'),
$this->_('Auteur'),
$this->_('Date d\'emprunt'),
$this->_('Date de retour'),
$this->_('Informations')];
}
protected function renderLoan($loan) {
return
$this->_tag('tr',
$this->_tag('td',
$loan->getUserFullName())
. $this->_tag('td',
$this->_renderDocTypeLabel($loan))
. $this->_tag('td',
$this->_renderThumbnail($loan, ['retour_abonne' => 'prets']))
. $this->_tag('td',
$this->_renderTitle($loan, ['retour_abonne' => 'prets']))
. $this->_tag('td',
$this->_renderAuthor($loan, ['retour_abonne' => 'prets']))
. $this->_tag('td',
$loan->getIssueDate())
. $this->_tag('td',
$loan->getDateRetour())
. $this->_tag('td',
$loan->getType()), []);
}
}
\ 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
*/
include_once 'tests/fixtures/NanookFixtures.php';
abstract class AbonneControllerLoansHistoryNanookTestCase extends AbstractControllerTestCase {
const BASE_URL = 'http://localhost/afi_Nanook/ilsdi/';
protected
$_emprunteur,
$_storm_default_to_volatile = true,
$_mock_web_client;
public function setUp() {
parent::setUp();
$library = $this->fixture('Class_IntBib',
['id' => 1,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => static::BASE_URL]]);
$faustine = $this->fixture('Class_Users', ['id' => 12,
'login' => 'faustine',
'password' => 'toto',
'int_bib' => $library]);
$this->_emprunteur = new Class_WebService_SIGB_Emprunteur('34', 'faustine');
$faustine->setFicheSigb(['type_comm' => Class_IntBib::COM_NANOOK,
'fiche' => $this->_emprunteur]);
ZendAfi_Auth::getInstance()->logUser($faustine);
$this->_mock_web_client = $this->mock();
$service = Class_WebService_SIGB_Nanook::getService(['url_serveur' => static::BASE_URL]);
$service->setWebClient($this->_mock_web_client);
$this->_emprunteur->setService($service);
$this->_mock_web_client
->whenCalled('open_url')
->with('http://localhost/afi_Nanook/ilsdi/service/GetLoanHistory/patronId/34?pageNumber=1')
->answers(NanookFixtures::xmlGetLoanHistoryPageOne())
->whenCalled('open_url')
->with('http://localhost/afi_Nanook/ilsdi/service/GetLoanHistory/patronId/34?pageNumber=2')
->answers(NanookFixtures::xmlGetLoanHistoryPageTwo())
->beStrict();
}
}
class AbonneControllerLoansHistoryNanookIndexTest extends AbonneControllerLoansHistoryNanookTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/abonne/loans-history',true);
}
/** @test */
public function titleShouldBeDisplayed() {
$this->assertXPathContentContains('//table', 'La femme à droite sur la photo');
}
}
class AbonneControllerLoansHistoryNanookIndexPageTwoTest extends AbonneControllerLoansHistoryNanookTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/abonne/loans-history/page/2',true);
}
/** @test */
public function titleShouldBeDisplayed() {
$this->assertXPathContentContains('//table', 'Je te croquerai');
}
}
?>
\ No newline at end of file
......@@ -1298,7 +1298,7 @@ class NanookLoanHistoryTest extends NanookTestCase {
->answers(NanookFixtures::xmlGetLoanHistoryPageTwo())
->beStrict();
$this->emprunteur = new Class_WebService_SIGB_Emprunteur('34', 'harlock');
xdebug_break();
$this->loans_history = $this->_service->loansHistory($this->emprunteur,1);
}
......
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