Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Copyright (c) 2012-2023, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
include_once('Class/WebService/SIGB/Orphee/SessionStrategy.php');
include_once 'tests/library/Class/WebService/SIGB/OrpheeFixtures.php';
abstract class TemplatesAbonneCentralizedHoldsTestCase
extends AbstractControllerTestCase{
protected
$_search_client,
$_orphee,
$_henry_dupont,
$_john_lemon,
$_foix;
public function setUp() {
parent::setUp();
Class_CosmoVar::setValueOf('centralized_hold_mode', 34);
$this->_buildTemplateProfil(['id'=>1]);
$comm_params = ['url_serveur' => 'tests/fixtures/orphee.wsdl',
'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,
['id' => 34,
'mail' => 'test@jolieville.net',
'libelle' => 'JolieVille'
]);
$this->fixture(Class_IntBib::class,
['id' => 34,
'id_bib' => 34,
'nom' => 'JolieVille',
'nom_court' => 'JV',
'comm_sigb' => Class_IntBib::COM_ORPHEE,
'comm_params' => $comm_params
]);
$bib_wondertown = $this->fixture(Class_Bib::class,
['id' => 36,
'mail' => 'test@WonderTown.net',
'libelle' => 'WonderTown'
]);
$intbib_wondertown = $this->fixture(Class_IntBib::class,
['id' => 36,
'id_bib' => 36,
'nom' => 'WonderTown',
'nom_court' => 'WT',
'mail' => 'intbib@WonderTown.net',
'comm_sigb' => Class_IntBib::COM_ORPHEE,
'comm_params' => ['url_serveur' => 'tests/fixtures/orphee.wsdl',
'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->fixture(Class_Users::class,
['id' => 142,
'idAbon' => '',
'nom' => 'Lemon',
'prenom' => 'John',
'login' => 'uselogon',
'idabon' => '130425',
'password' => 'secret',
'mail' => 'johnlemon@abbeyroad.net',
'id_int_bib' => 37,
'int_bib' => $intbib_wondertown,
'bib' => $bib_wondertown,
'id_bib' => 37,
'id_sigb' => '789789789'
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
]);
$this->_foix =
$this->fixture(Class_Users::class,
['id' => 143,
'idAbon' => '1301500012',
'nom' => 'FOIX',
'prenom' => 'FPV',
'login' => '1301500012',
'password' => 's3cr3t',
'id_int_bib' => 34,
'id_bib' => 34
]);
$this->fixture(Class_Notice::class,
['id' => 3,
'titre' => 'La disparition',
'auteurs' => 'Georges PEREC',
'unimarc' => (new Class_NoticeUnimarc_Fluent)
->zoneWithChildren('200', ['a' => 'La disparition',
'f' => 'PEREC, Georges',
't' => 't. 1'])
->render(),
'type_doc' => Class_TypeDoc::LIVRE,
]);
$this->fixture(Class_Exemplaire::class,
['id' => 2345,
'id_notice' => 3,
'id_bib' => 34,
'id_int_bib' => 34,
'type_doc' => Class_TypeDoc::LIVRE,
'id_origine' => 312412,
'code_barres' => '012345']);
$this->fixture(Class_CodifAnnexe::class,
['id' => 37,
'libelle' => 'Paris',
'id_bib' => 37,
'id_origine' => 10]);
$this->fixture(Class_Exemplaire::class,
['id' => 2346,
'id_notice' => 3,
'id_bib' => 37,
'id_int_bib' => 37,
'type_doc' => Class_TypeDoc::LIVRE,
'id_origine' => 312413,
'annexe' =>37,
'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']);
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
$this->fixture(Class_Exemplaire::class,
['id' => 2347,
'id_notice' => 3,
'id_bib' => 36,
'id_int_bib' => 36,
'type_doc' => Class_TypeDoc::LIVRE,
'id_origine' => 312414,
'code_barres' => '012347']);
$this->_search_client = $this->mock();
$this->_search_client
->whenCalled('__getLastRequest')
->answers('last request')
->whenCalled('__getLastResponse')
->answers('last response')
->whenCalled('__getLastResponseHeaders')
->answers('last response headers')
->whenCalled('__getLastRequestHeaders')
->answers('last response')
->whenCalled('hasFunction')
->answers(false)
->whenCalled('__setCookie')
->answers(null)
->whenCalled('EndSession')
->answers(new EndSessionResponse())
->whenCalled('hasFunction')->with('GetId')->answers(true)
->whenCalled('GetId')
->with(new GetId())
->answers(GetIdResponse::withIdResult('1234'))
->whenCalled('hasFunction')->with('GetAdh')->answers(true)
->whenCalled('GetAdh')
->with(GetAdh::withNo('10900000753'))
->answers(Storm_Test_ObjectWrapper::mock()
->whenCalled('getXml')
->answers(OrpheeFixtures::xmlGetInfoUserCarteHenryDupont()))
->whenCalled('GetAdh')
->with(GetAdh::withNo('1301500012'))
->answers(Storm_Test_ObjectWrapper::mock()
->whenCalled('getXml')
->answers(OrpheeFixtures::xmlGetAdhFoix()))
->whenCalled('GetAdh')
->with(GetAdh::withCardAndPassword('1301500012',$this->_foix->getPassword()))
->answers(Storm_Test_ObjectWrapper::mock()
->whenCalled('getXml')
->answers(OrpheeFixtures::xmlGetAdhFoix()))
->whenCalled('GetLstDmt')
->with(GetLstDmt::withNtcAndFas('312412', 0))
->answers(GetLstDmtResponse::withResult(OrpheeFixtures::xmlGetLstDmtMillenium()))
->whenCalled('RsvNtcAdh')
->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))
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>'));
$allow_hold_available_items=true;
$this->_orphee = Class_WebService_SIGB_Orphee_Service::getService('tests/fixtures/orphee.wsdl', null, $allow_hold_available_items);
$this->_orphee->setSearchClient($this->_search_client);
$this->_orphee->isConnected();
$this->_henry_dupont =
$this->fixture(Class_Users::class,
['id' => 2,
'login' => '10900000753',
'idabon' => '100753',
'password' => 'secret',
'id_int_bib' => 34,
'id_site' => 34]);
$this->_henry_dupont->beAbonneSIGB()->assertSave();
Class_WebService_SIGB_Orphee::setService(array_merge($comm_params,
['id_bib' => 34,
'type' => Class_IntBib::COM_ORPHEE]),
$this->_orphee);
Class_WebService_SIGB_Orphee::setService(array_merge($comm_params,
['id_bib' => 36,
'type' => Class_IntBib::COM_ORPHEE,
'use_card_number' => '1301500012']),
$this->_orphee);
}
public function tearDown(){
Class_WebService_SIGB_Orphee::reset();
parent::tearDown();
}
}
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);
}
}
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
class TemplatesAbonneCentralizedHoldsFailuresTest extends TemplatesAbonneCentralizedHoldsTestCase {
/** @test */
public function HenryDupontShouldUseUniquePatronShouldBeFalse() {
$this->assertFalse($this->_henry_dupont->shouldUseUniquePatron());
}
/** @test */
public function JohnLemonShouldUseUniquePatronShouldBeTrue() {
$this->assertTrue($this->_john_lemon->shouldUseUniquePatron());
}
/** @test */
public function FoixShouldUseUniquePatronShouldBeFalse() {
$this->assertFalse($this->_foix->shouldUseUniquePatron());
}
/** @test */
public function JohnLemonGetUseCardNumberShouldBe130150012() {
$this->assertEquals($this->_john_lemon->getUseCardNumber(),'1301500012');
}
/** @test */
public function johnLemonReserveItem2346ShouldReturnReservationImpossibleNonReservable() {
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);
}
/** @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);
}
/** @test */
public function henryDupontReservItem2345ShouldReturnReservationImpossibleDocumentBibliothequeCentrale() {
Class_CosmoVar::setValueOf('centralized_hold_mode',36);
$this->_henry_dupont->setIntBib(Class_IntBib::find(38));
ZendAfi_Auth::getInstance()->logUser($this->_henry_dupont);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2347/id_origine/312412/id/123');
$this->assertContains('Vous ne pouvez pas réserver cet exemplaire !',
json_decode($this->_response->getBody())->content);
}
}
class TemplatesAbonneCentralizedHoldsReservationSuccessTest
extends TemplatesAbonneCentralizedHoldsTestCase{
protected $_mock_transport;
public function setUp() {
parent::setUp();
$this->_mock_transport = new MockMailTransport();
Zend_Mail::setDefaultTransport($this->_mock_transport);
Class_Profil::getCurrentProfil()->setMailSite('laurent@afi-sa.fr');
$this->_john_lemon
->setIdIntBib(37)
->setIntBib(Class_IntBib::find(37));
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
ZendAfi_Auth::getInstance()->logUser($this->_john_lemon);
$this->dispatch('/recherche/reservationajax/id_bib/36/copy_id/2345/id_origine/312412/id/123');
}
/** @test */
public function johnLemonReserveItem312412ShouldReturnReservationEnregistree() {
$this->assertContains('Votre réservation est enregistrée',
json_decode($this->_response->getBody())->content);
}
/** @test */
public function EmailSentCountShouldBeThree() {
$this->assertEquals(count($this->_mock_transport->getSentMails()), 3);
}
public function getSenders(){
return [[0],[1],[2]];
}
/** @test
* @dataProvider getSenders
*/
public function emailSentFromShouldBeProfilEmail($email_count) {
$this->assertEquals($this->_mock_transport->getSentMails()[$email_count]->getFrom(), 'laurent@afi-sa.fr');
}
public function getRecipients(){
return [[0, 'test@jolieville.net'],
[1, 'intbibqsdf@WonderTown.net'],
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
[2,'johnlemon@abbeyroad.net']];
}
/** @test
* @dataProvider getRecipients
*/
public function emailSentFirstRecipientShouldBeAsExpected($email_count, $recipient_address) {
$this->assertEquals($this->_mock_transport->getSentMails()[$email_count]->getRecipients()[0], $recipient_address);
}
public function getSubjects(){
return [[0, 'Nouvelle réservation par WonderTown pour John Lemon sur 012345'],
[1, 'Nouvelle réservation pour John Lemon sur 012345 auprès de JolieVille'],
[2, 'Votre réservation de La disparition pour la bibliothèque WonderTown']];
}
/** @test
* @dataProvider getSubjects
*/
public function emailSentSubjectShouldBeAsExpected($email_count, $subject_string) {
$this->assertEquals(iconv_mime_decode($this->_mock_transport->getSentMails()[$email_count]->getSubject()),
$subject_string);
}
public function getMailContents(){
$mail_to_central_library = <<<HTML_CENTRAL
<p>Bonjour,</p>
<p>Une réservation a été effectuée par un utilisateur du portail BDP.</p>
<p>Il s'agit du document : La disparition de Code Barre : 012345</p>
<p>Pour l'utilisateur : John Lemon</p>
<p>Pour la bibliothèque : WonderTown.
La réservation a été reportée dans le Orphée BDP au nom de la bibliothèque WonderTown avec le code adhérent 1301500012.
Le document doit être récupéré à la Bibliothèque Départementale et envoyé vers la bibliothèque WonderTown.
HTML_CENTRAL;
$mail_to_user_library = <<<HTML_LIBRARY
<p>Bonjour,</p>
<p>Une réservation a été effectuée par un utilisateur de votre bibliothèque sur le portail BDP.</p>
<p>Il s'agit du document : La disparition de Code Barre : 012345</p>
<p>Pour l'utilisateur : John Lemon</p>
<p>Pour la bibliothèque : WonderTown.
La réservation a été reportée dans le Orphée BDP au nom de votre bibliothèque avec le code adhérent 1301500012.
Le document doit vous être envoyé par la BDP.
HTML_LIBRARY;
$mail_to_user= <<<HTML_USER
<p>Bonjour,</p>
<p>Une réservation a été effectuée par un utilisateur de votre bibliothèque sur le portail BDP.</p>
<p>Il s'agit du document : La disparition de Code Barre : 012345</p>
<p>Pour l'utilisateur : John Lemon</p>
<p>Pour la bibliothèque : WonderTown.
La réservation a été reportée dans le Orphée BDP au nom de votre bibliothèque avec le code adhérent 1301500012.
Le document doit vous être envoyé par la BDP.
HTML_USER;
return [[0, $mail_to_central_library],
[1, $mail_to_user_library],
[2, $mail_to_user]];
}
/** @test
* @dataProvider getMailContents
*/
public function emailSentContentShouldBeAsExpected($email_count, $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')
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
->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);
}