Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (5)
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
class RechercheController extends ZendAfi_Controller_Action { class RechercheController extends ZendAfi_Controller_Action {
protected protected
$moteur, $moteur,
$preferences; $preferences,
$_code_annexe;
public function __call($method_name, $args) { public function __call($method_name, $args) {
...@@ -389,7 +390,7 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -389,7 +390,7 @@ class RechercheController extends ZendAfi_Controller_Action {
public function reservationAction() { public function reservationAction() {
if (!$this->userConnected()) if (!$this->_userConnected())
return; return;
if ((!$library = Class_Bib::find((int)$this->_getParam('id_bib'))) if ((!$library = Class_Bib::find((int)$this->_getParam('id_bib')))
...@@ -473,7 +474,7 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -473,7 +474,7 @@ class RechercheController extends ZendAfi_Controller_Action {
public function consultationajaxAction() { public function consultationajaxAction() {
if (!$this->userConnected()) if (!$this->_userConnected())
return; return;
$title = $this->view->_('Consultation sur place'); $title = $this->view->_('Consultation sur place');
...@@ -497,38 +498,17 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -497,38 +498,17 @@ class RechercheController extends ZendAfi_Controller_Action {
} }
public function reservationajaxAction() { protected function _canItemBeReservedWithCentralizedLibrary(?int $central_library_id) : bool {
$viewRenderer = $this->getHelper('ViewRenderer'); if (!$central_library_id)
$viewRenderer->setNoRender(); return false;
if (!$user = $this->userConnected())
return;
$id_bib = (int)$this->_getParam('id_bib');
$id_exemplaire = $this->_getParam('copy_id');
$code_annexe = $this->_getParam('code_annexe', '');
if (Class_CosmoVar::isSiteRetraitResaPatronLibrary())
$code_annexe = $user->getUserIdSite();
if ( !$item = Class_Exemplaire::find($id_exemplaire))
return $this->renderPopupResult($this->view->_('Réservation'),
$this->_('Document introuvable'));
if (Class_CosmoVar::isSiteRetraitResaItemLibrary())
$code_annexe = $item->getAnnexe();
if ($item->requiresCalendarHold())
return $this->_redirect(sprintf('/recherche/reservation-calendar-ajax/id_bib/%s/copy_id/%s/code_annexe/%s',
$id_bib,
$id_exemplaire,
$code_annexe));
$ret = Class_CommSigb::getInstance()->reserveItem( $item,
$code_annexe ?? '');
$this->renderPopupResult($this->view->_('Réservation'), if (($item = Class_Exemplaire::find($this->_getParam('copy_id')))
$this->_getHoldMessage($user, $id_exemplaire, $ret)); && ($central_library_id == $item->getIdIntBib())
&& ($user = Class_Users::getIdentity())
&& ($user_intbib = $user->getIntBib())
&& $user_intbib->getUseCardNumber())
return true;
return false;
} }
...@@ -569,10 +549,12 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -569,10 +549,12 @@ class RechercheController extends ZendAfi_Controller_Action {
$reservedate, $reservedate,
$expirationdate); $expirationdate);
$item = Class_Exemplaire::find($id_exemplaire);
if ( !$comm_sigb->hasErrors()) if ( !$comm_sigb->hasErrors())
return $this->renderPopupResult($this->view->_('Réservation'), return $this->renderPopupResult($this->view->_('Réservation'),
$this->_getHoldMessage($this->userConnected(), $this->_getHoldMessage($this->_userConnected(),
$id_exemplaire, $item,
['erreur' =>''])); ['erreur' =>'']));
$form $form
...@@ -646,14 +628,29 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -646,14 +628,29 @@ class RechercheController extends ZendAfi_Controller_Action {
} }
protected function _getHoldMessage($user, $item_id, $response) { protected function _getHoldMessage(Class_Users $user, Class_Exemplaire $item, array $response) :string {
if ($response['erreur']) if ($response['erreur'] ?? false)
return $response['erreur']; return $response['erreur'];
if (isset($response['popup']) && $response['popup']) if (isset($response['popup']) && $response['popup'])
return '<iframe src="' . $response['popup'] . '"></iframe>'; return '<iframe src="' . $response['popup'] . '"></iframe>';
$content = $this->_('Votre réservation est enregistrée.<br>Nous vous informerons quand le document%s sera disponible',
$this->_getMessageNoticeLabel($item->getId()));
if ($library_libelle = $this->_getLibraryLabel($user, $item))
return $content . $this->_(' à : %s',$library_libelle);
if ($location_label = $this->_getPickupLocationLabelForUserAndItem($user, $item))
return $content . $this->_(' pour être retiré à : %s',$location_label);
return $content;
}
protected function _getPickupLocationLabelForUserAndItem(Class_Users $user, Class_Exemplaire $item) : string {
$current_hold = null; $current_hold = null;
$item_id = $item->getId();
foreach($user->getReservations() as $hold) { foreach($user->getReservations() as $hold) {
if (!$opac_item = $hold->getExemplaireOPAC()) if (!$opac_item = $hold->getExemplaireOPAC())
continue; continue;
...@@ -663,12 +660,9 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -663,12 +660,9 @@ class RechercheController extends ZendAfi_Controller_Action {
break; break;
} }
} }
return ($current_hold && $location_label = $current_hold->getPickupLocationLabel())
return ($current_hold && ($location_label = $current_hold->getPickupLocationLabel())) ? $location_label
? $this->view->_('Votre réservation est enregistrée.<br>Nous vous informerons quand le document%s sera disponible pour être retiré à : %s', : '';
$this->_getMessageNoticeLabel($item_id), $location_label)
: $this->view->_('Votre réservation est enregistrée.<br>Nous vous informerons quand le document%s sera disponible',
$this->_getMessageNoticeLabel($item_id));
} }
...@@ -689,12 +683,12 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -689,12 +683,12 @@ class RechercheController extends ZendAfi_Controller_Action {
} }
protected function userConnected() { protected function _userConnected():?Class_Users {
if (!$user = Class_Users::getIdentity()) { if ($user = Class_Users::getIdentity())
$this->_forwardToLogin($this->view->url(), ''); return $user;
return false;
} $this->_forwardToLogin($this->view->url(), '');
return $user; return null;
} }
...@@ -715,7 +709,7 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -715,7 +709,7 @@ class RechercheController extends ZendAfi_Controller_Action {
public function consultationPickupAjaxAction() { public function consultationPickupAjaxAction() {
if (!$this->userConnected()) if (!$this->_userConnected())
return ; return ;
if ($this->_request->isPost()) { if ($this->_request->isPost()) {
...@@ -739,38 +733,141 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -739,38 +733,141 @@ class RechercheController extends ZendAfi_Controller_Action {
public function reservationPickupAjaxAction() { public function reservationPickupAjaxAction() {
if (!$user = $this->_userConnected())
if (!$this->userConnected())
return ; return ;
if (($central_library_id = Class_CosmoVar::get('centralized_hold_mode')) if ( ! $item = Class_Exemplaire::find($this->_getParam('copy_id')))
&& (in_array($central_library_id,[ $this->_getParam('code_annexe'), return $this->renderPopupResult($this->view->_('Réservation'),
$this->_getParam('int_bib') $this->_('Document introuvable'));
]))) {
$this->_forward('reservationajax'); $central_library_id = Class_CosmoVar::get('centralized_hold_mode');
return;
} if ( ! $central_library_id
&& Class_CosmoVar::isSiteRetraitResaChoiceEnabled())
return $this->_pickupLocationForm($user);
if ($this->_canItemBeReservedWithCentralizedLibrary($central_library_id))
return $this->_holdItem($user, $item);
if (!Class_CosmoVar::isSiteRetraitResaChoiceEnabled() if ($this->isLoggedInUserOnSameIlsAsItem($item)
&& !$this->arePickupLocationsProvidedByComm()) { && ! $this->_arePickupLocationsProvidedByUserComm($user))
$this->_forward('reservationajax'); return $this->_holdItem($user, $item);
return ($this->isLoggedInUserOnSameIlsAsItem($item)
&& $this->_arePickupLocationsProvidedByUserComm($user))
? $this->_pickupLocationForm($user)
: $this->_holdItemUnavailable();
}
protected function _holdItemUnavailable(): void {
$this->renderPopupResult($this->_('Réservation impossible'),
$this->_('Vous ne pouvez pas réserver cet exemplaire !'));
}
protected function _holdItem(Class_Users $user, Class_Exemplaire $item): void {
$code_annexe = $this->_getCodeAnnexe($user, $item);
$response = Class_CommSigb::getInstance()->reserveItem($item,
$code_annexe);
$this->renderPopupResult($this->_('Réservation'),
$this->_getHoldMessage($user, $item, $response));
}
public function reservationajaxAction() {
$viewRenderer = $this->getHelper('ViewRenderer');
$viewRenderer->setNoRender();
if (!$user = $this->_userConnected())
return; return;
}
$id_bib = (int)$this->_getParam('id_bib');
$id_exemplaire = $this->_getParam('copy_id');
if ( !$item = Class_Exemplaire::find($id_exemplaire))
return $this->renderPopupResult($this->view->_('Réservation'),
$this->_('Document introuvable'));
$code_annexe = $this->_getCodeAnnexe($user, $item);
if ( ($central_library_id = Class_CosmoVar::get('centralized_hold_mode'))
&& (!$this->_canItemBeReservedWithCentralizedLibrary($central_library_id)
&& ($item = Class_Exemplaire::find($this->_getParam('copy_id')))
&& (!$this->isLoggedInUserOnSameIlsAsItem($item))))
return $this->renderPopupResult($this->view->_('Réservation impossible'),
$this->_('Vous ne pouvez pas réserver cet exemplaire !'));
if ($item->requiresCalendarHold())
return $this->_redirect(sprintf('/recherche/reservation-calendar-ajax/id_bib/%s/copy_id/%s/code_annexe/%s',
$id_bib,
$id_exemplaire,
$code_annexe));
$ret = Class_CommSigb::getInstance()->reserveItem( $item,
$code_annexe ?? '');
$this->renderPopupResult($this->view->_('Réservation'),
$this->_getHoldMessage($user, $item, $ret));
}
protected function _getCodeAnnexe( Class_Users $user, Class_Exemplaire $item) : string {
if ($this->_code_annexe)
return $this->_code_annexe;
$code_annexe = $this->_getParam('code_annexe', '');
if (Class_CosmoVar::isSiteRetraitResaPatronLibrary())
$code_annexe = $user->getUserIdSite();
if (Class_CosmoVar::isSiteRetraitResaItemLibrary())
$code_annexe = ($annexe = $item->getCodifAnnexe())
? $annexe->getCode()
: '';
return $this->_code_annexe = $code_annexe;
}
protected function _getLibraryLabel( Class_Users $user, Class_Exemplaire $item) : string {
$code_annexe = $this->_getParam('code_annexe', '');
if (Class_CosmoVar::isSiteRetraitResaPatronLibrary())
return $user->getLibelleBib();
if (Class_CosmoVar::isSiteRetraitResaItemLibrary())
return $item->getLibelleSite();
$code_annexe = $this->_getParam('code_annexe', '');
return ($annexe = Class_CodifAnnexe::findByCode($code_annexe))
? $annexe->getLibelle()
: '';
}
protected function _pickupLocationForm(Class_Users $user): void {
$form = $this->getReservationForm(); $form = $this->getReservationForm();
$radio = $form->getElement('code_annexe'); $radio = $form->getElement('code_annexe');
$locations = $this->arePickupLocationsProvidedByComm()
$locations = $this->_arePickupLocationsProvidedByUserComm($user)
? $this->_addLocationsFromCommTo($radio) ? $this->_addLocationsFromCommTo($radio)
: $this->_addLocationsFromCodifTo($radio); : $this->_addLocationsFromCodifTo($radio);
$this->_setLocationTo($radio, $locations); $this->_setLocationTo($radio, $locations);
if ($this->_request->isPost() if ($this->_request->isPost()
&& $form->isValid($this->_request->getPost())) { && $form->isValid($this->_request->getPost())) {
return $this->_redirect($this->view->url(['module' => 'opac', $this->_redirect($this->view->url(['module' => 'opac',
'controller' => 'recherche', 'controller' => 'recherche',
'action' => 'reservationajax', 'action' => 'reservationajax',
'render' => null, 'render' => null,
'code_annexe' => $this->_request->getPost('code_annexe')])); 'code_annexe' => $this->_request->getPost('code_annexe')]));
return;
} }
$html = []; $html = [];
...@@ -783,8 +880,23 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -783,8 +880,23 @@ class RechercheController extends ZendAfi_Controller_Action {
['class' => 'error']) ['class' => 'error'])
: $this->view->renderForm($form)); : $this->view->renderForm($form));
$this->renderPopupResult($this->view->_('Lieu de mise à disposition demandé'), $html = implode($html);
implode('',$html)); $this->renderPopupResult($this->_('Lieu de mise à disposition demandé'),
$html);
}
protected function isLoggedInUserOnSameIlsAsItem(Class_Exemplaire $item) : bool {
if (!$user = Class_Users::getIdentity())
return false;
if (!$exemplaire_intbib = $item->getIntBib())
return false;
if (!$user_intbib = $user->getIntBib())
return false;
return $exemplaire_intbib->getUrlServer() == $user_intbib->getUrlServer();
} }
...@@ -827,13 +939,12 @@ class RechercheController extends ZendAfi_Controller_Action { ...@@ -827,13 +939,12 @@ class RechercheController extends ZendAfi_Controller_Action {
} }
protected function arePickupLocationsProvidedByComm() { protected function _arePickupLocationsProvidedByUserComm(Class_Users $user):bool {
if ((!$user = Class_Users::getIdentity()) if ( !Class_CosmoVar::isSiteRetraitResaChoiceEnabled())
|| (!Class_Exemplaire::find($this->_getParam('copy_id'))))
return false; return false;
return ($comm = $user->getSIGBComm()) ? return ($comm = $user->getSIGBComm()) ?
$comm->providesPickupLocations() : false; (bool) $comm->providesPickupLocations() : false;
} }
......
...@@ -168,7 +168,9 @@ class Class_CommSigb { ...@@ -168,7 +168,9 @@ class Class_CommSigb {
protected function _isHoldCentralizedAndGetCentralLibrary(Class_Users $user, Class_Exemplaire $exemplaire ) :int { protected function _isHoldCentralizedAndGetCentralLibrary(Class_Users $user, Class_Exemplaire $exemplaire ) :int {
return ($central_library = Class_CosmoVar::get('centralized_hold_mode')) return ($central_library = Class_CosmoVar::get('centralized_hold_mode'))
&& ($user->getIdIntBib() != $central_library) && ($user->getIdIntBib() != $central_library)
&& ($exemplaire->getIdIntBib() != $user->getIdIntBib()) && (($exemplaire_intbib =$exemplaire->getIntBib())
&& ($user_intbib = $user->getIntBib())
&& $exemplaire_intbib->getUrlServer() != $user_intbib->getUrlServer())
? $central_library ? $central_library
: 0; : 0;
} }
...@@ -186,6 +188,11 @@ class Class_CommSigb { ...@@ -186,6 +188,11 @@ class Class_CommSigb {
return $this->_error($this->_('Réservation impossible : votre bibliothèque n\'autorise pas la réservation des documents de la bibliotheque centrale')); return $this->_error($this->_('Réservation impossible : votre bibliothèque n\'autorise pas la réservation des documents de la bibliotheque centrale'));
$sigb_central = $this->SIGBCentralLibraryConnect(); $sigb_central = $this->SIGBCentralLibraryConnect();
if (!$sigb_central instanceof Class_WebService_SIGB_LibraryWrapper
&& isset($sigb_central['erreur']))
return $this->_error( $sigb_central['erreur'] );
$result = $sigb_central->reserverExemplaire($user, $exemplaire, $central_library_id); $result = $sigb_central->reserverExemplaire($user, $exemplaire, $central_library_id);
if (true === ($result['statut'] ?? false)) if (true === ($result['statut'] ?? false))
...@@ -306,10 +313,12 @@ class Class_CommSigb { ...@@ -306,10 +313,12 @@ class Class_CommSigb {
return $this->withUserAndSIGBDo($std_user, $prolonger); return $this->withUserAndSIGBDo($std_user, $prolonger);
} }
public function SIGBCentralLibraryConnect() {
public function SIGBCentralLibraryConnect() : ?Class_WebService_SIGB_LibraryWrapper{
if (!$int_bib = Class_IntBib::find(Class_CosmoVar::get('centralized_hold_mode'))) if (!$int_bib = Class_IntBib::find(Class_CosmoVar::get('centralized_hold_mode')))
return $this->_error($this->_('Pas de paramètres pour la bibliothèque centralisée')); return $this->_error($this->_('Pas de paramètres pour la bibliothèque centralisée'));
if (($sigb = $int_bib->getSIGBComm()) && $sigb->isConnected()) if (($sigb = $int_bib->getSIGBComm())
&& $sigb->isConnected())
return $sigb; return $sigb;
return $this->_error($this->_("Une erreur de communication avec le serveur a fait échouer la requête. Merci de signaler ce problème à la bibliothèque.")); return $this->_error($this->_("Une erreur de communication avec le serveur a fait échouer la requête. Merci de signaler ce problème à la bibliothèque."));
} }
......
...@@ -650,9 +650,6 @@ class Class_IntBib extends Storm_Model_Abstract { ...@@ -650,9 +650,6 @@ class Class_IntBib extends Storm_Model_Abstract {
public function getUseCardNumber() : string{ public function getUseCardNumber() : string{
if(!$this->isOrphee() ||!$this->isCommKoha())
return '';
$params = $this->getCommParamsAsArray(); $params = $this->getCommParamsAsArray();
return ($params['use_card_number'] ?? ''); return ($params['use_card_number'] ?? '');
} }
......
...@@ -26,47 +26,58 @@ abstract class RechercheControllerReservationPergameTestCase extends AbstractCon ...@@ -26,47 +26,58 @@ abstract class RechercheControllerReservationPergameTestCase extends AbstractCon
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$bib_toulon = $this->fixture('Class_Bib', $bib_toulon = $this->fixture(Class_Bib::class,
['id' => 1]); ['id' => 1]);
$int_bib_toulon = $this->fixture('Class_IntBib', ['id' => 1, $int_bib_toulon = $this->fixture(Class_IntBib::class,
'comm_sigb' => Class_IntBib::COM_PERGAME, ['id' => 1,
'comm_params' => ['url_serveur' => 'bib-toulon.sud', 'comm_sigb' => Class_IntBib::COM_PERGAME,
'Autoriser_docs_disponibles' => 1], 'comm_params' => ['url_serveur' => 'bib-toulon.sud',
'id_bib' => 1]); 'Autoriser_docs_disponibles' => 1],
'id_bib' => 1]);
$bib_can = $this->fixture('Class_Bib', $bib_can = $this->fixture(Class_Bib::class,
['id' => 2]); ['id' => 2]);
$int_bib_canne = $this->fixture('Class_IntBib', ['id' => 2, $int_bib_canne = $this->fixture(Class_IntBib::class,
'comm_sigb' => Class_IntBib::COM_PERGAME, ['id' => 2,
'comm_params' => ['url_serveur' => 'bib-canne.sud', 'comm_sigb' => Class_IntBib::COM_PERGAME,
'Autoriser_docs_disponibles' => 1], 'comm_params' => ['url_serveur' => 'bib-canne.sud',
'id_bib' => 2]); 'Autoriser_docs_disponibles' => 1],
'id_bib' => 2]);
$bib_mars = $this->fixture('Class_Bib', ['id' => 3]); $this->fixture(Class_CodifAnnexe::class,
['id' => 2,
'libelle' => 'Canne',
'id_bib' => 2,
'id_origine' => 2]);
$jacques = $this->fixture('Class_Users', ['id' => 1, $bib_mars = $this->fixture(Class_Bib::class, ['id' => 3]);
'login' => 'jacques',
'password' => 'secret',
'idabon' => '1414',
'ordreabon' => '1',
'bib' => $bib_mars,
'int_bib' => $int_bib_toulon]);
$jacques = $this->fixture(Class_Users::class,
['id' => 1,
'login' => 'jacques',
'password' => 'secret',
'idabon' => '1414',
'ordreabon' => '1',
'bib' => $bib_mars,
'int_bib' => $int_bib_toulon]);
ZendAfi_Auth::getInstance()->logUser($jacques);
$this->fixture('Class_Notice', ['id' => 31084, ZendAfi_Auth::getInstance()->logUser($jacques);
'titres' => 'TITEUF TITEF FILLES FIL C00 EST NUL']);
$this->fixture('Class_Exemplaire', ['id' => 1142445, $this->fixture(Class_Notice::class,
'id_notice' => 31084, ['id' => 31084,
'code_barres' => '0229923321', 'titres' => 'TITEUF TITEF FILLES FIL C00 EST NUL']);
'id_origine' => '00021243',
'id_int_bib' => 2, $this->fixture(Class_Exemplaire::class,
'id_bib' => 2, ['id' => 1142445,
'annexe' => 2]); 'id_notice' => 31084,
'code_barres' => '0229923321',
'id_origine' => '00021243',
'id_int_bib' => 2,
'id_bib' => 2,
'annexe' => 2]);
} }
} }
...@@ -78,10 +89,9 @@ class RechercheControllerReservationPergameWithPickupToItemLibrary ...@@ -78,10 +89,9 @@ class RechercheControllerReservationPergameWithPickupToItemLibrary
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->fixture('Class_CosmoVar', ['id' => 'site_retrait_resa', Class_CosmoVar::setValueOf('site_retrait_resa', Class_CosmoVar::PICKUP_LOCATION_ITEM);
'valeur' => 0]);
$this->dispatch('recherche/reservationajax/id_bib/2/copy_id/1142445/code_annexe/2',true); $this->dispatch('recherche/reservationajax/id_bib/2/copy_id/1142445/code_annexe/2');
} }
...@@ -101,10 +111,9 @@ class RechercheControllerReservationPergameWithPickupToPatronLibrary ...@@ -101,10 +111,9 @@ class RechercheControllerReservationPergameWithPickupToPatronLibrary
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->fixture('Class_CosmoVar', ['id' => 'site_retrait_resa', Class_CosmoVar::setValueOf('site_retrait_resa', Class_CosmoVar::PICKUP_LOCATION_PATRON);
'valeur' => 2]);
$this->dispatch('recherche/reservationajax/id_bib/8/copy_id/1142445/code_annexe/18',true); $this->dispatch('recherche/reservationajax/id_bib/8/copy_id/1142445/code_annexe/18');
} }
......
...@@ -41,6 +41,24 @@ abstract class RechercheControllerReservationTestCase ...@@ -41,6 +41,24 @@ abstract class RechercheControllerReservationTestCase
'id_origine' => '37', 'id_origine' => '37',
'libelle' => 'Cran']); 'libelle' => 'Cran']);
$this->fixture(Class_Notice::class,
['id' => 124,
'titre' => 'Aimer'
]);
$this->fixture(Class_IntBib::class,
['id' => 12,
'sigb_comm' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://valensol.net']]);
$this->fixture(Class_Exemplaire::class,
['id' => 13425,
'id_origine' => 12,
'id_int_bib' => 12,
'notice_id' => 124,
'code_barres' => '1242',
]);
$this->_xpath = new Storm_Test_XPath(); $this->_xpath = new Storm_Test_XPath();
} }
} }
...@@ -67,7 +85,7 @@ class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest ...@@ -67,7 +85,7 @@ class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36',true); $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36&copy_id=13425',true);
$this->_json = json_decode($this->_response->getBody()); $this->_json = json_decode($this->_response->getBody());
} }
...@@ -105,6 +123,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest ...@@ -105,6 +123,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest
$this->postDispatch('recherche/reservation-pickup-ajax', $this->postDispatch('recherche/reservation-pickup-ajax',
['id_bib' => 2, ['id_bib' => 2,
'id_origine' => 12, 'id_origine' => 12,
'copy_id' => 13425,
'code_annexe' => '36']); 'code_annexe' => '36']);
$this->assertRedirectTo('/recherche/reservationajax/code_annexe/36'); $this->assertRedirectTo('/recherche/reservationajax/code_annexe/36');
...@@ -117,6 +136,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest ...@@ -117,6 +136,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest
$this->postDispatch('recherche/reservation-pickup-ajax', $this->postDispatch('recherche/reservation-pickup-ajax',
['id_bib' => 2, ['id_bib' => 2,
'id_origine' => 12, 'id_origine' => 12,
'copy_id' => 13425,
'code_annexe' => '36']); 'code_annexe' => '36']);
$json = json_decode($this->_response->getBody(), true); $json = json_decode($this->_response->getBody(), true);
$this->assertContains('Aucun site de retrait disponible', $json['content']); $this->assertContains('Aucun site de retrait disponible', $json['content']);
...@@ -126,7 +146,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest ...@@ -126,7 +146,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest
/** @test */ /** @test */
public function withoutAvailablePickupLocationGETResponseShouldAnswerError() { public function withoutAvailablePickupLocationGETResponseShouldAnswerError() {
Class_CodifAnnexe::deleteBy([]); Class_CodifAnnexe::deleteBy([]);
$this->dispatch('recherche/reservation-pickup-ajax/id_bib/2/id_origine/12'); $this->dispatch('recherche/reservation-pickup-ajax/id_bib/2/id_origine/12/copy_id/13425');
$json = json_decode($this->_response->getBody(), true); $json = json_decode($this->_response->getBody(), true);
$this->assertContains('Aucun site de retrait disponible', $json['content']); $this->assertContains('Aucun site de retrait disponible', $json['content']);
} }
...@@ -139,6 +159,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest ...@@ -139,6 +159,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest
$this->postDispatch('recherche/reservation-pickup-ajax/render/popup/inspector_gadget/1', $this->postDispatch('recherche/reservation-pickup-ajax/render/popup/inspector_gadget/1',
['id_bib' => 2, ['id_bib' => 2,
'id_origine' => 12, 'id_origine' => 12,
'copy_id' => 13425,
'code_annexe' => '36']); 'code_annexe' => '36']);
$this->assertNotNull($json = json_decode($this->_response->getBody(), true)); $this->assertNotNull($json = json_decode($this->_response->getBody(), true));
$this->assertContains('<script>location.reload();</script>', $json['content']); $this->assertContains('<script>location.reload();</script>', $json['content']);
...@@ -150,6 +171,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest ...@@ -150,6 +171,7 @@ class RechercheControllerReservationPickupAjaxActionPostTest
$this->postDispatch('recherche/reservation-pickup-ajax/render/popup', $this->postDispatch('recherche/reservation-pickup-ajax/render/popup',
['id_bib' => 2, ['id_bib' => 2,
'id_origine' => 12, 'id_origine' => 12,
'copy_id' => 13425,
'code_annexe' => '36']); 'code_annexe' => '36']);
$json = json_decode($this->_response->getBody(), true); $json = json_decode($this->_response->getBody(), true);
$this->assertContains('<script>location.reload();</script>', $json['content']); $this->assertContains('<script>location.reload();</script>', $json['content']);
...@@ -168,13 +190,13 @@ class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch ...@@ -168,13 +190,13 @@ class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch
parent::setUp(); parent::setUp();
$bib = $this $bib = $this
->fixture('Class_IntBib', ->fixture(Class_IntBib::class,
['id' => 1, ['id' => 1,
'comm_sigb' => Class_IntBib::COM_NANOOK, 'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]); 'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]);
$this->jajm = $this $this->jajm = $this
->fixture('Class_Users', ->fixture(Class_Users::class,
['id' => 1, ['id' => 1,
'login' => 'jajm', 'login' => 'jajm',
'password' => 'secret', 'password' => 'secret',
...@@ -254,7 +276,8 @@ class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup ...@@ -254,7 +276,8 @@ class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup
Class_CosmoVar::setValueOf('site_retrait_resa', Class_CosmoVar::setValueOf('site_retrait_resa',
Class_CosmoVar::PICKUP_LOCATION_PATRON); Class_CosmoVar::PICKUP_LOCATION_PATRON);
$this->fixture('Class_Exemplaire', ['id' => 12]); $this->fixture('Class_Exemplaire', ['id' => 12,
'id_int_bib' => 12]);
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36&copy_id=12', true); $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36&copy_id=12', true);
} }
...@@ -306,6 +329,7 @@ class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup ...@@ -306,6 +329,7 @@ class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup
$this->fixture(Class_Exemplaire::class, $this->fixture(Class_Exemplaire::class,
['id' => 12, ['id' => 12,
'id_int_bib' => 1,
'annexe' => 36]); 'annexe' => 36]);
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36&copy_id=12', true); $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36&copy_id=12', true);
...@@ -454,6 +478,13 @@ class RechercheControllerReservationWithWebServiceKohaTest ...@@ -454,6 +478,13 @@ class RechercheControllerReservationWithWebServiceKohaTest
/** @test */ /** @test */
public function reservationAjaxWithItemRequiringCalendarHoldShouldRedirectToReservationCalendarAjax() { public function reservationAjaxWithItemRequiringCalendarHoldShouldRedirectToReservationCalendarAjax() {
$this->fixture(Class_CodifAnnexe::class,
['id' => 123,
'code' => 'VS',
'libelle' => 'ValStar',
'id_int_bib' => 1,
'id_origine' => 'VS']);
$item = $this->fixture(Class_Exemplaire::class, $item = $this->fixture(Class_Exemplaire::class,
['id' => 456, ['id' => 456,
'code_barres' => 123, 'code_barres' => 123,
...@@ -1125,12 +1156,18 @@ abstract class RechercheControllerReservationPickupAjaxWithNanookPickupLocations ...@@ -1125,12 +1156,18 @@ abstract class RechercheControllerReservationPickupAjaxWithNanookPickupLocations
parent::setUp(); parent::setUp();
$bib = $this $bib = $this
->fixture('Class_IntBib', ->fixture(Class_IntBib::class,
['id' => 12, ['id' => 12,
'comm_sigb' => Class_IntBib::COM_NANOOK, 'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]); 'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]);
$this->jajm = $this->fixture('Class_Users', $this
->fixture(Class_CodifAnnexe::class,
['id' => 12,
'libelle' => 'Vanne',
'id_origine' => '12']);
$this->jajm = $this->fixture(Class_Users::class,
['id' => 1, ['id' => 1,
'login' => 'jajm', 'login' => 'jajm',
'password' => 'secret', 'password' => 'secret',
...@@ -1154,34 +1191,53 @@ abstract class RechercheControllerReservationPickupAjaxWithNanookPickupLocations ...@@ -1154,34 +1191,53 @@ abstract class RechercheControllerReservationPickupAjaxWithNanookPickupLocations
ZendAfi_Auth::getInstance()->logUser($this->jajm); ZendAfi_Auth::getInstance()->logUser($this->jajm);
$this->fixture('Class_Exemplaire', ['id' => 12]); $this->fixture(Class_Exemplaire::class,
['id' => 12,
'id_int_bib' => 12,
'int_bib' => Class_IntBib::find(12),
'annexe' => 12]);
} }
}
public function choices() {
return [[36], [37], [45]];
class RechercheControllerReservationPickupAjaxNanookPickupLocationsItemLibraryHoldTest
extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase {
public function setUp() {
parent::setUp();
$this->nanook->whenCalled('getUserAnnexe')->answers('45')
->whenCalled('reserverExemplaire')->answers(['status' => true,
'erreur' => '']);
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=37&copy_id=12', true);
$this->_json = json_decode($this->_response->getBody());
} }
/** /** @test */
* @test public function jsonReturnedVotreReservationEstEnregistree() {
* @dataProvider choices $this->assertContains($this->_json->content, 'Votre réservation est enregistrée.<br>Nous vous informerons quand le document sera disponible à : Vanne');
*/
public function choiceShouldBePresent($location_id) {
$this->_xpath
->assertXPath($this->_json->content,
'//input[@type="radio"][@value="' . $location_id . '"]');
} }
} }
class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckPatronTest class RechercheControllerReservationPickupAjaxNanookPickupLocationsPatronLibraryHoldTest
extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
Class_CosmoVar::setValueOf('site_retrait_resa',2);
$this->fixture(Class_Bib::class,
['id' => 12,
'libelle' => 'Rennes'
]);
$this->nanook->whenCalled('getUserAnnexe')->answers('45') $this->nanook->whenCalled('getUserAnnexe')->answers('45')
->whenCalled('reserverExemplaire')->answers(['status' => true, ->whenCalled('reserverExemplaire')->answers(['status' => true,
...@@ -1194,9 +1250,8 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckPatro ...@@ -1194,9 +1250,8 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckPatro
/** @test */ /** @test */
public function istresShouldBeChecked() { public function jsonReturnedVotreReservationEstEnregistree() {
$this->_xpath $this->assertContains($this->_json->content, 'Votre réservation est enregistrée.<br>Nous vous informerons quand le document sera disponible à : Rennes');
->assertXPath($this->_json->content, '//input[@type="radio"][@value="45"][@checked]');
} }
} }
...@@ -1208,7 +1263,7 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckReque ...@@ -1208,7 +1263,7 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckReque
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
Class_CosmoVar::setValueOf('site_retrait_resa',1);
$this->nanook->whenCalled('getUserAnnexe')->answers('66'); $this->nanook->whenCalled('getUserAnnexe')->answers('66');
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=37&copy_id=12', true); $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=37&copy_id=12', true);
...@@ -1217,6 +1272,22 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckReque ...@@ -1217,6 +1272,22 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckReque
} }
public function choices() {
return [[36], [37], [45]];
}
/**
* @test
* @dataProvider choices
*/
public function choiceShouldBePresent($location_id) {
$this->_xpath
->assertXPath($this->_json->content,
'//input[@type="radio"][@value="' . $location_id . '"]');
}
/** @test */ /** @test */
public function cranShouldBeChecked() { public function cranShouldBeChecked() {
$this->_xpath $this->_xpath
...@@ -1233,6 +1304,8 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsNoPrecheckTes ...@@ -1233,6 +1304,8 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsNoPrecheckTes
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
Class_CosmoVar::setValueOf('site_retrait_resa',1);
$this->nanook->whenCalled('getUserAnnexe')->answers('66'); $this->nanook->whenCalled('getUserAnnexe')->answers('66');
$this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=77&copy_id=12', true); $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=77&copy_id=12', true);
...@@ -1273,8 +1346,7 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsStrongInLabel ...@@ -1273,8 +1346,7 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsStrongInLabel
@test @test
*/ */
public function LunelShouldContainStrong() { public function LunelShouldContainStrong() {
$this->_xpath $this->assertContains($this->_json->content, 'Votre réservation est enregistrée.<br>Nous vous informerons quand le document sera disponible à : Vanne');
->assertXPath($this->_json->content, '//strong',$this->_json->content);
} }
} }
......
...@@ -123,8 +123,9 @@ class HandleBranchcodeHoldItemTest extends HandleBranchcodeTestCase { ...@@ -123,8 +123,9 @@ class HandleBranchcodeHoldItemTest extends HandleBranchcodeTestCase {
->with($this->ilsdi . '?service=HoldItem&patron_id=18&bib_id=16&item_id=&pickup_location=CHY-GB') ->with($this->ilsdi . '?service=HoldItem&patron_id=18&bib_id=16&item_id=&pickup_location=CHY-GB')
->willDo(function() {$this->expected_call = true;}); ->willDo(function() {$this->expected_call = true;});
$this->fixture('Class_Exemplaire', $this->fixture(Class_Exemplaire::class,
['id' => 16, ['id' => 16,
'id_int_bib' => 3,
'id_origine' => 16]); 'id_origine' => 16]);
} }
...@@ -147,14 +148,27 @@ class HandleBranchcodeHoldItemTest extends HandleBranchcodeTestCase { ...@@ -147,14 +148,27 @@ class HandleBranchcodeHoldItemTest extends HandleBranchcodeTestCase {
class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase { abstract class HandleBranchcodeHoldsWithItemTestCase extends HandleBranchcodeTestCase {
public function setUp(){
parent::setUp();
Class_AdminVar::set('KOHA_TRY_HOLD_ITEM', 1);
$this->fixture(Class_Exemplaire::class,
['id' => 16,
'id_int_bib' => 3]);
}
}
class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeHoldsWithItemTestCase {
protected $expected_call = []; protected $expected_call = [];
/** @test */ /** @test */
public function wsKohaShouldBeCallTwiceWithUnavailabeStatus() { public function wsKohaShouldBeCallTwiceWithUnavailabeStatus() {
Class_AdminVar::set('KOHA_TRY_HOLD_ITEM', 1);
$this->mock_web_client $this->mock_web_client
->whenCalled('open_url') ->whenCalled('open_url')
...@@ -167,9 +181,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase ...@@ -167,9 +181,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase
->beStrict(); ->beStrict();
$this->fixture('Class_Exemplaire',
['id' => 16]);
$this->dispatch('/opac/recherche/reservation-pickup-ajax/id_notice/15/id_int_bib/1/id_bib/1/copy_id/16/code_annexe/CHYGB', true); $this->dispatch('/opac/recherche/reservation-pickup-ajax/id_notice/15/id_int_bib/1/id_bib/1/copy_id/16/code_annexe/CHYGB', true);
$this->assertEquals([1,2], $this->expected_call); $this->assertEquals([1,2], $this->expected_call);
...@@ -178,7 +189,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase ...@@ -178,7 +189,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase
/** @test */ /** @test */
public function wsKohaShouldBeCallTwiceWithItemHoldNotAllowed() { public function wsKohaShouldBeCallTwiceWithItemHoldNotAllowed() {
Class_AdminVar::set('KOHA_TRY_HOLD_ITEM', 1);
$this->mock_web_client $this->mock_web_client
->whenCalled('open_url') ->whenCalled('open_url')
...@@ -195,10 +205,7 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase ...@@ -195,10 +205,7 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase
->beStrict(); ->beStrict();
$this->fixture('Class_Exemplaire', $this->dispatch('/opac/recherche/reservation-pickup-ajax/id_notice/15/id_int_bib/1/id_bib/1/copy_id/16/code_annexe/CHYGB');
['id' => 16]);
$this->dispatch('/opac/recherche/reservation-pickup-ajax/id_notice/15/id_int_bib/1/id_bib/1/copy_id/16/code_annexe/CHYGB', true);
$this->assertEquals([1,2], $this->expected_call); $this->assertEquals([1,2], $this->expected_call);
} }
...@@ -206,7 +213,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase ...@@ -206,7 +213,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase
/** @test */ /** @test */
public function wsKohaShouldBeCallOnceWithItemHold() { public function wsKohaShouldBeCallOnceWithItemHold() {
Class_AdminVar::set('KOHA_TRY_HOLD_ITEM', 1);
$this->mock_web_client $this->mock_web_client
->whenCalled('open_url') ->whenCalled('open_url')
...@@ -219,9 +225,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase ...@@ -219,9 +225,6 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase
}) })
->beStrict(); ->beStrict();
$this->fixture('Class_Exemplaire',
['id' => 16]);
$this->dispatch('/opac/recherche/reservation-pickup-ajax/id_notice/15/id_int_bib/1/id_bib/1/copy_id/16/code_annexe/CHYGB', true); $this->dispatch('/opac/recherche/reservation-pickup-ajax/id_notice/15/id_int_bib/1/id_bib/1/copy_id/16/code_annexe/CHYGB', true);
$this->assertEquals([1], $this->expected_call); $this->assertEquals([1], $this->expected_call);
......
...@@ -42,6 +42,20 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase ...@@ -42,6 +42,20 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase
$comm_params = ['url_serveur' => 'tests/fixtures/orphee.wsdl', $comm_params = ['url_serveur' => 'tests/fixtures/orphee.wsdl',
'allow_hold_available_items' => true]; 'allow_hold_available_items' => true];
$this->fixture(Class_CodifAnnexe::class,
['id' => 82,
'code' => 34,
'id_origine' => 34,
'libelle' => 'JolieVille'
]);
$this->fixture(Class_CodifAnnexe::class,
['id' => 83,
'code' => 37,
'id_origine' => 37,
'libelle' => 'WonderTown'
]);
$this->fixture(Class_Bib::class, $this->fixture(Class_Bib::class,
['id' => 34, ['id' => 34,
'mail' => 'test@jolieville.net', 'mail' => 'test@jolieville.net',
...@@ -69,9 +83,31 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase ...@@ -69,9 +83,31 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase
'nom' => 'WonderTown', 'nom' => 'WonderTown',
'nom_court' => 'WT', 'nom_court' => 'WT',
'mail' => 'intbib@WonderTown.net', 'mail' => 'intbib@WonderTown.net',
'comm_sigb' => Class_IntBib::COM_ORPHEE, 'comm_sigb' => Class_IntBib::COM_ORPHEE,
'comm_params' => array_merge($comm_params, 'comm_params' => ['url_serveur' => 'tests/fixtures/orphee.wsdl',
['use_card_number' => '1301500012'])]); 'allow_hold_available_items' => true,
'use_card_number' => '1301500012']]);
$this->fixture(Class_IntBib::class,
['id' => 37,
'id_bib' => 37,
'nom' => 'Eightth Wonder',
'nom_court' => '8THW',
'mail' => 'intbibqsdf@WonderTown.net',
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://bib.valensol.net',
'provide_pickup_locations' => true,
'use_card_number' => '1301500012']]);
$this->fixture(Class_IntBib::class,
['id' => 38,
'id_bib' => 38,
'nom' => 'Bibliothèque Sans réservations centralisées',
'nom_court' => 'BSRC',
'mail' => 'bsrc@WonderTown.net',
'comm_sigb' => Class_IntBib::COM_NANOOK,
'comm_params' => ['url_serveur' => 'http://bib.valenciel.net']]);
$this->_john_lemon = $this->_john_lemon =
$this->fixture(Class_Users::class, $this->fixture(Class_Users::class,
...@@ -83,10 +119,11 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase ...@@ -83,10 +119,11 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase
'idabon' => '130425', 'idabon' => '130425',
'password' => 'secret', 'password' => 'secret',
'mail' => 'johnlemon@abbeyroad.net', 'mail' => 'johnlemon@abbeyroad.net',
'id_int_bib' => 36, 'id_int_bib' => 37,
'int_bib' => $intbib_wondertown, 'int_bib' => $intbib_wondertown,
'bib' => $bib_wondertown, 'bib' => $bib_wondertown,
'id_bib' => 36 'id_bib' => 37,
'id_sigb' => '789789789'
]); ]);
$this->_foix = $this->_foix =
...@@ -118,11 +155,18 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase ...@@ -118,11 +155,18 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase
['id' => 2345, ['id' => 2345,
'id_notice' => 3, 'id_notice' => 3,
'id_bib' => 34, 'id_bib' => 34,
'annexe' => 34,
'id_int_bib' => 34, 'id_int_bib' => 34,
'type_doc' => Class_TypeDoc::LIVRE, 'type_doc' => Class_TypeDoc::LIVRE,
'id_origine' => 312412, 'id_origine' => 312412,
'code_barres' => '012345']); 'code_barres' => '012345']);
$this->fixture(Class_CodifAnnexe::class,
['id' => 37,
'libelle' => 'Paris',
'id_bib' => 37,
'id_origine' => 10]);
$this->fixture(Class_Exemplaire::class, $this->fixture(Class_Exemplaire::class,
['id' => 2346, ['id' => 2346,
'id_notice' => 3, 'id_notice' => 3,
...@@ -130,8 +174,19 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase ...@@ -130,8 +174,19 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase
'id_int_bib' => 37, 'id_int_bib' => 37,
'type_doc' => Class_TypeDoc::LIVRE, 'type_doc' => Class_TypeDoc::LIVRE,
'id_origine' => 312413, 'id_origine' => 312413,
'annexe' =>37,
'code_barres' => '012346']); 'code_barres' => '012346']);
$this->fixture(Class_Exemplaire::class,
['id' => 2348,
'id_notice' => 3,
'id_bib' => 37,
'id_int_bib' => 38,
'type_doc' => Class_TypeDoc::LIVRE,
'id_origine' => 312415,
'annexe' => 38,
'code_barres' => '012348']);
$this->fixture(Class_Exemplaire::class, $this->fixture(Class_Exemplaire::class,
['id' => 2347, ['id' => 2347,
'id_notice' => 3, 'id_notice' => 3,
...@@ -191,6 +246,10 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase ...@@ -191,6 +246,10 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase
->whenCalled('RsvNtcAdh') ->whenCalled('RsvNtcAdh')
->with(RsvNtcAdh::withNoticeUserNo('312412', '1301500012', 0)) ->with(RsvNtcAdh::withNoticeUserNo('312412', '1301500012', 0))
->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>'))
->whenCalled('RsvNtcAdh')
->with(RsvNtcAdh::withNoticeUserNo('312414', '1301500012', 0))
->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>')); ->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>'));
$allow_hold_available_items=true; $allow_hold_available_items=true;
...@@ -229,6 +288,39 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase ...@@ -229,6 +288,39 @@ abstract class TemplatesAbonneCentralizedHoldsTestCase
} }
class TemplatesAbonneCentralizedHoldsWithHoldModeFailuresTest extends TemplatesAbonneCentralizedHoldsTestCase {
public function _setHoldMode() {
$this->_orphee->beHoldModeItem();
return $this;
}
/** @test */
public function johnLemonReserveItem2345ShouldReturnDocumentUnavailable() {
Class_CosmoVar::setValueOf('centralized_hold_mode', 34);
ZendAfi_Auth::getInstance()->logUser($this->_john_lemon);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2345/id_origine/312412/id/123');
$this->assertContains('Votre réservation est enregistrée.<br>Nous vous informerons quand le document \'La disparition / PEREC, Georges\' sera disponible à : JolieVille',
json_decode($this->_response->getBody())->content);
}
/** @test */
public function noParameterForCentralizedLibraryShouldReturnError() {
Class_CosmoVar::setValueOf('centralized_hold_mode',39);
ZendAfi_Auth::getInstance()->logUser($this->_john_lemon);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2346/id_origine/312412/id/123');
$this->assertContains('Vous ne pouvez pas réserver cet exemplaire !',
json_decode($this->_response->getBody())->content);
}
}
class TemplatesAbonneCentralizedHoldsFailuresTest extends TemplatesAbonneCentralizedHoldsTestCase { class TemplatesAbonneCentralizedHoldsFailuresTest extends TemplatesAbonneCentralizedHoldsTestCase {
/** @test */ /** @test */
...@@ -259,7 +351,16 @@ class TemplatesAbonneCentralizedHoldsFailuresTest extends TemplatesAbonneCentral ...@@ -259,7 +351,16 @@ class TemplatesAbonneCentralizedHoldsFailuresTest extends TemplatesAbonneCentral
public function johnLemonReserveItem2346ShouldReturnReservationImpossibleNonReservable() { public function johnLemonReserveItem2346ShouldReturnReservationImpossibleNonReservable() {
ZendAfi_Auth::getInstance()->logUser($this->_john_lemon); ZendAfi_Auth::getInstance()->logUser($this->_john_lemon);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2346/id_origine/312412/id/123'); $this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2346/id_origine/312412/id/123');
$this->assertContains('Réservation impossible : l\'exemplaire n\'est pas réservable', $this->assertContains('Vous ne pouvez pas réserver cet exemplaire !',
json_decode($this->_response->getBody())->content);
}
/** @test */
public function johnLemonReserveItem23247ShouldReturnReservationEnregistree() {
ZendAfi_Auth::getInstance()->logUser($this->_john_lemon);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2347/id_origine/312414/id/123');
$this->assertContains('Votre réservation est enregistrée.',
json_decode($this->_response->getBody())->content); json_decode($this->_response->getBody())->content);
} }
...@@ -267,9 +368,10 @@ class TemplatesAbonneCentralizedHoldsFailuresTest extends TemplatesAbonneCentral ...@@ -267,9 +368,10 @@ class TemplatesAbonneCentralizedHoldsFailuresTest extends TemplatesAbonneCentral
/** @test */ /** @test */
public function henryDupontReservItem2345ShouldReturnReservationImpossibleDocumentBibliothequeCentrale() { public function henryDupontReservItem2345ShouldReturnReservationImpossibleDocumentBibliothequeCentrale() {
Class_CosmoVar::setValueOf('centralized_hold_mode',36); Class_CosmoVar::setValueOf('centralized_hold_mode',36);
$this->_henry_dupont->setIntBib(Class_IntBib::find(38));
ZendAfi_Auth::getInstance()->logUser($this->_henry_dupont); ZendAfi_Auth::getInstance()->logUser($this->_henry_dupont);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2347/id_origine/312412/id/123'); $this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2347/id_origine/312412/id/123');
$this->assertContains('votre bibliothèque n\'autorise pas la réservation des documents de la bibliotheque centrale', $this->assertContains('Vous ne pouvez pas réserver cet exemplaire !',
json_decode($this->_response->getBody())->content); json_decode($this->_response->getBody())->content);
} }
...@@ -285,6 +387,9 @@ class TemplatesAbonneCentralizedHoldsReservationSuccessTest ...@@ -285,6 +387,9 @@ class TemplatesAbonneCentralizedHoldsReservationSuccessTest
$this->_mock_transport = new MockMailTransport(); $this->_mock_transport = new MockMailTransport();
Zend_Mail::setDefaultTransport($this->_mock_transport); Zend_Mail::setDefaultTransport($this->_mock_transport);
Class_Profil::getCurrentProfil()->setMailSite('laurent@afi-sa.fr'); Class_Profil::getCurrentProfil()->setMailSite('laurent@afi-sa.fr');
$this->_john_lemon
->setIdIntBib(37)
->setIntBib(Class_IntBib::find(37));
ZendAfi_Auth::getInstance()->logUser($this->_john_lemon); ZendAfi_Auth::getInstance()->logUser($this->_john_lemon);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2345/id_origine/312412/id/123'); $this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2345/id_origine/312412/id/123');
} }
...@@ -317,7 +422,7 @@ class TemplatesAbonneCentralizedHoldsReservationSuccessTest ...@@ -317,7 +422,7 @@ class TemplatesAbonneCentralizedHoldsReservationSuccessTest
public function getRecipients(){ public function getRecipients(){
return [[0, 'test@jolieville.net'], return [[0, 'test@jolieville.net'],
[1, 'intbib@WonderTown.net'], [1, 'intbibqsdf@WonderTown.net'],
[2,'johnlemon@abbeyroad.net']]; [2,'johnlemon@abbeyroad.net']];
} }
...@@ -388,3 +493,107 @@ HTML_USER; ...@@ -388,3 +493,107 @@ HTML_USER;
$this->assertEquals(quoted_printable_decode($this->_mock_transport->getSentMails()[$email_count]->getBodyHtml()->getContent()), $mail_content); $this->assertEquals(quoted_printable_decode($this->_mock_transport->getSentMails()[$email_count]->getBodyHtml()->getContent()), $mail_content);
} }
} }
include_once 'tests/fixtures/NanookFixtures.php';
class TemplatesAbonneCentralizedHoldsReservationPickupAjaxNetworkTest
extends TemplatesAbonneCentralizedHoldsTestCase{
protected
$_mock_web_client,
$_service;
public function setUp() {
parent::setUp();
$this
->_john_lemon
->setIntBib(Class_IntBib::find(37));
$this->_mock_web_client = $this->mock()
->whenCalled('open_url')
->with('http://bib.valensol.net/service/GetPickupLocation/bibId/0/patronId/0/siteId/0')
->answers(NanookFixtures::pickupLocationsOkAnswer())
->whenCalled('open_url')
->with('http://bib.valensol.net/service/GetPickupLocation/bibId/312413/patronId/789789789/siteId/37')
->answers(NanookFixtures::pickupLocationsOkAnswer());
$_service = Class_WebService_SIGB_Nanook_Service::newInstance()
->setServerRoot('http://bib.valensol.net')
->setUseCardNumber('1301500012')
->setWebClient($this->_mock_web_client);
$this
->_service = Class_WebService_SIGB_Nanook::setService(['url_serveur' => 'http://bib.valensol.net',
'provide_pickup_locations' => true,
'use_card_number' => '1301500012',
'id_bib' => 37,
'type' => 7],
$_service);
Class_WebService_SIGB_AbstractRESTService::shouldThrowError(true);
ZendAfi_Auth::getInstance()->logUser($this->_john_lemon);
}
public function tearDown(){
$this->_service = null;
$this->_mock_web_client = null;
Class_WebService_SIGB_Nanook::reset();
Class_WebService_SIGB_AbstractRESTService::shouldThrowError(false);
parent::tearDown();
}
/** @test */
public function reservationPickupAjaxForItemDifferentIlsShouldDisplayReservationImpossible() {
Class_CosmoVar::setValueOf('site_retrait_resa', 0);
Class_CosmoVar::setValueOf('centralized_hold_mode', 34);
$this->dispatch('/recherche/reservation-pickup-ajax/id_bib/36/copy_id/2347/id_origine/312414/id/123');
$this->assertContains(json_decode( $this->_response->getBody())->content,'Vous ne pouvez pas réserver cet exemplaire !');
$this->assertContains(json_decode( $this->_response->getBody())->title,'Réservation impossible');
}
/** @test */
public function reservationPickupAjaxForItemCentralLibraryShouldDisplayReservationEnregistree() {
$this->dispatch('/recherche/reservation-pickup-ajax/id_bib/34/copy_id/2345/id_origine/312412/id/123');
$this->assertContains('Votre réservation est enregistrée',json_decode( $this->_response->getBody())->content);
$this->assertContains(json_decode( $this->_response->getBody())->title,'Réservation');
}
/** @test */
public function reservationPickupAjaxForItemSameIlsShouldShowIlsPickupLibraries() {
Class_CosmoVar::setValueOf('site_retrait_resa', 1);
$this->dispatch('/recherche/reservation-pickup-ajax/id_bib/37/copy_id/2346/id_origine/312413/id/123');
$this->assertContains('First library', json_decode($this->_response->getBody())->content);
}
/** @test */
public function reservationPickupAjaxForItemNotInIlsCentralizedHoldModeShouldCallCentralizedHold() {
Class_CosmoVar::setValueOf('site_retrait_resa', 0);
Class_CosmoVar::setValueOf('centralized_hold_mode', 36);
$this->dispatch('/recherche/reservation-pickup-ajax/id_bib/36/copy_id/2347/id_origine/312414/id/123');
$this->assertContains('Votre réservation est enregistrée',json_decode( $this->_response->getBody())->content);
}
/** @test */
public function reservationPickupAjaxForItemNotInIlsCentralizedHoldModeAndSiteRetraitResaEnabledShouldCallCentralizedHold() {
Class_CosmoVar::setValueOf('site_retrait_resa', 1);
Class_CosmoVar::setValueOf('centralized_hold_mode', 36);
$this->dispatch('/recherche/reservation-pickup-ajax/id_bib/36/copy_id/2347/id_origine/312414/id/123');
$this->assertContains('Votre réservation est enregistrée',json_decode( $this->_response->getBody())->content);
}
/** @test */
public function reservationPickupAjaxWithUnknownItemShouldContainsError() {
$this->dispatch('/recherche/reservation-pickup-ajax/id_bib/36/copy_id/7897892347/id_origine/312414/id/123');
$this->assertContains('Document introuvable',json_decode( $this->_response->getBody())->content);
}
}
...@@ -852,7 +852,7 @@ class TemplatesSearchReservationPickupAjaxConnectedUserTest ...@@ -852,7 +852,7 @@ class TemplatesSearchReservationPickupAjaxConnectedUserTest
'libelle' => 'Cran']); 'libelle' => 'Cran']);
Class_AdminVar::set('HOLD_SITE_SELECTION_CUSTOM_MESSAGE', '<b>This is an additional text message</b>')->save(); Class_AdminVar::set('HOLD_SITE_SELECTION_CUSTOM_MESSAGE', '<b>This is an additional text message</b>')->save();
$this->dispatch('/recherche/reservation-pickup-ajax/id/34/id_notice/34/id_int_bib/2/id_bib/23'); $this->dispatch('/recherche/reservation-pickup-ajax/id/34/id_notice/34/copy_id/12/id_int_bib/2/id_bib/23');
$this->_xpath = new Storm_Test_XPath(); $this->_xpath = new Storm_Test_XPath();
$this->_html = json_decode($this->_response->getBody(), true)['content']; $this->_html = json_decode($this->_response->getBody(), true)['content'];
......