3 # This file is part of Koha
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 1;
23 use JSON qw( encode_json );
25 use C4::Reserves qw(AddReserve);
28 use Koha::BackgroundJob::BatchDeleteBiblio;
29 use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
32 use t::lib::TestBuilder;
34 my $schema = Koha::Database->new->schema;
35 my $builder = t::lib::TestBuilder->new;
37 subtest "process() tests" => sub {
41 $schema->storage->txn_begin;
43 my $biblio = $builder->build_sample_biblio;
44 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id });
45 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id });
47 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
50 borrowernumber => $patron->id,
51 biblionumber => $biblio->id,
52 itemnumber => $item_1->id,
53 branchcode => $patron->branchcode
59 my $mock_holds_queue_job = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
60 $mock_holds_queue_job->mock( 'enqueue', sub {
64 my $job = Koha::BackgroundJob::BatchDeleteBiblio->new(
68 borrowernumber => undef,
69 type => 'batch_biblio_record_deletion',
71 record_ids => [ $biblio->id ],
76 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
80 record_ids => [ $biblio->id ],
84 is( $counter, 1, 'Holds queue update is enqueued only once' );
86 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
88 $biblio = $builder->build_sample_biblio;
90 $job = Koha::BackgroundJob::BatchDeleteBiblio->new(
94 borrowernumber => undef,
95 type => 'batch_biblio_record_deletion',
97 record_ids => [ $biblio->id ],
104 record_ids => [ $biblio->id ],
108 is( $counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' );
110 $schema->storage->txn_rollback;