diff --git a/VERSIONS_HOTLINE/64528 b/VERSIONS_HOTLINE/64528 new file mode 100644 index 0000000000000000000000000000000000000000..41a593004b2a8d6812d76800189b19640491b557 --- /dev/null +++ b/VERSIONS_HOTLINE/64528 @@ -0,0 +1 @@ + - 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 \ No newline at end of file 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/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/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)); }