diff --git a/VERSIONS_HOTLINE/165447 b/VERSIONS_HOTLINE/165447 new file mode 100644 index 0000000000000000000000000000000000000000..bf4c897875aad76325b2cd3346dd7a44fbea513c --- /dev/null +++ b/VERSIONS_HOTLINE/165447 @@ -0,0 +1 @@ + - correctif #165447 : Réservation : choix par défaut n'est pas le site de l'abonné après identification \ No newline at end of file diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index 2b651b5712f554e085e39580cd28592e74507ca4..92120cdb78b79b98a2b0566aad1daab4cf58b0d9 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -729,6 +729,7 @@ class RechercheController extends ZendAfi_Controller_Action { public function reservationPickupAjaxAction() { + if (!$this->userConnected()) return ; @@ -740,10 +741,11 @@ class RechercheController extends ZendAfi_Controller_Action { $form = $this->getReservationForm(); $radio = $form->getElement('code_annexe'); - $this->arePickupLocationsProvidedByComm() ? - $this->_addLocationsFromCommTo($radio) : - $this->_addLocationsFromCodifTo($radio); + $locations = $this->arePickupLocationsProvidedByComm() + ? $this->_addLocationsFromCommTo($radio) + : $this->_addLocationsFromCodifTo($radio); + $this->_setLocationTo($radio, $locations); if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) { return $this->_redirect($this->view->url(['module' => 'opac', @@ -768,18 +770,34 @@ class RechercheController extends ZendAfi_Controller_Action { } - protected function _addLocationsFromCodifTo($element) { - foreach (Class_CodifAnnexe::findAllByPickup() as $annexe) + protected function _addLocationsFromCodifTo(Zend_Form_Element $element) : array{ + $locations = []; + + foreach (Class_CodifAnnexe::findAllByPickup() as $annexe){ $element->addMultiOption($annexe->getCode(), $annexe->getLibelle()); - $element->setValue($this->_getParam('code_annexe')); + $locations[$annexe->getCode()]=$annexe->getLibelle(); + } + return $locations; + } + + + protected function _setLocationTo(Zend_Form_Element $element, array $locations) { + $requested_location = $this->_getParam('code_annexe'); + if (($user = Class_Users::getIdentity()) + && ($user_location = $user->getUserIdSite()) + && ($locations[$user_location] ?? '')) + $requested_location = $user_location; + + if ($locations[ $requested_location ] ?? '') + $element->setValue($requested_location); } - protected function _addLocationsFromCommTo($element) { + protected function _addLocationsFromCommTo(Zend_Form_Element $element) : array{ if ((!$user = Class_Users::getIdentity()) || (!$comm = $user->getSIGBComm()) || (!$item = Class_Exemplaire::find($this->_getParam('copy_id')))) - return; + return []; $first = ''; $locations = $comm->pickupLocationsFor($user, $item); @@ -787,18 +805,7 @@ class RechercheController extends ZendAfi_Controller_Action { $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; - } + return $locations; } diff --git a/library/Class/Users.php b/library/Class/Users.php index a1b4ba01db90af03f77372e786438218261e7707..bb39bc5f239ed839f8e565cd89e396bc535bbf50 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -587,7 +587,11 @@ class Class_Users extends Storm_Model_Abstract { public function getUserIdSite() { $comm = new Class_CommSigb(); - return $comm->getUserAnnexe($this); + return + (($id = $comm->getUserAnnexe($this)) + && (!is_array( $id))) + ? $id + : $this->getLibraryCode(); } @@ -1264,10 +1268,7 @@ class Class_Users extends Storm_Model_Abstract { } - /** - * @return Class_WebService_SIGB_Emprunteur - */ - public function getEmprunteur() { + public function getEmprunteur() : Class_WebService_SIGB_Emprunteur{ return array_at('fiche', $this->getFicheSigb()); } diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 542fa823e18dec3cc77783937ce89be2609143bb..134764136114da5de57035752825acd211d25eb5 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -2676,10 +2676,7 @@ class NoticeAjaxControllerNanookSIGBWithHoldSiteEnabledTest ['id' => 10, 'exemplaires' => [$item]]); - $user_from_sigb = (new Class_Entity()) - ->whenCalledDo('getLibraryCode', function() {return 'CAV';}) - ; - + $user_from_sigb = (Class_WebService_SIGB_Emprunteur::nullInstance())->setLibraryCode('CAV'); $user = $this->fixture('Class_Users', ['id' => 789, 'login' => 'Paul', diff --git a/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php b/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php index 6067bdb0fdc0b87f90788b16e84edeeb4e669c00..766c9d6de2fd274b74885f3f94ed1e8380e252f7 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerReservationTest.php @@ -29,13 +29,13 @@ abstract class RechercheControllerReservationTestCase public function setUp() { parent::setUp(); - $this->fixture('Class_CodifAnnexe', + $this->fixture(Class_CodifAnnexe::class, ['id' => 2, 'code' => '36', 'id_origine' => '36', 'libelle' => 'Annecy']); - $this->fixture('Class_CodifAnnexe', + $this->fixture(Class_CodifAnnexe::class, ['id' => 3, 'code' => '37', 'id_origine' => '37', @@ -95,6 +95,7 @@ class RechercheControllerReservationPickupAjaxActionWithChosenPickupTest + class RechercheControllerReservationPickupAjaxActionPostTest extends RechercheControllerReservationWithPickupChoiceTestCase { @@ -200,7 +201,6 @@ class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch $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->_sent_mails = $mock_transport->getSentMails(); - } @@ -219,6 +219,7 @@ class RechercheControllerReservationPickupAjaxActionTestWithChosenPickupDispatch + class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup extends RechercheControllerReservationTestCase { @@ -264,12 +265,12 @@ class RechercheControllerReservationPickupAjaxActionTestWithPatronLibraryPickup public function getUserAnnexeResultShouldBeUsedForReservation() { $this->assertEquals('12', $this->nanook->getAttributesForLastCallOn('reserverExemplaire')[2]); - } } + class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup extends RechercheControllerReservationTestCase { @@ -287,7 +288,7 @@ class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup 'password' => 'secret', 'idabon' => '0000007', 'int_bib' => $bib - ]); + ]); $this->nanook = Storm_Test_ObjectWrapper::mock() ->whenCalled('isConnected')->answers(true) @@ -314,12 +315,12 @@ class RechercheControllerReservationPickupAjaxActionTestWithItemLibraryPickup public function itemAnnexeShouldBeUsedForReservation() { $this->assertEquals('36', $this->nanook->getAttributesForLastCallOn('reserverExemplaire')[2]); - } } + class RechercheControllerReservationWithMailPostAction extends AbstractControllerTestCase { protected @@ -452,7 +453,6 @@ class RechercheControllerReservationWithWebServiceKohaTest } - /** @test */ public function reservationAjaxWithItemRequiringCalendarHoldShouldRedirectToReservationCalendarAjax() { $this->fixture('Class_Exemplaire', @@ -592,6 +592,7 @@ class RechercheControllerReservationWithWebServiceKohaTest + class RechercheControllerReservationSerialWithWebServiceKohaTest extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; @@ -707,7 +708,6 @@ class RechercheControllerReservationCalendarAjaxTest extends AbstractControllerT public function setUp() { parent::setUp(); - $item = $this->fixture('Class_Exemplaire', ['id' => 456, 'id_origine' => 1, @@ -791,8 +791,6 @@ class RechercheControllerReservationCalendarPostTest extends AbstractControllerT $_storm_default_to_volatile = true, $_comm_sigb; - - public function setUp() { parent::setUp(); @@ -810,7 +808,7 @@ class RechercheControllerReservationCalendarPostTest extends AbstractControllerT ->with($item) ->answers(['statut' => true, 'holds' => []]) - ->beStrict(); + ->beStrict(); Class_CommSigb::setInstance($this->_comm_sigb); } @@ -860,7 +858,6 @@ class RechercheControllerReservationCalendarPostTest extends AbstractControllerT ->answers(['statut' => false, 'erreur' => 'Durée minimale requise: 30 jours']); - $this->postDispatch('/recherche/reservation-calendar-ajax/id_bib/1/copy_id/456/code_annexe/VS', ['reservedate' => '10/05/2020' , 'expirationdate' => '25/05/2020']); @@ -957,7 +954,6 @@ abstract class RechercheControllerReservationWithMailFormPostTestCase ->zoneWithChildren('214', [ 'c' => 'Test editor'], ' 0') ->render(); - $this->fixture('Class_Notice', ['id' => 550171, 'type_doc' => 1, @@ -965,7 +961,6 @@ abstract class RechercheControllerReservationWithMailFormPostTestCase 'unimarc' => $unimarc, ]); - $_SESSION['captcha_code'] = 'e2df0'; Zend_Mail::setDefaultTransport($this->_mail_transport = new MockMailTransport()); @@ -979,13 +974,13 @@ abstract class RechercheControllerReservationWithMailFormPostTestCase protected function assertElementError($path, $message) { - $this->assertXPathContentContains($path . '/following-sibling::ul[@class="errors"]/li', $message, - $this->_response->getBody()); + $this->assertXPathContentContains($path . '/following-sibling::ul[@class="errors"]/li', $message); } } + class RechercheControllerReservationWithMailFormInvalidPostTest extends RechercheControllerReservationWithMailFormPostTestCase{ @@ -1176,6 +1171,7 @@ abstract class RechercheControllerReservationPickupAjaxWithNanookPickupLocations + class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckPatronTest extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { @@ -1199,6 +1195,7 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckPatro + class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckRequestedTest extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { @@ -1222,6 +1219,7 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsPrecheckReque + class RechercheControllerReservationPickupAjaxNanookPickupLocationsNoPrecheckTest extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { @@ -1247,6 +1245,8 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsNoPrecheckTes } + + class RechercheControllerReservationPickupAjaxNanookPickupLocationsStrongInLabel extends RechercheControllerReservationPickupAjaxWithNanookPickupLocationsTestCase { @@ -1262,8 +1262,8 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsStrongInLabel /** - @see https://forge.afi-sa.net/issues/94332 - @test + @see https://forge.afi-sa.net/issues/94332 + @test */ public function LunelShouldContainStrong() { $this->_xpath @@ -1272,6 +1272,8 @@ class RechercheControllerReservationPickupAjaxNanookPickupLocationsStrongInLabel } + + class RechercheControllerReservationPickupAjaxAndNotifyByMailEnabledTest extends RechercheControllerReservationWithPickupChoiceTestCase { @@ -1290,11 +1292,11 @@ class RechercheControllerReservationPickupAjaxAndNotifyByMailEnabledTest 'comm_params' => ['url_serveur' => 'http://bib.valensol.net/cgi-bin/koha/ilsdi.pl']]); $bib = $this->fixture('Class_Bib', - ['id' => 1, - 'notify_on_new_resa' => 1, - 'mail'=>'adminpukapuka@example.com', - 'int_bib' => $int_bib]); - $this->fixture('Class_CodifAnnexe', + ['id' => 1, + 'notify_on_new_resa' => 1, + 'mail'=>'adminpukapuka@example.com', + 'int_bib' => $int_bib]); + $this->fixture(Class_CodifAnnexe::class, ['id' => 34, 'libelle'=>'BDM', 'id_origine' => 23]); @@ -1312,7 +1314,6 @@ class RechercheControllerReservationPickupAjaxAndNotifyByMailEnabledTest 'bib' => $bib ]); - $this->mock = Storm_Test_ObjectWrapper::mock() ->whenCalled('isConnected')->answers(true) ->whenCalled('open_url') @@ -1324,9 +1325,9 @@ class RechercheControllerReservationPickupAjaxAndNotifyByMailEnabledTest ->whenCalled('reserverExemplaire')->answers(['statut'=>true,'erreur'=>'']); Class_WebService_SIGB_Koha::setService(['url_serveur' => 'http://bib.valensol.net/cgi-bin/koha/ilsdi.pl', - 'id_bib' => 1, - 'type' => Class_IntBib::COM_KOHA,], - $this->mock); + 'id_bib' => 1, + 'type' => Class_IntBib::COM_KOHA,], + $this->mock); ZendAfi_Auth::getInstance()->logUser($this->jajm); @@ -1339,7 +1340,6 @@ class RechercheControllerReservationPickupAjaxAndNotifyByMailEnabledTest 'type_doc' => Class_TypeDoc::LIVRE]) ]); - $mock_transport = new MockMailTransport(); Zend_Mail::setDefaultTransport($mock_transport); @@ -1361,6 +1361,7 @@ class RechercheControllerReservationPickupAjaxAndNotifyByMailEnabledTest $this->assertEquals(1, count($this->_sent_mails)); } + /** @test */ public function mailSubjectShouldContainsJulianMonsieurSurExemplaire12341() { $this->assertContains("Julian Monsieur ? =?utf-8?Q?sur l'exemplaire 12341", @@ -1373,6 +1374,7 @@ class RechercheControllerReservationPickupAjaxAndNotifyByMailEnabledTest $this->assertContains("adminpukapuka@example.com",current($this->_sent_mails)->getRecipients()[0]); } + /** @test */ public function mailFromShouldBeMailAdminAtExampleDotCom() { $this->assertContains("admin@example.com",current($this->_sent_mails)->getFrom()); @@ -1406,8 +1408,7 @@ require_once 'tests/fixtures/KohaFixtures.php'; class RechercheControllerReservationWithWebServiceKohaAndItypesTest extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - + protected $_xpath; public function setUp() { parent::setUp(); @@ -1442,25 +1443,32 @@ PRET_VALISE", ->setWebClient($http_client); $record = - $this->fixture('Class_Notice', + $this->fixture(Class_Notice::class, ['id' => 8890, 'titre_principal' => 'Elementaire mon cher polar', 'auteur_principal' => 'Conan Doyle']); - $this->fixture('Class_Exemplaire', - ['id' => 456, - 'id_origine' => 678, - 'code_barres' => 5360246264, - 'id_int_bib' => 1, - 'notice' => $record]); + $this->fixture(Class_Exemplaire::class, + ['id' => 456, + 'id_origine' => 678, + 'code_barres' => 5360246264, + 'id_int_bib' => 1, + 'notice' => $record]); - $this->fixture('Class_CodifAnnexe', + $this->fixture(Class_CodifAnnexe::class, ['id' => 3, 'code' => 'VS', 'id_origine' => 'VS', 'libelle' => 'Cran', 'no_pickup' => '0']); + $this->fixture(Class_CodifAnnexe::class, + ['id' => 4, + 'code' => 'AN', + 'id_origine' => 'AN', + 'libelle' => 'Annecy', + 'no_pickup' => '0']); + Class_CosmoVar::setValueOf('site_retrait_resa', 1); $user = $this->fixture('Class_Users', @@ -1468,13 +1476,30 @@ PRET_VALISE", 'login' => 'jajm', 'password' => 'secret', 'int_bib' => $bib, + 'id_site' => 3, 'idabon' => '395749' ]); - + $this->_xpath = new Storm_Test_XPath(); ZendAfi_Auth::getInstance()->logUser($user); } + /** @test */ + public function reservationShouldSelectUserAnnexeByDefault() { + $emprunteur = new Class_WebService_SIGB_Emprunteur('395749', 'jajm'); + $emprunteur->setLibraryCode('VS'); + Class_CommSigb::setInstance($this->mock() + ->whenCalled('ficheAbonne') + ->answers(['fiche' => $emprunteur])); + + + $this->dispatch('/recherche/reservation-pickup-ajax/id_bib/1/copy_id/456/code_annexe/AN'); + $json = json_decode($this->_response->getBody()); + $this->_xpath + ->assertXPath($json->content, '//input[@type="radio"][@name="code_annexe"][ @value="VS"][ @checked="checked"]', $json->content); + } + + /** @test */ public function reservationAjaxWithItemRequiringCalendarHoldShouldRedirectToReservationCalendarAjaxWithoutException() { $this->postDispatch('/recherche/reservation-pickup-ajax/id_bib/1/copy_id/456/code_annexe/VS', @@ -1489,4 +1514,4 @@ PRET_VALISE", $this->dispatch('/recherche/reservationajax/id_bib/1/copy_id/456/code_annexe/VS'); $this->assertRedirectTo('/recherche/reservation-calendar-ajax/id_bib/1/copy_id/456/code_annexe/VS'); } -} \ No newline at end of file +}