An error occurred while loading the file. Please try again.
-
Ghislain Loas authoredc04e3531
RechercheControllerReservationTest.php 20.15 KiB
<?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 RechercheControllerReservationPickupAjaxActionWithChosenPickupTest extends AbstractControllerTestCase {
protected $_json, $_xpath;
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAnnexe')
->whenCalled('findAllBy')
->with(array('no_pickup' => '0',
'order' => 'libelle'))
->answers(array(Class_CodifAnnexe::getLoader()->newInstanceWithId(2)
->setLibelle('Annecy')
->setCode('ANN'),
Class_CodifAnnexe::getLoader()->newInstanceWithId(3)
->setLibelle('Cran')
->setCode('CRN')));
Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 1]);
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=ANN',true);
$this->_json = json_decode($this->_response->getBody());
$this->_xpath = new Storm_Test_XPath();
}
/** @test */
public function shouldRenderAnnecyCheckedRadio() {
$this->_xpath->assertXPath($this->_json->content,
'//input[@name="code_annexe"][@value="ANN"][@checked="checked"]',$this->_json->content);
}
/** @test */
public function shouldRenderCranRadio() {
$this->_xpath->assertXPath($this->_json->content,
'//input[@name="code_annexe"][@value="CRN"]');
}
/** @test */
public function layoutShouldBeEmpty() {
$this->_xpath->assertNotXPath($this->_json->content, '//div[@id="banniere"]');
}
}
class RechercheControllerReservationPickupAjaxActionPostTest extends AbstractControllerTestCase {
protected $_json, $_xpath;
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAnnexe')
->whenCalled('findAllBy')
->with(array('no_pickup' => '0',
'order' => 'libelle'))
->answers(array(Class_CodifAnnexe::getLoader()->newInstanceWithId(2)
->setLibelle('Annecy')
->setCode('ANN'),
Class_CodifAnnexe::getLoader()->newInstanceWithId(3)
->setLibelle('Cran')
->setCode('CRN')));
Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 1]);
$this->postDispatch('recherche/reservation-pickup-ajax',
['id_bib' => 2,
'id_origine' => 12,
'code_annexe' => 'ANN'],
true);
}
/** @test */
public function responseShouldRedirectToReservationajaxAction() {
$this->assertRedirect();
}
}
class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch extends AbstractControllerTestCase {
protected $_json, $_xpath;
public function setUp() {
parent::setUp();
$this->jajm = $this->fixture('Class_Users',
['id' => 1,
'login' => 'jajm',
'password' => 'secret',
'idabon' => '0000007',
'int_bib' => $this->fixture('Class_IntBib',
['id' => 1,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://bib.valensol.net']])
]);
$this->nanook = Storm_Test_ObjectWrapper::mock()
->whenCalled('isConnected')->answers(true)
->whenCalled('reserverExemplaire')->answers(true);
Class_WebService_SIGB_Nanook::setService($this->nanook);
ZendAfi_Auth::getInstance()->logUser($this->jajm);
Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 1]);
$this->fixture('Class_Exemplaire',
['id' => 12]);
$this->dispatch('recherche/reservationajax/id/11760/id_int_bib/23/id_bib/23/id_origine/594105/code_annexe/23/render/popup/copy_id/12',true);
}
/** @test */
public function parameterCodeAnnexeShouldBeUsedForReservation() {
$this->assertEquals('23',
$this->nanook->getAttributesForLastCallOn('reserverExemplaire')[2]);
}
}
class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup extends AbstractControllerTestCase {
protected $_json, $_xpath;
public function setUp() {
parent::setUp();
$this->jajm = $this->fixture('Class_Users',
['id' => 1,
'login' => 'jajm',
'password' => 'secret',
'idabon' => '0000007',
'int_bib' => $this->fixture('Class_IntBib',
['id' => 12,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://bib.valensol.net']])
]);
$this->nanook = Storm_Test_ObjectWrapper::mock()
->whenCalled('isConnected')->answers(true)
->whenCalled('reserverExemplaire')->answers(true)
->whenCalled('providesPickupLocations')->answers(false)
->whenCalled('getUserAnnexe')->answers('12');
Class_WebService_SIGB_Nanook::setService($this->nanook);
ZendAfi_Auth::getInstance()->logUser($this->jajm);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAnnexe')
->whenCalled('findAllBy')
->with(array('no_pickup' => '0',
'order' => 'libelle'))
->answers(array(Class_CodifAnnexe::getLoader()->newInstanceWithId(2)
->setLibelle('Annecy')
->setCode('ANN'),
Class_CodifAnnexe::getLoader()->newInstanceWithId(3)
->setLibelle('Cran')
->setCode('CRN')));
Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 2]);
$this->fixture('Class_Exemplaire',
['id' => 12]);
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=ANN©_id=12',true);
}
/** @test */
public function getUserAnnexeResultShouldBeUsedForReservation() {
$this->assertEquals('12',
$this->nanook->getAttributesForLastCallOn('reserverExemplaire')[2]);
}
}
class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup extends AbstractControllerTestCase {
protected $_json, $_xpath;
public function setUp() {
parent::setUp();
$this->jajm = $this->fixture('Class_Users',
['id' => 1,
'login' => 'jajm',
'password' => 'secret',
'idabon' => '0000007',
'int_bib' => $this->fixture('Class_IntBib',
['id' => 1,
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://bib.valensol.net']])
]);
$this->nanook = Storm_Test_ObjectWrapper::mock()
->whenCalled('isConnected')->answers(true)
->whenCalled('providesPickupLocations')->answers(false)
->whenCalled('reserverExemplaire')->answers(true);
Class_WebService_SIGB_Nanook::setService($this->nanook);
ZendAfi_Auth::getInstance()->logUser($this->jajm);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAnnexe')
->whenCalled('findAllBy')
->with(array('no_pickup' => '0',
'order' => 'libelle'))
->answers(array(Class_CodifAnnexe::getLoader()->newInstanceWithId(2)
->setLibelle('Annecy')
->setCode('ANN'),
Class_CodifAnnexe::getLoader()->newInstanceWithId(3)
->setLibelle('Cran')
->setCode('CRN')));
Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 0]);
$this->fixture('Class_Exemplaire',
['id' => 12]);
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=ANN©_id=12',true);
}
/** @test */
public function itemAnnexeShouldBeUsedForReservation() {
$this->assertEquals('ANN',
$this->nanook->getAttributesForLastCallOn('reserverExemplaire')[2]);
}
}
class RechercheControllerReservationWithMailPostAction extends AbstractControllerTestCase {
protected $_sent_mails;
public function setUp() {
parent::setUp();
$_SESSION["captcha_code"] = '1234';
$mock_transport = new MockMailTransport();
Zend_Mail::setDefaultTransport($mock_transport);
$this->fixture('Class_Bib', ['id' => 4, 'libelle' => 'Astrolabe']);
$this->fixture('Class_Notice', ['id' => 4,
'unimarc' => "01570nam0 2200325 450 0010007000000100033000070200017000400210027000571000041000841010008001251020007001331050018001401060006001582000106001642100075002702150044003452250023003893000125004123000020005373000137005573300265006943450018009594100051009775120027010286060033010556060060010886760012011487000045011608010039012052218529 a2-86642-370-4bbr.d8,95 EUR aFRb00347575 aFRbDLE-20031204-51138 a20031107d2003 m h0frey0103 ba| afre aFR ay z 000y| ar1 aCinema d'animationbTexte impriméedessin animé, marionnettes, images de synthèsefBernard Genin a[Paris]c\"Cahiers du cinéma\"cSCEREN-CNDPdcop. 2003gimpr. en Italie a95 p.cill., couv. ill. en coul.d19 cm2 aLes petits cahiers aLa couv. porte en plus : \"du crayon à l'ordinateur, pour ou contre Disney, Europe-Japon : le dessin animé aujourd'hui\" aBibliogr. p. 93 aSCEREN = Services, cultures, éditions, ressources pour l'éducation nationale. CNDP = Centre national de documentation pédagogique aPrésente un historique du cinéma d'animation, un survol des différentes productions nationales à travers le monde (Etats-Unis, Japon, France, Canada), les techniques du volume animé, l'image de synthèse, mais aussi l'oeuvre de Disney et le film d'auteur. b9782866423704 032525826tLes Petits cahiers (Paris)x1633-90531 aLe cinéma d'animation| 31053394aAnimation (cinéma)| 31031625aDessins animés32195497xHistoire et critique a791.431 |32547161aGeninbBernardf1946-....4070 0aFRbBNFc20031107gAFNOR2intermrc"]);
$this->postDispatch('/recherche/reservation',
['id_notice' => 4,
'id_bib' => 4,
'mail_bib' => 'zork@gloub.fr',
'user_name' => 'nanuk',
'demande' => 'je veux le livre',
'user_mail' => 'nanuk@gloub.com',
'code_saisi' => '1234',
'cote' => 'XYZ'],
true);
$this->_sent_mails = $mock_transport->getSentMails();
$this->first_mail = array_first($this->_sent_mails);
$this->first_content = $this->first_mail->getBodyText()->getContent();
$this->last_mail = array_last($this->_sent_mails);
}
/** @test */
public function twoMailsShouldHaveBeenSent() {
$this->assertEquals(2, count($this->_sent_mails));
}
/** @test */
public function firstMailFromShouldBeNanuk() {
$this->assertEquals('nanuk@gloub.com',
$this->first_mail->getFrom());
}
/** @test */
public function firstMailSubjectShouldBeDemandeDeReservation() {
$this->assertContains('Demande de réservation de document',
quoted_printable_decode($this->first_mail->getSubject()));
}
/** @test */
public function firstMailToShouldBeZork() {
$this->assertContains('zork@gloub.fr',
$this->first_mail->getRecipients());
}
/** @test */
public function titleShouldBePresent() {
$this->assertTrue(false !== strpos($this->first_content, 'Titre : Cinema d\'animation'));
}
/** @test */
public function authorShouldBePresent() {
$this->assertTrue(false !== strpos($this->first_content, 'Auteur : Bernard Genin'),
$this->first_content);
}
/** @test */
public function secondMailFromShouldBeNobody() {
$this->assertEquals('nobody@noreply.fr',
$this->last_mail->getFrom());
}
/** @test */
public function secondMailToShouldBeNanuk() {
$this->assertContains('nanuk@gloub.com',
$this->last_mail->getRecipients());
}
}
class RechercheControllerReservationWithWebServiceKohaTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$webservice = 'http://bib.valensol.net';
$this->jajm = $this->fixture('Class_Users',
['id' => 1,
'login' => 'jajm',
'password' => 'secret',
'int_bib' => $this->fixture('Class_IntBib',
['id' => 1,
'comm_sigb' => Class_IntBib::COM_KOHA,
'comm_params' => ['url_serveur' => $webservice]])
]);
ZendAfi_Auth::getInstance()->logUser($this->jajm);
$this->koha = Storm_Test_ObjectWrapper::mock();
$this->koha
->whenCalled('getServerRoot')
->answers($webservice);
Class_WebService_SIGB_Koha::setService(['url_serveur' => $webservice,
'id_bib' => 1,
'type' => Class_IntBib::COM_KOHA],
$this->koha);
}
protected function dispatchAndCheckContentEquals($expected) {
$this->dispatch('/recherche/reservationajax/id_bib/1/copy_id/456/code_annexe/VS',
true);
$this->json = json_decode($this->_response->getBody());
$this->assertEquals($expected, $this->json->content);
}
/** @test */
public function withMatchingHoldMessageShouldContainsPickupLocation() {
$item = $this->fixture('Class_Exemplaire',
['id' => 456,
'code_barres' => 123,
'id_int_bib' => 1]);
$response = $this->_prepareEmprunteurHolding($item, 'Valensole');
$expected_message = 'Votre réservation est enregistrée.<br>Nous vous informerons quand le document sera disponible pour être retiré à : Valensole';
$this->_dispatchWithEmprunteurAndAssertContentEquals($response,
$expected_message);
}
/** @test */
public function withMatchingHoldAndRecordMessageShouldContainsPickupLocationAndRecordTitleAuthor() {
$exemplaire = $this->fixture('Class_Exemplaire',
['id' => 456,
'code_barres' => 123,
'id_int_bib' => 1,
'notice' => $this->fixture('Class_Notice',
['id' => 8890,
'titre_principal' => 'Arcadia',
'auteur_principal' => 'Matsumoto'])]);
$this->_dispatchWithEmprunteurAndAssertContentEquals(
$this->_prepareEmprunteurHolding($exemplaire, 'Valensole'),
'Votre réservation est enregistrée.<br>Nous vous informerons quand le document \'Arcadia / Matsumoto\' sera disponible pour être retiré à : Valensole');
}
/** @test */
public function withoutMatchingHoldMessageShouldContainsDocumentNotFound() {
$this->_dispatchWithEmprunteurAndAssertContentEquals(
$this->_prepareEmprunteurHolding(null, 'Valensole'),
'Document introuvable');
}
/** @test */
public function withMatchingHoldAndNoPickupLocationShouldNotContainsPickupLocation() {
$this->_dispatchWithEmprunteurAndAssertContentEquals(
$this->_prepareEmprunteurHolding($this->fixture('Class_Exemplaire', ['id' => 456]),
null),
'Votre réservation est enregistrée.<br>Nous vous informerons quand le document sera disponible');
}
protected function _prepareEmprunteurHolding($item, $pickup_label) {
$this->jajm->setIdabon(395749);
$exemplaire = (new Class_WebService_SIGB_Exemplaire(2))
->setExemplaireOPAC($item);
$hold = new Class_WebService_SIGB_Reservation(2, $exemplaire);
$hold->setPickupLocationLabel($pickup_label)
->setCodeBarre(123);
$emprunteur_jajm = Class_WebService_SIGB_Emprunteur::newInstance(2, 'jajm');
$emprunteur_jajm->reservationsAdd($hold);
return $emprunteur_jajm;
}
protected function _dispatchWithEmprunteurAndAssertContentEquals($emprunteur, $content) {
$this->koha
->whenCalled('isConnected')->answers(true)
->whenCalled('reserverExemplaire')->answers(['statut' => true,
'erreur' => '',
'popup' => false])
->whenCalled('getEmprunteur')->answers($emprunteur);
$this->dispatchAndCheckContentEquals($content);
}
/** @test */
public function popupResultContentWithWebServiceErrorShouldContainsErreurDeCommunication() {
$this->jajm->setIdabon(395749);
$this->_prepareEmprunteurHolding($this->fixture('Class_Exemplaire', ['id' => 456]),
'Valensole');
$this->koha->whenCalled('isConnected')->answers(false);
$this->dispatchAndCheckContentEquals("Une erreur de communication avec le serveur a fait échouer la requête. Merci de signaler ce problème à la bibliothèque.");
}
/** @test */
public function withoutIdAbonpopupResultContentShouldContainsVousDevezVousConnecterSousVotreNumeroDeCarte() {
$this->dispatchAndCheckContentEquals("Vous devez vous connecter sous votre numéro de carte pour effectuer une réservation.");
}
}
class RechercheControllerReservationWithMailFormTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_Bib', ['id' => 88, 'libelle' => 'My Library', 'mail' => 'my@library.com']);
Class_Bib::beVolatile();
$this->dispatch('/recherche/reservation/id/550171/id_int_bib/88/id_bib/88/id_notice/550171/cote/P+TRA', true);
}
/** @test */
public function bibIdShouldBePresentInForm() {
$this->assertXPath('//input[@type="hidden"][@name="id_bib"][@value="88"]');
}
/** @test */
public function bibMailShouldBePresentInForm() {
$this->assertXPath('//input[@type="hidden"][@name="mail_bib"][@value="my@library.com"]', $this->_response->getBody());
}
/** @test */
public function bibNameShouldBePresentInForm() {
$this->assertXPath('//input[@type="text"][@name="bib_name"][@value="My Library"]', $this->_response->getBody());
}
/** @test */
public function noticeIdShouldBePresentInForm() {
$this->assertXPath('//input[@type="hidden"][@name="id_notice"][@value="550171"]');
}
}
?>