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