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 => 2;
24 use t::lib::TestBuilder;
28 my $schema = Koha::Database->new->schema;
29 my $builder = t::lib::TestBuilder->new;
31 subtest 'ModBiblio() + holds_queue update tests' => sub {
35 $schema->storage->txn_begin;
37 my $biblio = $builder->build_sample_biblio;
39 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
41 my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
42 $mock->mock( 'enqueue', sub {
43 my ( $self, $args ) = @_;
44 my ($package, $filename, $line) = caller;
48 'ModBiblio triggers a holds queue update for the related biblio'
53 $builder->build_object(
55 class => 'Koha::Holds',
57 biblionumber => $biblio->id,
62 # this call will trigger the mocked 'enqueue'
63 C4::Biblio::ModBiblio(
64 $biblio->metadata->record, $biblio->id,
65 $biblio->frameworkcode, { skip_holds_queue => 0 }
68 # this call will not trigger the mocked 'enqueue', so the test count is 1
69 C4::Biblio::ModBiblio(
70 $biblio->metadata->record, $biblio->id,
71 $biblio->frameworkcode, { skip_holds_queue => 1 }
74 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
76 # this call should not trigger the mocked 'enqueue'
77 C4::Biblio::ModBiblio(
78 $biblio->metadata->record, $biblio->id,
79 $biblio->frameworkcode, { skip_holds_queue => 0 }
82 # this call shoul not trigger the mocked 'enqueue'
83 C4::Biblio::ModBiblio(
84 $biblio->metadata->record, $biblio->id,
85 $biblio->frameworkcode, { skip_holds_queue => 1 }
88 $schema->storage->txn_rollback;
91 subtest 'DelBiblio + holds_queue update tests' => sub {
95 $schema->storage->txn_begin;
97 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
99 my $biblio = $builder->build_sample_biblio;
101 my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
102 $mock->mock( 'enqueue', sub {
103 my ( $self, $args ) = @_;
107 'DelBiblio triggers a holds queue update for the related biblio'
112 $builder->build_object(
114 class => 'Koha::Holds',
116 biblionumber => $biblio->id,
121 C4::Biblio::DelBiblio( $biblio->id );
123 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
125 $biblio = $builder->build_sample_biblio;
127 C4::Biblio::DelBiblio( $biblio->id );
129 $schema->storage->txn_rollback;