Koha/t/db_dependent/Circulation_holdsqueue.t
Tomas Cohen Arazi 90b76521bf Bug 29346: Circulation actions triggers
This patch introduces triggers for real-time updating the holds queue at
check out and check in.

The following high-level methods are involved:

- C4::Circulation::AddIssue
- C4::Circulation::AddReturn

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Circulation_holdsqueue.t
=> SUCCESS: Tests pass! Triggers are triggered
3. Sign off :-D

Note: I put the tests on a separate file because the other one was too
big already.

Sponsored-by: Montgomery County Public Libraries
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2022-05-05 11:17:35 -10:00

64 lines
1.8 KiB
Perl
Executable file

#!/usr/bin/perl
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 1;
use Test::MockModule;
use C4::Circulation qw( AddIssue AddReturn );
use Koha::Database;
use t::lib::Mocks;
use t::lib::TestBuilder;
my $schema = Koha::Database->schema;
my $builder = t::lib::TestBuilder->new;
subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $library = $builder->build_object({ class => 'Koha::Libraries' });
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $item = $builder->build_sample_item({ library => $library->id });
t::lib::Mocks::mock_userenv({ branchcode => $library->id });
my $action;
my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
$mock->mock( 'enqueue', sub {
my ( $self, $args ) = @_;
is_deeply(
$args->{biblio_ids},
[ $item->biblionumber ],
"$action triggers a holds queue update for the related biblio"
);
} );
$action = 'AddIssue';
AddIssue( $patron->unblessed, $item->barcode, );
$action = 'AddReturn';
AddReturn( $item->barcode );
$schema->storage->txn_rollback;
};