From f311063d081ad24d9e831852fd9a09a87ef98de3 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 17 Feb 2025 10:56:18 +0000 Subject: [PATCH] Bug 39145: Add unit tests Test plan: Run t/db_dependent/Koha/Virtualshelves.t Signed-off-by: Marcel de Rooy Signed-off-by: David Nind --- t/db_dependent/Koha/Virtualshelves.t | 43 +++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Virtualshelves.t b/t/db_dependent/Koha/Virtualshelves.t index 48f1a0cd2c..6f6caae1bc 100755 --- a/t/db_dependent/Koha/Virtualshelves.t +++ b/t/db_dependent/Koha/Virtualshelves.t @@ -31,7 +31,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'disown_or_delete() tests' => sub { - plan tests => 3; + plan tests => 4; subtest 'All set cases' => sub { @@ -172,6 +172,47 @@ subtest 'disown_or_delete() tests' => sub { $schema->storage->txn_rollback; }; + subtest 'ListOwnershipUponPatronDeletion set to transfer_public' => sub { + plan tests => 2; + $schema->storage->txn_begin; + my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron_3 = $builder->build_object( { class => 'Koha::Patrons' } ); + my $public_list = $builder->build_object( + { + class => "Koha::Virtualshelves", + value => { owner => $patron_1->id, public => 1 } + } + ); + my $private_list_shared = $builder->build_object( + { + class => "Koha::Virtualshelves", + value => { owner => $patron_1->id, public => 0 } + } + ); + $builder->build_object( + { + class => 'Koha::Virtualshelfshares', + value => + { shelfnumber => $private_list_shared->id, invitekey => undef, borrowernumber => $patron_2->id } + } + ); + + t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer_public' ); + t::lib::Mocks::mock_preference( 'ListOwnerDesignated', $patron_3->id ); + + my $rs = Koha::Virtualshelves->search( + { shelfnumber => [ $public_list->id, $private_list_shared->id ] } ); + + my $result = $rs->disown_or_delete; + $rs->reset; + + is( $rs->count, 1, 'Only public list should be transferred' ); + is( $rs->next->id, $public_list->id, 'Check id too' ); + + $schema->storage->txn_rollback; + }; + subtest 'ListOwnershipUponPatronDeletion set to delete' => sub { plan tests => 2; -- 2.39.5