From 87e17d783df7303c70fa0bbc48d05266451a0973 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 25 Jul 2025 13:59:23 +0000 Subject: [PATCH] Bug 40517: Add unit tests Run the updated test file: prove ./t/db_dependent/Koha/Patron.t Relevant tests worth running to ensure no regressions are added to existing covered functionality: prove ./t/db_dependent/Circulation* prove ./t/db_dependent/Hold* prove ./t/db_dependent/Reserves* Test plan, k-t-d: 1) Apply patches, enable DisplayAddHoldGroups system preference 2) Do a search for 'test': /cgi-bin/koha/catalogue/search.pl?q=test 3) Click the 'Select all' link at the top of the search results, click the 'Place hold' button. 4) Enter the 'koha' user 5) Pick a pickup location for each of the holds and click 'Place holds'. 6) Visit the 'koha' patron: /cgi-bin/koha/members/moremember.pl?borrowernumber=51 7) Click the 'holds' tab. Notice a new 'Group selected' button now exists 8) Pick any number of holds (more than 2) and click the 'Group selected' button. Confirm 9) Notice the hold group shows '1'. If you click on it you're presented the hold group modal. 10) Group multiple holds multiple times. 11) Notice you can't group a hold that has already been found. 12) Notice you can't click the 'Group selected' button unless at least 2 holds are selected. 13) Notice a hold group is deleted if left with 0 or 1 hold e.g. make a group of 2 holds, cancel 1, notice the remaining hold is left without a group. prove t/db_dependent/api/v1/patrons_hold_groups.t prove t/db_dependent/Koha/Patron.t --- t/db_dependent/Koha/Patron.t | 90 +++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 7cba994728a..f1d717ef8e4 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 42; +use Test::More tests => 43; use Test::NoWarnings; use Test::Exception; use Test::Warn; @@ -3118,3 +3118,91 @@ subtest 'is_anonymous' => sub { $schema->storage->txn_rollback; }; + +subtest "create_hold_group, hold_groups, visual_hold_group_id tests" => sub { + + plan tests => 13; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $hold1 = $builder->build_object( + { + class => 'Koha::Holds', + value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber } + } + ); + my $hold2 = $builder->build_object( + { + class => 'Koha::Holds', + value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber } + } + ); + my $hold3 = $builder->build_object( + { + class => 'Koha::Holds', + value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber } + } + ); + + my $hold4 = $builder->build_object( + { + class => 'Koha::Holds', + value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber } + } + ); + my $hold5 = $builder->build_object( + { + class => 'Koha::Holds', + value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber } + } + ); + + my $hold6 = $builder->build_object( + { + class => 'Koha::Holds', + value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber } + } + ); + + my $patron_hold_groups = $patron->hold_groups; + is( $patron_hold_groups->count, 0, 'Patron does not have any hold groups' ); + + # Create 1st hold group + $patron->create_hold_group( [ $hold1->reserve_id, $hold2->reserve_id, $hold3->reserve_id ] ); + is( $patron_hold_groups->count, 1, 'Patron has one hold group' ); + + my $hold_group = $patron->hold_groups->as_list->[0]; + is( $hold_group->visual_hold_group_id, 1, 'Visual hold group id is 1' ); + is( $hold_group->hold_group_id, $hold1->get_from_storage->hold_group_id, 'hold1 added to hold_group' ); + is( $hold_group->hold_group_id, $hold2->get_from_storage->hold_group_id, 'hold2 added to hold_group' ); + is( $hold_group->hold_group_id, $hold3->get_from_storage->hold_group_id, 'hold3 added to hold_group' ); + + # Create 2nd hold group + $patron->create_hold_group( [ $hold4->reserve_id, $hold5->reserve_id ] ); + is( $patron_hold_groups->count, 2, 'Patron has two hold groups' ); + + my $second_hold_group = $patron->hold_groups->as_list->[1]; + is( $second_hold_group->visual_hold_group_id, 2, 'Visual hold group id is 2' ); + is( + $second_hold_group->hold_group_id, $hold4->get_from_storage->hold_group_id, + 'hold4 added to second hold_group' + ); + is( + $second_hold_group->hold_group_id, $hold5->get_from_storage->hold_group_id, + 'hold5 added to second hold_group' + ); + + $hold3->get_from_storage->fill(); + is( $patron->get_from_storage->hold_groups->count, 1, 'Patron only has one hold group again' ); + + $hold4->get_from_storage->cancel(); + is( $patron->get_from_storage->hold_groups->count, 0, 'Patron does not have any hold groups again' ); + + # Create 3rd hold group + $patron->create_hold_group( [ $hold5->reserve_id, $hold6->reserve_id ] ); + my $third_hold_group = $patron->hold_groups->as_list->[0]; + is( $third_hold_group->visual_hold_group_id, 1, 'Visual hold group id is 1' ); + + $schema->storage->txn_rollback; +}; -- 2.39.5