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