Commit bea83329 authored by Ghislain Loas's avatar Ghislain Loas

Merge branch 'hotline#75730_mybibapp_erreur_sur_la_recuperation_des_prets' into 'hotline'

hotline #75730 MyBibApp / user / loans : fix PNB loans rendering

See merge request afi/opacce!2673
parents 98d8934f 4fdf47ae
- ticket #75730 : MyBibApp: correction de la récupération des prêts PNB.
\ No newline at end of file
......@@ -23,7 +23,8 @@
class Api_UserController extends ZendAfi_Controller_Action {
public function preDispatch() {
parent::preDispatch();
$this->_authenticate();
if (!Class_Users::hasIdentity())
$this->_authenticate();
}
......
......@@ -104,6 +104,13 @@ class Class_Loan_Pnb extends Storm_Model_Abstract {
}
public function getNoticeOPAC() {
return ($album = $this->getAlbum())
? $album->getNotice()
: null;
}
public function setAlbum($album) {
return $this->setRecordOriginId($album->getIdOrigine());
}
......@@ -144,6 +151,12 @@ class Class_Loan_Pnb extends Storm_Model_Abstract {
}
public function getDateRetourISO8601() {
return substr($this->getDateRetour(), 0, 10);
}
public function isRenewable() {
return false;
}
......
......@@ -32,7 +32,7 @@ class ZendAfi_View_Helper_Api_Holds extends Zend_View_Helper_Abstract {
public function holdToArray($hold) {
$datas = [
'id' => $hold->getId(),
'title' => $hold->getTitre(),
'title' => strip_tags($hold->getTitre()),
'author' => $hold->getAuteur(),
'status' => $hold->getEtat(),
'held_by' => $hold->getUserFullName(),
......
......@@ -32,7 +32,7 @@ class ZendAfi_View_Helper_Api_Loans extends Zend_View_Helper_Abstract {
public function loanToArray($loan) {
$datas = [
'id' => $loan->getId(),
'title' => $loan->getTitre(),
'title' => strip_tags($loan->getTitre()),
'author' => $loan->getAuteur(),
'date_due' => $loan->getDateRetourISO8601(),
'loaned_by' => $loan->getUserFullName(),
......
......@@ -55,7 +55,7 @@ abstract class Scenario_MobileApplication_UserAccountTestCase extends AbstractCo
->setNoticeOPAC($this->fixture('Class_Notice',
['id' => 34,
'url_vignette' => 'http://img.com/potter.jpg',
'titre_principal' => 'Potter',
'titre_principal' => 'Harry Potter<br /> La chambre des secrets',
'auteur_principal' => 'J.K.R' ]));
$alice = new Class_WebService_SIGB_Emprunt('13', new Class_WebService_SIGB_Exemplaire(456));
......@@ -82,12 +82,32 @@ abstract class Scenario_MobileApplication_UserAccountTestCase extends AbstractCo
->reservationsAddAll([$afrodeezia])])
->assertSave();
Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($this->mock()
->whenCalled('open_url')
->answers(''));
$this->fixture('Class_Loan_Pnb',
['id' => 5,
'subscriber_id' => $puppy->getIdabon(),
'ongoing' => true,
'expected_return_date' => '2022-05-02T18:14:14+02:00',
'loan_date' => '2016-06-13T15:10:02+02:00',
'album' => $this->fixture('Class_Album',
['id' => 4,
'notice_id' => 5,
'id_origine' => 'Dilicom-88817216',
'titre' => 'Pinocchio'])->addAuthor('Collodi')
]);
ZendAfi_Auth::getInstance()->clearIdentity();
}
public function tearDown() {
unset($_SERVER['HTTPS']);
Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient(null);
parent::tearDown();
}
}
......@@ -114,7 +134,7 @@ class Scenario_MobileApplication_UserAccountLoansWithTokenTest extends Scenario_
/** @test */
public function responseShouldContainsPotterLoan() {
$this->assertEquals(['id' => '345_12',
'title' => 'Potter',
'title' => 'Harry Potter La chambre des secrets',
'author' => 'J.K.R',
'date_due' => '1974-01-01',
'loaned_by' => 'puppy',
......@@ -126,6 +146,19 @@ class Scenario_MobileApplication_UserAccountLoansWithTokenTest extends Scenario_
}
/** @test */
public function responseShouldContainsPinocchioPnbLoan() {
$this->assertEquals(['id' => '345_5',
'title' => 'Pinocchio',
'author' => 'Collodi',
'date_due' => '2022-05-02',
'loaned_by' => 'puppy',
'library' => ''
],
$this->_json['loans'][2]);
}
/** @test */
public function responseHeaderContentTypeShouldBeApplicationJson() {
$this->assertArraySubset(['name' => 'Content-Type',
......@@ -280,7 +313,25 @@ class Scenario_MobileApplication_UserAccountLoansWithoutTokenTest extends Scenar
"Content-Type" => "application/json"]);
$loans = json_decode($this->_response->getBody(), true);
$this->assertArraySubset(['title' => 'Potter',
$this->assertArraySubset(['title' => 'Harry Potter La chambre des secrets',
'author' => 'J.K.R',
'date_due' => '1974-01-01',
'loaned_by' => 'puppy',
'library' => 'Annecy'
],
$loans['loans'][0]);
}
/** @test */
public function withSessionOpenedShouldAnswerLoans() {
ZendAfi_Auth::getInstance()->logUser(Class_Users::find(345));
$this->dispatch('/api/user/loans',
true,
["Content-Type" => "application/json"]);
$loans = json_decode($this->_response->getBody(), true);
$this->assertArraySubset(['title' => 'Harry Potter La chambre des secrets',
'author' => 'J.K.R',
'date_due' => '1974-01-01',
'loaned_by' => 'puppy',
......
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