diff --git a/VERSIONS b/VERSIONS index 0c09c65244b6735a215994b74cb6e14a1ea65ef9..c583e0d154b0797911d4f75ca755111d4511f6a9 100644 --- a/VERSIONS +++ b/VERSIONS @@ -1,3 +1,12 @@ +18/09/2017 - v7.10.1 + + - ticket #64605 : Avis sur les notices : Correction de l'affichage des avis en attente de modération + + - ticket #64528 : SIGB Nanook : Bokeh transmet l'identifiant du site préféré lors de la demande des sites de retrait possibles pour une réservation + + - ticket #64747 : Administration : Correction du paramétrage de la boîte articles + + 11/09/2017 - v7.10.0 - ticket #51538 : Administration : Ajout de la possibilité de spécifier les jours de lancement des batchs diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index 2c25e5ca247a6f31868c11c2bb47cf43ac414a07..cac6b1bed5315bd3782e1de7fdd7cb6d117b40bc 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -692,10 +692,24 @@ class RechercheController extends ZendAfi_Controller_Action { return; $first = ''; - foreach($comm->pickupLocationsFor($user, $item) as $k => $v) { + $locations = $comm->pickupLocationsFor($user, $item); + foreach($locations as $k => $v) { $first = $first ? $first : $k; $element->addMultiOption($k, $v); } + + if (($user_location = $user->getUserIdSite()) + && array_key_exists($user_location, $locations)) { + $element->setValue($user_location); + return; + } + + if (($requested_location = $this->_getParam('code_annexe')) + && array_key_exists($requested_location, $locations)) { + $element->setValue($requested_location); + return; + } + if ($first) $element->setValue($first); } diff --git a/library/Class/CosmoVar.php b/library/Class/CosmoVar.php index 96e289ba85f47622efcb8f6758e8b529d7194ed4..2a816f4aa40910152cf6373e007313069d07c393 100644 --- a/library/Class/CosmoVar.php +++ b/library/Class/CosmoVar.php @@ -118,13 +118,18 @@ class Class_CosmoVarLoader extends Storm_Model_Loader { class Class_CosmoVar extends Storm_Model_Abstract { + const DOUBLE_SEARCH_NONE = 2; + const DOUBLE_SEARCH_ALPHA_KEY = 1; + const DOUBLE_SEARCH_IDS = 0; + + const PICKUP_LOCATION_ITEM = 0; + const PICKUP_LOCATION_CHOICE = 1; + const PICKUP_LOCATION_PATRON = 2; + protected $_table_name = 'variables'; protected $_table_primary = 'clef'; protected $_loader_class = 'Class_CosmoVarLoader'; protected $_fixed_id = true; - const DOUBLE_SEARCH_NONE = 2; - const DOUBLE_SEARCH_ALPHA_KEY = 1; - const DOUBLE_SEARCH_IDS = 0; /** * @param string $name diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index 92a1901fe6ded261762db6c079d979ba24111d42..e1c1c57c05f607a5ca01bd65add06dc7515b9a00 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -835,7 +835,7 @@ class Class_ScriptLoader { public function onFormChangeDo($node, $callback) { return $this ->addOPACPluginScript('on_form_change_do/on_form_change_do.js') - ->addJQueryReady(sprintf('$("%s").on_form_change_do(%s)', + ->addJQueryReady(sprintf('$("%s").each(function(i, el) { $(el).on_form_change_do(%s) })', $node, json_encode(['callback' => $callback]))); } diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php index b075fff1b383d091e17acbd3a593a2a4d9fb5850..d82cbdeab0f1de2c886246d4b09e3e63a2ece672 100644 --- a/library/Class/WebService/SIGB/Nanook/Service.php +++ b/library/Class/WebService/SIGB/Nanook/Service.php @@ -22,6 +22,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac protected $_provide_suggest = false, $_provide_pickup_locations = null, + $_pickup_locations_params = null, $_error_codes = []; @@ -338,23 +339,45 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac if (null !== $this->_provide_pickup_locations) return $this->_provide_pickup_locations; + // API with siteId $result = $this->ilsdiAction('GetPickupLocation', - ['bibId' => 0, 'patronId' => 0], + ['bibId' => 0, + 'patronId' => 0, + 'siteId' => 0], 'error', ''); - return $this->_provide_pickup_locations = !$this->_isNetworkError($result); + if (!$this->_isNetworkError($result)) { + $this->_pickup_locations_params = new PickupLocationsParamsWithSiteId(); + return $this->_provide_pickup_locations = true; + } + + // API without siteId + $result = $this->ilsdiAction('GetPickupLocation', + ['bibId' => 0, + 'patronId' => 0], + 'error', ''); + + if ($this->_isNetworkError($result)) + return $this->_provide_pickup_locations = false; + + $this->_pickup_locations_params = new PickupLocationsParams(); + return $this->_provide_pickup_locations = true; } public function pickupLocationsFor($user, $item) { - if (!$this->providesPickupLocations() || !$user | !$item) + if (!$this->providesPickupLocations() + || !$user + || !$item + || !$item->getCodifAnnexe()) return parent::pickupLocationsFor($user, $item); - $params = ['service' => 'GetPickupLocation', - 'bibId' => $item->getIdOrigine(), - 'patronId' => $user->getIdSigb()]; + $params = ['service' => 'GetPickupLocation', + 'bibId' => $item->getIdOrigine(), + 'patronId' => $user->getIdSigb(), + 'siteId' => $item->getCodifAnnexe()->getIdOrigine()]; - $xml = $this->httpGet($params); + $xml = $this->httpGet($this->_pickup_locations_params->paramsFor($user, $item)); if ($this->_getTagData($xml, 'error')) return []; @@ -362,4 +385,24 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac ->read($xml) ->getLocations(); } +} + + + +class PickupLocationsParams { + public function paramsFor($user, $item) { + return ['service' => 'GetPickupLocation', + 'bibId' => $item->getIdOrigine(), + 'patronId' => $user->getIdSigb()]; + } +} + + + +class PickupLocationsParamsWithSiteId extends PickupLocationsParams { + public function paramsFor($user, $item) { + $params = parent::paramsFor($user, $item); + $params['siteId'] = $item->getCodifAnnexe()->getIdOrigine(); + return $params; + } } \ No newline at end of file diff --git a/library/Class/WebService/SimpleWebClient.php b/library/Class/WebService/SimpleWebClient.php index 3673413641071804ba8fd89fa89ee1549b3f3978..1e74842440cd7602778c2e32ba9e4d34f6539d86 100644 --- a/library/Class/WebService/SimpleWebClient.php +++ b/library/Class/WebService/SimpleWebClient.php @@ -37,7 +37,7 @@ class Class_WebService_SimpleWebClient { } - public function setAuth($user, $pass) { + public function setAuth($user, $pass='') { $httpClient = Zend_Registry::get('httpClient'); $httpClient->setAuth($user, $pass); } diff --git a/library/Trait/Avis.php b/library/Trait/Avis.php index 9cce4a6f6a7cbadd79d12a4672f3579c59a8aaae..f486694fab43e5b570a24823a6c4baa4e9ba8092 100644 --- a/library/Trait/Avis.php +++ b/library/Trait/Avis.php @@ -57,21 +57,30 @@ trait Trait_Avis { public function isWaitingForModeration() { - if ($this->isWrittenByAbonne() && Class_AdminVar::get('MODO_AVIS') == 1) - return $this->isModerationOK() == false; + return $this->shouldBeModerated() + ? $this->isModerationNOK() + : false; + } - if ($this->isWrittenByBibliothecaire() && Class_AdminVar::get('MODO_AVIS_BIBLIO') == 1) - return $this->isModerationOK() == false; - return false; + public function shouldBeModerated() { + return ($this->isWrittenByAbonne() && Class_AdminVar::get('MODO_AVIS') == 1) + || ($this->isWrittenByBibliothecaire() && Class_AdminVar::get('MODO_AVIS_BIBLIO') == 1); } public function isVisibleForUser($user) { - if ($this->getUser() == null || ($user && ($this->getIdUser() == $user->ID_USER))) - return true; + if (!$this->getUser()) + return $this->hasBeenModerated(); - return $this->isWaitingForModeration() == false; + return ($user && ($this->getIdUser() == $user->ID_USER)) + ? true + : $this->hasBeenModerated(); + } + + + public function hasBeenModerated() { + return !$this->isWaitingForModeration(); } @@ -79,14 +88,17 @@ trait Trait_Avis { return $this->getAbonOuBib() == self::$AVIS_ABONNE; } + public function isOrphan() { return $this->getFlags() == self::ORPHAN_FLAG ; } + public function isArchived() { return $this->getFlags() == self::ARCHIVED_FLAG ; } + public function beWrittenByAbonne() { return $this->setAbonOuBib(self::$AVIS_ABONNE); } @@ -112,6 +124,11 @@ trait Trait_Avis { } + public function isModerationNOK() { + return $this->getStatut() == self::$STATUT_NOK; + } + + public function setModerationNOK() { return $this->setStatut(self::$STATUT_NOK); } @@ -121,4 +138,3 @@ trait Trait_Avis { return 'notices_avis' == $this->_table_name; } } -?> \ No newline at end of file diff --git a/library/ZendAfi/Form/Configuration/Widget/Articles.php b/library/ZendAfi/Form/Configuration/Widget/Articles.php index 5a93a5cf0f98bca840b171c8b3c3306f8d0bd9bb..5898df1e684c70b4db0d38270852a7597ba0f91b 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Articles.php +++ b/library/ZendAfi/Form/Configuration/Widget/Articles.php @@ -59,9 +59,9 @@ class ZendAfi_Form_Configuration_Widget_Articles extends ZendAfi_Form_Configurat Class_ScriptLoader::getInstance() ->addJQueryReady( - 'formSelectToggleVisibilityForElement("input[name=\'display_order\']", "#fieldset-datas tr:nth-child(2)", ["DateCreationDesc", "DebutPublicationDesc", "EventDebut", "Random", "CommentCount"]);' + 'formSelectToggleVisibilityForElement("input[name=\'display_order\']", "#fieldset-display_settings_group tr:nth-child(2)", ["DateCreationDesc", "DebutPublicationDesc", "EventDebut", "Random", "CommentCount"]);' - . 'formSelectToggleVisibilityForElement("input[name=\'display_order\']", "#fieldset-datas tr:nth-child(3)", "Random");' + . 'formSelectToggleVisibilityForElement("input[name=\'display_order\']", "#fieldset-display_settings_group tr:nth-child(3)", "Random");' . 'checkBoxToggleVisibilityForElement("#allow_link_on_title", $("#anchor").closest("tr"), true);'); } diff --git a/library/startup.php b/library/startup.php index f77140932c28165e547b3b8346b6beda0af71a26..08d6635f0f83c73661903e023209c1e285d4949e 100644 --- a/library/startup.php +++ b/library/startup.php @@ -82,7 +82,7 @@ class Bokeh_Engine { function setupConstants() { defineConstant('BOKEH_MAJOR_VERSION','7.10'); - defineConstant('BOKEH_RELEASE_NUMBER', BOKEH_MAJOR_VERSION . '.0'); + defineConstant('BOKEH_RELEASE_NUMBER', BOKEH_MAJOR_VERSION . '.1'); defineConstant('BOKEH_REMOTE_FILES', 'http://git.afi-sa.fr/afi/opacce/'); diff --git a/public/admin/js/global.js b/public/admin/js/global.js index 64384af5a9443a123b1e91d864a91a908a12496f..d1a37eeed668756b24891a9ed01b66017f6e95e0 100644 --- a/public/admin/js/global.js +++ b/public/admin/js/global.js @@ -172,14 +172,14 @@ function getElementsByClassName(strClass, strTag, objContElm) { } -function formSelectToggleVisibilityForElement(element, toggle, value) { - if (!(value instanceof Array)) - value = [value]; +function formSelectToggleVisibilityForElement(eventSourceSelector, objectToShowSelector, visibleForValues) { + if (!(visibleForValues instanceof Array)) + visibleForValues = [visibleForValues]; - return toggleVisibilityForElement(element, - toggle, + return toggleVisibilityForElement(eventSourceSelector, + objectToShowSelector, function(element) { - return 0 <= $.inArray(element.val(), value); + return 0 <= $.inArray(element.val(), visibleForValues); }); } @@ -197,19 +197,19 @@ function checkBoxToggleVisibilityForElement(eventSourceSelector, objectToShowSel function toggleVisibilityForElement(eventSourceSelector, objectToShowSelector, testingAlgorithm) { var objectToShow = $(objectToShowSelector); - var source_object = $(eventSourceSelector); + var sourceObject = $(eventSourceSelector); - var toggleVisibility = function() { - return testingAlgorithm(source_object) + var toggleVisibility = function(element) { + return testingAlgorithm(element) ? objectToShow.fadeIn() : objectToShow.fadeOut(); } - $(source_object).change(function() { - return toggleVisibility(); + sourceObject.change(function(event) { + return toggleVisibility($(event.target)); }); - source_object.change(); + sourceObject.change(); } diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 1fea64ff4d35754f7468f19533577e151f0718c0..b69eb4b43f9ecbc6553a2dc55688cef74a4261d9 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -1419,56 +1419,127 @@ class NoticeAjaxControllerDisponibiliteNoticeTest extends AbstractControllerTest -abstract class NoticeAjaxControllerNoticeWithAvisTestCase extends AbstractControllerTestCase { +abstract class NoticeAjaxControllerNoticeWithAvisTestCase + extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; public function setup() { parent::setup(); - Class_AdminVar::newInstanceWithId('AVIS_BIB_SEULEMENT')->setValeur(0); + Class_AdminVar::set('AVIS_BIB_SEULEMENT', 0); + Class_AdminVar::set('AVIS_MIN_SAISIE', 1); + Class_AdminVar::set('AVIS_MAX_SAISIE', 10000); - $avis_de_paul = Class_AvisNotice::newInstanceWithId(23,['entete'=>'Tres Bien', - 'note'=>'4', - 'user'=>Class_Users::newInstanceWithId(15,['login'=>'polo'])->beAbonneSIGB(), - 'avis'=>'de la balle', - 'date_avis'=>'15/03/2013', - 'clef_oeuvre'=>'potter', - 'abon_ou_bib'=>'0']) - ->setModerationOk(); + $paul = $this->fixture('Class_Users', + ['id' => 15, + 'login' => 'polo', + 'password' => 'secret']) + ->beAbonneSIGB(); - $avis_de_francois = Class_AvisNotice::newInstanceWithId(24,['entete'=>'Cool', - 'note'=>'4', - 'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(), - 'avis'=>'tres bien', - 'date_avis'=>'16/02/2013', - 'clef_oeuvre'=>'potter', - 'abon_ou_bib'=>'1']) + $avis_de_paul = $this->fixture('Class_AvisNotice', + ['id' => 23, + 'entete' => 'Tres Bien', + 'note' => '4', + 'user' => $paul, + 'avis' => 'de la balle', + 'date_avis' => '15/03/2013', + 'clef_oeuvre' => 'potter', + 'abon_ou_bib' => '0', + 'statut' => 1, + ]); + + $avis_de_francois = Class_AvisNotice::newInstanceWithId(24, + ['entete'=>'Cool', + 'note'=>'4', + 'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(), + 'avis'=>'tres bien', + 'date_avis'=>'16/02/2013', + 'clef_oeuvre'=>'potter', + 'abon_ou_bib'=>'1']) ->setModerationOk(); - Class_Notice::newInstanceWithId(34,['titre_principal'=>'Potter', - 'clef_oeuvre'=>'potter', - 'avis' => [$avis_de_paul, $avis_de_francois]]); + Class_Notice::newInstanceWithId(34, + ['titre_principal'=>'Potter', + 'clef_oeuvre'=>'potter', + 'avis' => [$avis_de_paul, + $avis_de_francois]]); } } -class NoticeAjaxControllerNoticeWithAvisEditLinkNotLoggedTest extends NoticeAjaxControllerNoticeWithAvisTestCase { +class NoticeAjaxControllerNoticeWithAvisEditLinkNotLoggedTest + extends NoticeAjaxControllerNoticeWithAvisTestCase { /** * parent::_login setup an admin account by default -> do not log at all in this test */ protected function _login() {} + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); + } + + /** @test */ public function editLinkShouldNotBePresent() { - $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); $this->assertNotXPath('//a[contains(@href, "abonne/editavisnotice")]'); } } +/** @see http://forge.afi-sa.fr/issues/64605 */ +class NoticeAjaxControllerNoticeWithAvisWithModerationAndAuthorLostNotLoggedTest + extends AbstractControllerTestCase { + + protected $_storm_default_to_volatile = true; + + /** + * parent::_login setup an admin account by default -> do not log at all in this test + */ + protected function _login() {} + + public function setup() { + parent::setup(); + + Class_AdminVar::set('AVIS_BIB_SEULEMENT', 0); + Class_AdminVar::set('AVIS_MIN_SAISIE', 1); + Class_AdminVar::set('AVIS_MAX_SAISIE', 10000); + Class_AdminVar::set('MODO_AVIS', 1); + + $avis_orphelin = $this->fixture('Class_AvisNotice', + ['id' => 23, + 'entete' => 'Tres Bien', + 'note' => '4', + 'id_user' => 24, + 'avis' => 'de la balle', + 'date_avis' => '15/03/2013', + 'clef_oeuvre' => 'potter', + 'abon_ou_bib' => '0', + 'statut' => 0, + ]); + + Class_Notice::newInstanceWithId(34, + ['titre_principal'=>'Potter', + 'clef_oeuvre'=>'potter', + 'avis' => [$avis_orphelin]]); + + $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); + } + + + /** @test */ + public function notValidatedShouldNotBePresent() { + $this->assertNotXPathContentContains('//a[contains(@href, "/viewavis/")][contains(@href, "/id/23")]', + 'Tres Bien', + $this->_response->getBody()); + } +} + + class NoticeAjaxControllerNoticeWithAvisEditLinkGuestLoggedTest extends NoticeAjaxControllerNoticeWithAvisTestCase { protected function _loginHook($account) { diff --git a/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php b/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php index 1cb371b15aaf553675669fceb365452364f3f269..2d5d41b48b1554a500b0f51b54080d922a6a1716 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php @@ -19,7 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest extends AbstractControllerTestCase { + +abstract class RechercheControllerReservationTestCase + extends AbstractControllerTestCase { + protected $_json, $_xpath, $_storm_default_to_volatile = true; @@ -28,33 +31,57 @@ class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest extends $this->fixture('Class_CodifAnnexe', ['id' => 2, - 'id_origine' => 'ANN', + 'code' => '36', + 'id_origine' => '36', 'libelle' => 'Annecy']); $this->fixture('Class_CodifAnnexe', ['id' => 3, - 'id_origine' => 'CRN', + 'code' => '37', + 'id_origine' => '37', 'libelle' => 'Cran']); - Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 1]); + $this->_xpath = new Storm_Test_XPath(); + } +} + + + +abstract class RechercheControllerReservationWithPickupChoiceTestCase + extends RechercheControllerReservationTestCase { + + public function setUp() { + parent::setUp(); + Class_CosmoVar::setValueOf('site_retrait_resa', + Class_CosmoVar::PICKUP_LOCATION_CHOICE); + } +} + + + +class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest + extends RechercheControllerReservationWithPickupChoiceTestCase { + + public function 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=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); + '//input[@name="code_annexe"][@value="36"][@checked="checked"]',$this->_json->content); } /** @test */ public function shouldRenderCranRadio() { $this->_xpath->assertXPath($this->_json->content, - '//input[@name="code_annexe"][@value="CRN"]'); + '//input[@name="code_annexe"][@value="37"]'); } @@ -66,31 +93,16 @@ class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest extends -class RechercheControllerReservationPickupAjaxActionPostTest extends AbstractControllerTestCase { - protected $_json, $_xpath; +class RechercheControllerReservationPickupAjaxActionPostTest + extends RechercheControllerReservationWithPickupChoiceTestCase { 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); + 'code_annexe' => '36']); } @@ -103,22 +115,25 @@ class RechercheControllerReservationPickupAjaxActionPostTest extends AbstractCon -class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch extends AbstractControllerTestCase { - protected $_json, $_xpath, $_storm_default_to_volatile = true; +class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch + extends RechercheControllerReservationWithPickupChoiceTestCase { public function setUp() { parent::setUp(); + $bib = $this + ->fixture('Class_IntBib', + ['id' => 1, + 'comm_sigb' => Class_IntBib::COM_NANOOK, + 'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]); + $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']]) + 'int_bib' => $bib, ]); $this->nanook = Storm_Test_ObjectWrapper::mock() @@ -132,12 +147,9 @@ class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch ZendAfi_Auth::getInstance()->logUser($this->jajm); - Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 1]); - - $this->fixture('Class_Exemplaire', - ['id' => 12]); + $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); + $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); } @@ -145,30 +157,29 @@ class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch public function parameterCodeAnnexeShouldBeUsedForReservation() { $this->assertEquals('23', $this->nanook->getAttributesForLastCallOn('reserverExemplaire')[2]); - } - - } + class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup - extends AbstractControllerTestCase { - protected $_json, $_xpath, $_storm_default_to_volatile = true; + extends RechercheControllerReservationTestCase { public function setUp() { parent::setUp(); + $bib = $this + ->fixture('Class_IntBib', + ['id' => 12, + 'comm_sigb' => Class_IntBib::COM_NANOOK, + 'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]); + $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']]) - ]); + 'int_bib' => $bib]); $this->nanook = Storm_Test_ObjectWrapper::mock() ->whenCalled('isConnected')->answers(true) @@ -183,24 +194,12 @@ class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup 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]); + Class_CosmoVar::setValueOf('site_retrait_resa', + Class_CosmoVar::PICKUP_LOCATION_PATRON); - $this->fixture('Class_Exemplaire', - ['id' => 12]); + $this->fixture('Class_Exemplaire', ['id' => 12]); - $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=ANN©_id=12',true); + $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36©_id=12', true); } @@ -214,21 +213,23 @@ class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup -class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup extends AbstractControllerTestCase { - protected $_json, $_xpath, $_storm_default_to_volatile=true; +class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup + extends RechercheControllerReservationTestCase { public function setUp() { parent::setUp(); + $bib = $this->fixture('Class_IntBib', + ['id' => 1, + 'comm_sigb' => Class_IntBib::COM_NANOOK, + 'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]); + $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']]) + 'int_bib' => $bib ]); $this->nanook = Storm_Test_ObjectWrapper::mock() @@ -236,7 +237,6 @@ class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup ex ->whenCalled('providesPickupLocations')->answers(false) ->whenCalled('reserverExemplaire')->answers(true); - Class_WebService_SIGB_Nanook::setService(['url_serveur' => 'http://bib.valensol.net', 'id_bib' => 1, 'type' => Class_IntBib::COM_NANOOK,], @@ -244,40 +244,30 @@ class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup ex ZendAfi_Auth::getInstance()->logUser($this->jajm); + Class_CosmoVar::setValueOf('site_retrait_resa', + Class_CosmoVar::PICKUP_LOCATION_ITEM); - 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->fixture('Class_Exemplaire', - ['id' => 12]); - - $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=ANN©_id=12',true); + $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=36©_id=12', true); } + /** @test */ public function itemAnnexeShouldBeUsedForReservation() { - $this->assertEquals('ANN', + $this->assertEquals('36', $this->nanook->getAttributesForLastCallOn('reserverExemplaire')[2]); } - - } - -class RechercheControllerReservationWithMailPostAction extends AbstractControllerTestCase { - protected $_sent_mails; +class RechercheControllerReservationWithMailPostAction + extends AbstractControllerTestCase { + protected + $_sent_mails, + $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); @@ -363,21 +353,24 @@ class RechercheControllerReservationWithMailPostAction extends AbstractControlle -class RechercheControllerReservationWithWebServiceKohaTest extends AbstractControllerTestCase { +class RechercheControllerReservationWithWebServiceKohaTest + extends AbstractControllerTestCase { + public function setUp() { parent::setUp(); $webservice = 'http://bib.valensol.net'; + $bib = $this->fixture('Class_IntBib', + ['id' => 1, + 'comm_sigb' => Class_IntBib::COM_KOHA, + 'comm_params' => ['url_serveur' => $webservice]]); $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]]) - ]); + 'int_bib' => $bib, + ]); ZendAfi_Auth::getInstance()->logUser($this->jajm); $this->koha = Storm_Test_ObjectWrapper::mock(); @@ -385,9 +378,9 @@ class RechercheControllerReservationWithWebServiceKohaTest extends AbstractContr ->whenCalled('getServerRoot') ->answers($webservice); - Class_WebService_SIGB_Koha::setService(['url_serveur' => $webservice, - 'id_bib' => 1, - 'type' => Class_IntBib::COM_KOHA], + Class_WebService_SIGB_Koha::setService(['url_serveur' => $webservice, + 'id_bib' => 1, + 'type' => Class_IntBib::COM_KOHA], $this->koha); } @@ -496,7 +489,9 @@ class RechercheControllerReservationWithWebServiceKohaTest extends AbstractContr -class RechercheControllerReservationWithMailFormTest extends AbstractControllerTestCase { +class RechercheControllerReservationWithMailFormTest + extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; public function setUp() { @@ -595,7 +590,6 @@ abstract class RechercheControllerReservationWithMailFormPostTestCase class RechercheControllerReservationWithMailFormInvalidPostTest extends RechercheControllerReservationWithMailFormPostTestCase{ - /** @test */ public function withEmptyPostAllFieldsShouldBeRequired() { $this->postDatas([]); @@ -720,4 +714,130 @@ class RechercheControllerReservationWithMailFormValidPostTest public function shouldRedirectToRecordView() { $this->assertRedirectTo('/opac/recherche/viewnotice/id/550171?type_doc=1'); } +} + + + +abstract class RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase + extends RechercheControllerReservationTestCase{ + + public function setUp() { + parent::setUp(); + + $bib = $this + ->fixture('Class_IntBib', + ['id' => 12, + 'comm_sigb' => Class_IntBib::COM_NANOOK, + 'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]); + + $this->jajm = $this->fixture('Class_Users', + ['id' => 1, + 'login' => 'jajm', + 'password' => 'secret', + 'idabon' => '0000007', + 'int_bib' => $bib]); + + $this->nanook = $this->mock() + ->whenCalled('isConnected')->answers(true) + ->whenCalled('providesPickupLocations')->answers(true) + + ->whenCalled('pickupLocationsFor') + ->answers(['36' => 'Annecy', + '37' => 'Cran', + '45' => 'Istres']); + + Class_WebService_SIGB_Nanook::setService(['url_serveur' => 'http://bib.valensol.net', + 'id_bib' => 12, + 'type' => Class_IntBib::COM_NANOOK,], + $this->nanook); + + ZendAfi_Auth::getInstance()->logUser($this->jajm); + + $this->fixture('Class_Exemplaire', ['id' => 12]); + } + + + 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 . '"]'); + } +} + + + +class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckPatronTest + extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { + + public function setUp() { + parent::setUp(); + + $this->nanook->whenCalled('getUserAnnexe')->answers('45'); + + $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=37©_id=12', true); + + $this->_json = json_decode($this->_response->getBody()); + } + + + /** @test */ + public function istresShouldBeChecked() { + $this->_xpath + ->assertXPath($this->_json->content, '//input[@type="radio"][@value="45"][@checked]'); + } +} + + + +class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckRequestedTest + extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { + + public function setUp() { + parent::setUp(); + + $this->nanook->whenCalled('getUserAnnexe')->answers('66'); + + $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=37©_id=12', true); + + $this->_json = json_decode($this->_response->getBody()); + } + + + /** @test */ + public function cranShouldBeChecked() { + $this->_xpath + ->assertXPath($this->_json->content, '//input[@type="radio"][@value="37"][@checked]'); + } +} + + + +class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckFirstTest + extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { + + public function setUp() { + parent::setUp(); + + $this->nanook->whenCalled('getUserAnnexe')->answers('66'); + + $this->dispatch('recherche/reservation-pickup-ajax?id_bib=2&id_origine=12&code_annexe=77©_id=12', true); + + $this->_json = json_decode($this->_response->getBody()); + } + + + /** @test */ + public function annecyShouldBeChecked() { + $this->_xpath + ->assertXPath($this->_json->content, '//input[@type="radio"][@value="36"][@checked]'); + } } \ No newline at end of file diff --git a/tests/library/Class/WebService/SIGB/NanookTest.php b/tests/library/Class/WebService/SIGB/NanookTest.php index 8f85be61f62f187e4f0d698f8a2332cec509ebf4..f439fedbbaf680e65db76dd77f02fccacc99431c 100644 --- a/tests/library/Class/WebService/SIGB/NanookTest.php +++ b/tests/library/Class/WebService/SIGB/NanookTest.php @@ -1175,20 +1175,77 @@ class NanookPickupLocationsInactiveTest extends NanookTestCase { -class NanookPickupLocationsActiveTest extends NanookTestCase { +class NanookPickupLocationsActiveWithoutSiteIdTest extends NanookTestCase { + public function setUp() { + parent::setUp(); + $map = + [// API with siteId answers errors + '/bibId/0/patronId/0/siteId/0' => NanookFixtures::htmlTomcatError(), + '/bibId/2/patronId/9/siteId/11' => NanookFixtures::htmlTomcatError(), + '/bibId/999/patronId/9/siteId/34' => NanookFixtures::htmlTomcatError(), + + // API without siteId answers ilsdi + '/bibId/0/patronId/0' => NanookFixtures::pickupLocationsPingAnswer(), + '/bibId/2/patronId/9' => NanookFixtures::pickupLocationsOkAnswer(), + '/bibId/999/patronId/9' => NanookFixtures::pickupLocationsErrorAnswer()]; + + foreach($map as $url => $answer) { + $this->_mock_web_client + ->whenCalled('open_url') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation' . $url) + ->answers($answer); + } + + $this->_mock_web_client->beStrict(); + } + + + /** @test */ + public function shouldProvidePickupLocations() { + $this->assertTrue($this->_service->providesPickupLocations()); + } + + + /** @test */ + public function locationsForRecord2AndPatron9ShouldBeFirstAndSecondLibrary() { + $user = (new Class_Entity)->setIdSigb(9); + $item = (new Class_Entity) + ->setIdOrigine(2) + ->setCodifAnnexe((new Class_Entity)->setIdOrigine(11)); + + $this->assertEquals([1 => 'First library', 2 => 'Second library'], + $this->_service->pickupLocationsFor($user, $item)); + } + + + /** @test */ + public function locationsForRecord999AndPatron9ShouldBeEmpty() { + $user = (new Class_Entity)->setIdSigb(9); + $item = (new Class_Entity) + ->setIdOrigine(999) + ->setCodifAnnexe((new Class_Entity)->setIdOrigine(34)); + + $this->assertEquals([], $this->_service->pickupLocationsFor($user, $item)); + } +} + + + + +class NanookPickupLocationsActiveWithSiteIdTest extends NanookTestCase { public function setUp() { parent::setUp(); $this->_mock_web_client ->whenCalled('open_url') - ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/0/patronId/0') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/0/patronId/0/siteId/0') ->answers(NanookFixtures::pickupLocationsPingAnswer()) ->whenCalled('open_url') - ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/2/patronId/9') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/2/patronId/9/siteId/11') ->answers(NanookFixtures::pickupLocationsOkAnswer()) ->whenCalled('open_url') - ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/999/patronId/9') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/999/patronId/9/siteId/34') ->answers(NanookFixtures::pickupLocationsErrorAnswer()) ->beStrict(); @@ -1204,7 +1261,9 @@ class NanookPickupLocationsActiveTest extends NanookTestCase { /** @test */ public function locationsForRecord2AndPatron9ShouldBeFirstAndSecondLibrary() { $user = (new Class_Entity)->setIdSigb(9); - $item = (new Class_Entity)->setIdOrigine(2); + $item = (new Class_Entity) + ->setIdOrigine(2) + ->setCodifAnnexe((new Class_Entity)->setIdOrigine(11)); $this->assertEquals([1 => 'First library', 2 => 'Second library'], $this->_service->pickupLocationsFor($user, $item)); @@ -1214,7 +1273,9 @@ class NanookPickupLocationsActiveTest extends NanookTestCase { /** @test */ public function locationsForRecord999AndPatron9ShouldBeEmpty() { $user = (new Class_Entity)->setIdSigb(9); - $item = (new Class_Entity)->setIdOrigine(999); + $item = (new Class_Entity) + ->setIdOrigine(999) + ->setCodifAnnexe((new Class_Entity)->setIdOrigine(34)); $this->assertEquals([], $this->_service->pickupLocationsFor($user, $item)); }