Lines 42-47
use Koha::Patron::Categories;
Link Here
|
42 |
use Koha::Patron::Relationship; |
42 |
use Koha::Patron::Relationship; |
43 |
use Koha::Database; |
43 |
use Koha::Database; |
44 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
44 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
|
|
45 |
use Koha::Virtualshelf; |
45 |
use Koha::Virtualshelves; |
46 |
use Koha::Virtualshelves; |
46 |
use Koha::Notice::Messages; |
47 |
use Koha::Notice::Messages; |
47 |
|
48 |
|
Lines 459-480
subtest "move_to_deleted" => sub {
Link Here
|
459 |
}; |
460 |
}; |
460 |
|
461 |
|
461 |
subtest "delete" => sub { |
462 |
subtest "delete" => sub { |
462 |
plan tests => 7; |
463 |
plan tests => 11; |
463 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
464 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
|
|
465 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' ); |
466 |
Koha::Virtualshelves->search({})->delete; |
467 |
my $userenv = C4::Context->userenv(); |
464 |
my $patron = $builder->build( { source => 'Borrower' } ); |
468 |
my $patron = $builder->build( { source => 'Borrower' } ); |
|
|
469 |
my $patron_for_sharing = (ref($userenv) eq 'HASH' ) ? $userenv->{'number'} : 0; |
465 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
470 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
466 |
my $hold = $builder->build( |
471 |
my $hold = $builder->build( |
467 |
{ source => 'Reserve', |
472 |
{ source => 'Reserve', |
468 |
value => { borrowernumber => $patron->{borrowernumber} } |
473 |
value => { borrowernumber => $patron->{borrowernumber} } |
469 |
} |
|
|
470 |
); |
471 |
my $list = $builder->build( |
472 |
{ source => 'Virtualshelve', |
473 |
value => { owner => $patron->{borrowernumber} } |
474 |
} |
474 |
} |
475 |
); |
475 |
); |
476 |
my $modification = $builder->build_object({ class => 'Koha::Patron::Modifications', value => { borrowernumber => $patron->{borrowernumber} } }); |
476 |
my $modification = $builder->build_object({ class => 'Koha::Patron::Modifications', value => { borrowernumber => $patron->{borrowernumber} } }); |
|
|
477 |
my $private_list = Koha::Virtualshelf->new({ |
478 |
shelfname => "private", |
479 |
owner => $patron->{borrowernumber}, |
480 |
category => 1 |
481 |
} |
482 |
)->store; |
483 |
my $public_list = Koha::Virtualshelf->new({ |
484 |
shelfname => "public", |
485 |
owner => $patron->{borrowernumber}, |
486 |
category => 2 |
487 |
} |
488 |
)->store; |
489 |
my $list_to_share = Koha::Virtualshelf->new({ |
490 |
shelfname => "shared", |
491 |
owner => $patron->{borrowernumber}, |
492 |
category => 1 |
493 |
} |
494 |
)->store; |
477 |
|
495 |
|
|
|
496 |
my $shared_shelf = eval { $list_to_share->share("valid key")->accept("valid key", $patron_for_sharing) }; |
478 |
my $deleted = $retrieved_patron->delete; |
497 |
my $deleted = $retrieved_patron->delete; |
479 |
is( ref($deleted), 'Koha::Patron', 'Koha::Patron->delete should return the deleted patron object if the patron has been correctly deleted' ); |
498 |
is( ref($deleted), 'Koha::Patron', 'Koha::Patron->delete should return the deleted patron object if the patron has been correctly deleted' ); |
480 |
|
499 |
|
Lines 484-495
subtest "delete" => sub {
Link Here
|
484 |
|
503 |
|
485 |
is( Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have cancelled patron's holds 2| ); |
504 |
is( Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have cancelled patron's holds 2| ); |
486 |
|
505 |
|
487 |
is( Koha::Virtualshelves->search( { owner => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's lists| ); |
506 |
my $transferred_lists = Koha::Virtualshelves->search({ owner => $patron_for_sharing })->count; |
|
|
507 |
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'); |
508 |
is( Koha::Virtualshelfshares->search({ borrowernumber => $patron_for_sharing })->count, 0, "New owner of list should have shares removed" ); |
509 |
is( Koha::Virtualshelves->search({ owner => $patron->{borrowernumber} })->count, 0, q|Koha::Patron->delete should have deleted patron's lists/removed their ownership| ); |
488 |
|
510 |
|
489 |
is( Koha::Patron::Modifications->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's modifications| ); |
511 |
is( Koha::Patron::Modifications->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's modifications| ); |
490 |
|
512 |
|
491 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $retrieved_patron->borrowernumber } )->count; |
513 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $retrieved_patron->borrowernumber } )->count; |
492 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); |
514 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); |
|
|
515 |
|
516 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' ); |
517 |
Koha::Virtualshelves->search({})->delete; |
518 |
my $patron2 = $builder->build( { source => 'Borrower' } ); |
519 |
my $retrieved_patron2 = Koha::Patrons->find( $patron2->{borrowernumber} ); |
520 |
my $private_list2 = Koha::Virtualshelf->new({ |
521 |
shelfname => "private", |
522 |
owner => $patron2->{borrowernumber}, |
523 |
category => 1 |
524 |
} |
525 |
)->store; |
526 |
my $public_list2 = Koha::Virtualshelf->new({ |
527 |
shelfname => "public", |
528 |
owner => $patron2->{borrowernumber}, |
529 |
category => 2 |
530 |
} |
531 |
)->store; |
532 |
my $list_to_share2 = Koha::Virtualshelf->new({ |
533 |
shelfname => "shared", |
534 |
owner => $patron2->{borrowernumber}, |
535 |
category => 1 |
536 |
} |
537 |
)->store; |
538 |
|
539 |
my $shared_shelf2 = eval { $list_to_share2->share("valid key") }; |
540 |
my $deleted2 = $retrieved_patron2->delete; |
541 |
|
542 |
is( Koha::Virtualshelves->search( { owner => $patron2->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's lists| ); |
543 |
$transferred_lists = Koha::Virtualshelves->search({})->count; |
544 |
is( $transferred_lists, 0, 'All lists should be deleted with ListOwnershipUponPatronDeletion set to Delete'); |
493 |
}; |
545 |
}; |
494 |
|
546 |
|
495 |
subtest 'Koha::Patrons->delete' => sub { |
547 |
subtest 'Koha::Patrons->delete' => sub { |