From 352060d76738243307746f69a6313e3220d15508 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 23 Dec 2022 11:43:22 -0300 Subject: [PATCH] Bug 31086: (follow-up) There's no ->fill in 21.11 Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Hold.t | 239 ------------------------------------- 1 file changed, 239 deletions(-) diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index cee21805949..8fb432bcf09 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -61,245 +61,6 @@ subtest 'store() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'fill() tests' => sub { - - plan tests => 13; - - $schema->storage->txn_begin; - - my $fee = 15; - - my $category = $builder->build_object( - { - class => 'Koha::Patron::Categories', - value => { reservefee => $fee } - } - ); - my $patron = $builder->build_object( - { - class => 'Koha::Patrons', - value => { categorycode => $category->id } - } - ); - my $manager = $builder->build_object( { class => 'Koha::Patrons' } ); - - my $title = 'Do what you want'; - my $biblio = $builder->build_sample_biblio( { title => $title } ); - my $item = $builder->build_sample_item( { biblionumber => $biblio->id } ); - my $hold = $builder->build_object( - { - class => 'Koha::Holds', - value => { - biblionumber => $biblio->id, - borrowernumber => $patron->id, - itemnumber => $item->id, - priority => 10, - } - } - ); - - t::lib::Mocks::mock_preference( 'HoldFeeMode', 'any_time_is_collected' ); - t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); - t::lib::Mocks::mock_userenv( - { patron => $manager, branchcode => $manager->branchcode } ); - - my $interface = 'api'; - C4::Context->interface($interface); - - my $ret = $hold->fill; - - is( ref($ret), 'Koha::Hold', '->fill returns the object type' ); - is( $ret->id, $hold->id, '->fill returns the object' ); - - is( Koha::Holds->find($hold->id), undef, 'Hold no longer current' ); - my $old_hold = Koha::Old::Holds->find( $hold->id ); - - is( $old_hold->id, $hold->id, 'reserve_id retained' ); - is( $old_hold->priority, 0, 'priority set to 0' ); - is( $old_hold->found, 'F', 'found set to F' ); - - subtest 'fee applied tests' => sub { - - plan tests => 9; - - my $account = $patron->account; - is( $account->balance, $fee, 'Charge applied correctly' ); - - my $debits = $account->outstanding_debits; - is( $debits->count, 1, 'Only one fee charged' ); - - my $fee_debit = $debits->next; - is( $fee_debit->amount * 1, $fee, 'Fee amount stored correctly' ); - is( $fee_debit->description, $title, - 'Fee description stored correctly' ); - is( $fee_debit->manager_id, $manager->id, - 'Fee manager_id stored correctly' ); - is( $fee_debit->branchcode, $manager->branchcode, - 'Fee branchcode stored correctly' ); - is( $fee_debit->interface, $interface, - 'Fee interface stored correctly' ); - is( $fee_debit->debit_type_code, - 'RESERVE', 'Fee debit_type_code stored correctly' ); - is( $fee_debit->itemnumber, $item->id, - 'Fee itemnumber stored correctly' ); - }; - - my $logs = Koha::ActionLogs->search( - { - action => 'FILL', - module => 'HOLDS', - object => $hold->id - } - ); - - is( $logs->count, 1, '1 log line added' ); - - # Set HoldFeeMode to something other than any_time_is_collected - t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' ); - # Disable logging - t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); - - $hold = $builder->build_object( - { - class => 'Koha::Holds', - value => { - biblionumber => $biblio->id, - borrowernumber => $patron->id, - itemnumber => $item->id, - priority => 10, - } - } - ); - - $hold->fill; - - my $account = $patron->account; - is( $account->balance, $fee, 'No new charge applied' ); - - my $debits = $account->outstanding_debits; - is( $debits->count, 1, 'Only one fee charged, because of HoldFeeMode' ); - - $logs = Koha::ActionLogs->search( - { - action => 'FILL', - module => 'HOLDS', - object => $hold->id - } - ); - - is( $logs->count, 0, 'HoldsLog disabled, no logs added' ); - - subtest 'anonymization behavior tests' => sub { - - plan tests => 5; - - # reduce the tests noise - t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); - t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' ); - # unset AnonymousPatron - t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); - - # 0 == keep forever - $patron->privacy(0)->store; - my $hold = $builder->build_object( - { - class => 'Koha::Holds', - value => { borrowernumber => $patron->id, found => undef } - } - ); - $hold->fill(); - is( Koha::Old::Holds->find( $hold->id )->borrowernumber, - $patron->borrowernumber, 'Patron link is kept' ); - - # 1 == "default", meaning it is not protected from removal - $patron->privacy(1)->store; - $hold = $builder->build_object( - { - class => 'Koha::Holds', - value => { borrowernumber => $patron->id, found => undef } - } - ); - $hold->fill(); - is( Koha::Old::Holds->find( $hold->id )->borrowernumber, - $patron->borrowernumber, 'Patron link is kept' ); - - # 2 == delete immediately - $patron->privacy(2)->store; - $hold = $builder->build_object( - { - class => 'Koha::Holds', - value => { borrowernumber => $patron->id, found => undef } - } - ); - - throws_ok - { $hold->fill(); } - 'Koha::Exception', - 'AnonymousPatron not set, exception thrown'; - - $hold->discard_changes; # refresh from DB - - ok( !$hold->is_found, 'Hold is not filled' ); - - my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); - t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); - - $hold = $builder->build_object( - { - class => 'Koha::Holds', - value => { borrowernumber => $patron->id, found => undef } - } - ); - $hold->fill(); - is( - Koha::Old::Holds->find( $hold->id )->borrowernumber, - $anonymous_patron->id, - 'Patron link is set to the configured anonymous patron immediately' - ); - }; - - subtest 'holds_queue update tests' => sub { - - plan tests => 1; - - my $biblio = $builder->build_sample_biblio; - - my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); - $mock->mock( 'enqueue', sub { - my ( $self, $args ) = @_; - is_deeply( - $args->{biblio_ids}, - [ $biblio->id ], - '->fill triggers a holds queue update for the related biblio' - ); - } ); - - t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); - - $builder->build_object( - { - class => 'Koha::Holds', - value => { - biblionumber => $biblio->id, - } - } - )->fill; - - t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); - # this call shouldn't add a new test - $builder->build_object( - { - class => 'Koha::Holds', - value => { - biblionumber => $biblio->id, - } - } - )->fill; - }; - - $schema->storage->txn_rollback; -}; - subtest 'patron() tests' => sub { plan tests => 2; -- 2.34.1