Lines 26-37
use DateTime;
Link Here
|
26 |
use C4::Biblio; |
26 |
use C4::Biblio; |
27 |
use C4::Circulation; |
27 |
use C4::Circulation; |
28 |
use C4::Members; |
28 |
use C4::Members; |
|
|
29 |
use C4::Context; |
29 |
|
30 |
|
30 |
use Koha::Holds; |
31 |
use Koha::Holds; |
31 |
use Koha::Patron; |
32 |
use Koha::Patron; |
32 |
use Koha::Patrons; |
33 |
use Koha::Patrons; |
33 |
use Koha::Database; |
34 |
use Koha::Database; |
34 |
use Koha::DateUtils; |
35 |
use Koha::DateUtils; |
|
|
36 |
use Koha::Virtualshelf; |
35 |
use Koha::Virtualshelves; |
37 |
use Koha::Virtualshelves; |
36 |
|
38 |
|
37 |
use t::lib::TestBuilder; |
39 |
use t::lib::TestBuilder; |
Lines 64-70
my $new_patron_2 = Koha::Patron->new(
Link Here
|
64 |
)->store; |
66 |
)->store; |
65 |
|
67 |
|
66 |
C4::Context->_new_userenv('xxx'); |
68 |
C4::Context->_new_userenv('xxx'); |
67 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', ''); |
69 |
C4::Context->set_userenv(1,'userid','usercnum','firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', ''); |
68 |
|
70 |
|
69 |
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' ); |
71 |
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' ); |
70 |
|
72 |
|
Lines 336-367
subtest "move_to_deleted" => sub {
Link Here
|
336 |
}; |
338 |
}; |
337 |
|
339 |
|
338 |
subtest "delete" => sub { |
340 |
subtest "delete" => sub { |
339 |
plan tests => 5; |
341 |
plan tests => 9; |
340 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
342 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
|
|
343 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' ); |
344 |
Koha::Virtualshelves->search({})->delete; |
345 |
my $userenv = C4::Context->userenv(); |
341 |
my $patron = $builder->build( { source => 'Borrower' } ); |
346 |
my $patron = $builder->build( { source => 'Borrower' } ); |
|
|
347 |
my $patron_for_sharing = (ref($userenv) eq 'HASH' ) ? $userenv->{'number'} : 0; |
342 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
348 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
343 |
my $hold = $builder->build( |
349 |
my $hold = $builder->build( |
344 |
{ source => 'Reserve', |
350 |
{ source => 'Reserve', |
345 |
value => { borrowernumber => $patron->{borrowernumber} } |
351 |
value => { borrowernumber => $patron->{borrowernumber} } |
346 |
} |
352 |
} |
347 |
); |
353 |
); |
348 |
my $list = $builder->build( |
354 |
my $private_list = Koha::Virtualshelf->new({ |
349 |
{ source => 'Virtualshelve', |
355 |
shelfname => "private", |
350 |
value => { owner => $patron->{borrowernumber} } |
356 |
owner => $patron->{borrowernumber}, |
|
|
357 |
category => 1 |
351 |
} |
358 |
} |
352 |
); |
359 |
)->store; |
|
|
360 |
my $public_list = Koha::Virtualshelf->new({ |
361 |
shelfname => "public", |
362 |
owner => $patron->{borrowernumber}, |
363 |
category => 2 |
364 |
} |
365 |
)->store; |
366 |
my $list_to_share = Koha::Virtualshelf->new({ |
367 |
shelfname => "shared", |
368 |
owner => $patron->{borrowernumber}, |
369 |
category => 1 |
370 |
} |
371 |
)->store; |
353 |
|
372 |
|
|
|
373 |
my $shared_shelf = eval { $list_to_share->share("valid key")->accept("valid key", $patron_for_sharing) }; |
354 |
my $deleted = $retrieved_patron->delete; |
374 |
my $deleted = $retrieved_patron->delete; |
355 |
is( $deleted, 1, 'Koha::Patron->delete should return 1 if the patron has been correctly deleted' ); |
|
|
356 |
|
375 |
|
|
|
376 |
is( $deleted, 1, 'Koha::Patron->delete should return 1 if the patron has been correctly deleted' ); |
357 |
is( Koha::Patrons->find( $patron->{borrowernumber} ), undef, 'Koha::Patron->delete should have deleted the patron' ); |
377 |
is( Koha::Patrons->find( $patron->{borrowernumber} ), undef, 'Koha::Patron->delete should have deleted the patron' ); |
358 |
|
|
|
359 |
is( Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's holds| ); |
378 |
is( Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's holds| ); |
360 |
|
379 |
|
361 |
is( Koha::Virtualshelves->search( { owner => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's lists| ); |
380 |
my $transferred_lists = Koha::Virtualshelves->search({ owner => $patron_for_sharing })->count; |
|
|
381 |
is( $transferred_lists, 2, 'Public and shared lists should stay in database under a different owner with a unique name, while private lists delete, with ListOwnershipPatronDeletion set to Transfer'); |
382 |
is( Koha::Virtualshelfshares->search({ borrowernumber => $patron_for_sharing })->count, 0, "New owner of list should have shares removed" ); |
383 |
is( Koha::Virtualshelves->search({ owner => $patron->{borrowernumber} })->count, 0, q|Koha::Patron->delete should have deleted patron's lists/removed their ownership| ); |
362 |
|
384 |
|
363 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $retrieved_patron->borrowernumber } )->count; |
385 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->{borrowernumber} } )->count; |
364 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); |
386 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); |
|
|
387 |
|
388 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' ); |
389 |
Koha::Virtualshelves->search({})->delete; |
390 |
my $patron2 = $builder->build( { source => 'Borrower' } ); |
391 |
my $retrieved_patron2 = Koha::Patrons->find( $patron2->{borrowernumber} ); |
392 |
my $private_list2 = Koha::Virtualshelf->new({ |
393 |
shelfname => "private", |
394 |
owner => $patron2->{borrowernumber}, |
395 |
category => 1 |
396 |
} |
397 |
)->store; |
398 |
my $public_list2 = Koha::Virtualshelf->new({ |
399 |
shelfname => "public", |
400 |
owner => $patron2->{borrowernumber}, |
401 |
category => 2 |
402 |
} |
403 |
)->store; |
404 |
my $list_to_share2 = Koha::Virtualshelf->new({ |
405 |
shelfname => "shared", |
406 |
owner => $patron2->{borrowernumber}, |
407 |
category => 1 |
408 |
} |
409 |
)->store; |
410 |
|
411 |
my $shared_shelf2 = eval { $list_to_share2->share("valid key") }; |
412 |
my $deleted2 = $retrieved_patron2->delete; |
413 |
|
414 |
is( Koha::Virtualshelves->search( { owner => $patron2->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's lists| ); |
415 |
$transferred_lists = Koha::Virtualshelves->search({})->count; |
416 |
is( $transferred_lists, 0, 'All lists should be deleted with ListOwnershipUponPatronDeletion set to Delete'); |
365 |
}; |
417 |
}; |
366 |
|
418 |
|
367 |
subtest 'add_enrolment_fee_if_needed' => sub { |
419 |
subtest 'add_enrolment_fee_if_needed' => sub { |