Lines 460-550
subtest "move_to_deleted" => sub {
Link Here
|
460 |
}; |
460 |
}; |
461 |
|
461 |
|
462 |
subtest "delete" => sub { |
462 |
subtest "delete" => sub { |
463 |
plan tests => 11; |
463 |
plan tests => 13; |
464 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
464 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
465 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' ); |
465 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' ); |
466 |
Koha::Virtualshelves->delete; |
466 |
Koha::Virtualshelves->delete; |
467 |
|
467 |
|
|
|
468 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
469 |
my $patron_for_sharing = $builder->build_object({ class => 'Koha::Patrons' }); |
468 |
my $staff_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
470 |
my $staff_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
469 |
t::lib::Mocks::mock_userenv({ patron => $staff_patron }); |
471 |
t::lib::Mocks::mock_userenv({ patron => $staff_patron }); |
470 |
|
472 |
|
471 |
my $patron = $builder->build( { source => 'Borrower' } ); |
473 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->borrowernumber } }); |
472 |
my $patron_for_sharing = $staff_patron->borrowernumber; |
474 |
my $modification = $builder->build_object({ class => 'Koha::Patron::Modifications', value => { borrowernumber => $patron->borrowernumber } }); |
473 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
|
|
474 |
my $hold = $builder->build( |
475 |
{ source => 'Reserve', |
476 |
value => { borrowernumber => $patron->{borrowernumber} } |
477 |
} |
478 |
); |
479 |
my $modification = $builder->build_object({ class => 'Koha::Patron::Modifications', value => { borrowernumber => $patron->{borrowernumber} } }); |
480 |
my $private_list = Koha::Virtualshelf->new({ |
475 |
my $private_list = Koha::Virtualshelf->new({ |
481 |
shelfname => "private", |
476 |
shelfname => "private", |
482 |
owner => $patron->{borrowernumber}, |
477 |
owner => $patron->borrowernumber, |
483 |
public => 0, |
478 |
public => 0, |
484 |
} |
479 |
})->store; |
485 |
)->store; |
|
|
486 |
my $public_list = Koha::Virtualshelf->new({ |
480 |
my $public_list = Koha::Virtualshelf->new({ |
487 |
shelfname => "public", |
481 |
shelfname => "public", |
488 |
owner => $patron->{borrowernumber}, |
482 |
owner => $patron->borrowernumber, |
489 |
public => 1, |
483 |
public => 1, |
490 |
} |
484 |
})->store; |
491 |
)->store; |
|
|
492 |
my $list_to_share = Koha::Virtualshelf->new({ |
485 |
my $list_to_share = Koha::Virtualshelf->new({ |
493 |
shelfname => "shared", |
486 |
shelfname => "shared", |
494 |
owner => $patron->{borrowernumber}, |
487 |
owner => $patron->borrowernumber, |
495 |
public => 0, |
488 |
public => 0, |
496 |
} |
489 |
})->store; |
497 |
)->store; |
|
|
498 |
|
490 |
|
499 |
my $shared_shelf = eval { $list_to_share->share("valid key")->accept("valid key", $patron_for_sharing) }; |
491 |
$list_to_share->share("valid key")->accept( "valid key", $patron_for_sharing->borrowernumber ); |
500 |
my $deleted = $retrieved_patron->delete; |
492 |
$list_to_share->share("valid key")->accept( "valid key", $staff_patron->borrowernumber ); # this share should be removed at deletion too |
|
|
493 |
my $deleted = $patron->delete; |
501 |
is( ref($deleted), 'Koha::Patron', 'Koha::Patron->delete should return the deleted patron object if the patron has been correctly deleted' ); |
494 |
is( ref($deleted), 'Koha::Patron', 'Koha::Patron->delete should return the deleted patron object if the patron has been correctly deleted' ); |
|
|
495 |
ok( $patron->borrowernumber, 'Still have the deleted borrowernumber' ); |
502 |
|
496 |
|
503 |
is( Koha::Patrons->find( $patron->{borrowernumber} ), undef, 'Koha::Patron->delete should have deleted the patron' ); |
497 |
is( Koha::Patrons->find( $patron->borrowernumber ), undef, 'Koha::Patron->delete should have deleted the patron' ); |
504 |
|
498 |
|
505 |
is (Koha::Old::Holds->search( { reserve_id => $hold->{ reserve_id } } )->count, 1, q|Koha::Patron->delete should have cancelled patron's holds| ); |
499 |
is (Koha::Old::Holds->search({ reserve_id => $hold->reserve_id })->count, 1, q|Koha::Patron->delete should have cancelled patron's holds| ); |
506 |
|
500 |
|
507 |
is( Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have cancelled patron's holds 2| ); |
501 |
is( Koha::Holds->search( { borrowernumber => $patron->borrowernumber } )->count, 0, q|Koha::Patron->delete should have cancelled patron's holds 2| ); |
508 |
|
502 |
|
509 |
my $transferred_lists = Koha::Virtualshelves->search({ owner => $patron_for_sharing })->count; |
503 |
my $transferred_lists = Koha::Virtualshelves->search({ owner => $staff_patron->borrowernumber })->count; |
510 |
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'); |
504 |
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'); |
511 |
is( Koha::Virtualshelfshares->search({ borrowernumber => $patron_for_sharing })->count, 0, "New owner of list should have shares removed" ); |
505 |
is( Koha::Virtualshelfshares->search({ borrowernumber => $staff_patron->borrowernumber })->count, 0, "New owner of list should have shares removed" ); |
512 |
is( Koha::Virtualshelves->search({ owner => $patron->{borrowernumber} })->count, 0, q|Koha::Patron->delete should have deleted patron's lists/removed their ownership| ); |
506 |
is( Koha::Virtualshelfshares->search({ borrowernumber => $patron_for_sharing->borrowernumber })->count, 1, "But the other share is still there" ); |
|
|
507 |
is( Koha::Virtualshelves->search({ owner => $patron->borrowernumber })->count, 0, q|Koha::Patron->delete should have deleted patron's lists/removed their ownership| ); |
513 |
|
508 |
|
514 |
is( Koha::Patron::Modifications->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's modifications| ); |
509 |
is( Koha::Patron::Modifications->search( { borrowernumber => $patron->borrowernumber } )->count, 0, q|Koha::Patron->delete should have deleted patron's modifications| ); |
515 |
|
510 |
|
516 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $retrieved_patron->borrowernumber } )->count; |
511 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count; |
517 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); |
512 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); |
518 |
|
513 |
|
519 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' ); |
514 |
t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' ); |
520 |
Koha::Virtualshelves->search({})->delete; |
515 |
Koha::Virtualshelves->delete; |
521 |
my $patron2 = $builder->build( { source => 'Borrower' } ); |
516 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
522 |
my $retrieved_patron2 = Koha::Patrons->find( $patron2->{borrowernumber} ); |
|
|
523 |
my $private_list2 = Koha::Virtualshelf->new({ |
517 |
my $private_list2 = Koha::Virtualshelf->new({ |
524 |
shelfname => "private", |
518 |
shelfname => "private", |
525 |
owner => $patron2->{borrowernumber}, |
519 |
owner => $patron2->borrowernumber, |
526 |
public => 0, |
520 |
public => 0, |
527 |
} |
521 |
})->store; |
528 |
)->store; |
|
|
529 |
my $public_list2 = Koha::Virtualshelf->new({ |
522 |
my $public_list2 = Koha::Virtualshelf->new({ |
530 |
shelfname => "public", |
523 |
shelfname => "public", |
531 |
owner => $patron2->{borrowernumber}, |
524 |
owner => $patron2->borrowernumber, |
532 |
public => 1, |
525 |
public => 1, |
533 |
} |
526 |
})->store; |
534 |
)->store; |
|
|
535 |
my $list_to_share2 = Koha::Virtualshelf->new({ |
527 |
my $list_to_share2 = Koha::Virtualshelf->new({ |
536 |
shelfname => "shared", |
528 |
shelfname => "shared", |
537 |
owner => $patron2->{borrowernumber}, |
529 |
owner => $patron2->borrowernumber, |
538 |
public => 0, |
530 |
public => 0, |
539 |
} |
531 |
})->store; |
540 |
)->store; |
532 |
$list_to_share2->share("valid key")->accept( "valid key", $patron_for_sharing->borrowernumber ); |
541 |
|
|
|
542 |
my $shared_shelf2 = eval { $list_to_share2->share("valid key") }; |
543 |
my $deleted2 = $retrieved_patron2->delete; |
544 |
|
533 |
|
545 |
is( Koha::Virtualshelves->search( { owner => $patron2->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's lists| ); |
534 |
# Delete patron2, check if shelves and shares are now empty |
546 |
$transferred_lists = Koha::Virtualshelves->search({})->count; |
535 |
$patron2->delete; |
547 |
is( $transferred_lists, 0, 'All lists should be deleted with ListOwnershipUponPatronDeletion set to Delete'); |
536 |
is( Koha::Virtualshelves->count, 0, 'All lists should be gone now' ); |
|
|
537 |
is( Koha::Virtualshelfshares->count, 0, 'All shares should be gone too' ); |
548 |
}; |
538 |
}; |
549 |
|
539 |
|
550 |
subtest 'Koha::Patrons->delete' => sub { |
540 |
subtest 'Koha::Patrons->delete' => sub { |
551 |
- |
|
|