View | Details | Raw Unified | Return to bug 34596
Collapse All | Expand All

(-)a/C4/Circulation.pm (-1 / +3 lines)
Lines 415-421 sub transferbook { Link Here
415
        $messages->{'WasTransfered'} = $tbr;
415
        $messages->{'WasTransfered'} = $tbr;
416
416
417
    }
417
    }
418
    ModDateLastSeen($itemnumber);
418
419
    # Only build the holds queue if we have transferred above
420
    ModDateLastSeen( $itemnumber, undef, { skip_holds_queue => 1 } );
419
    return ( $dotransfer, $messages );
421
    return ( $dotransfer, $messages );
420
}
422
}
421
423
(-)a/t/db_dependent/Circulation_holdsqueue.t (-79 lines)
Lines 1-79 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
use Test::NoWarnings;
22
use Test::MockModule;
23
24
use C4::Circulation qw( AddIssue AddReturn );
25
26
use Koha::Database;
27
28
use t::lib::Mocks;
29
use t::lib::TestBuilder;
30
31
my $schema  = Koha::Database->schema;
32
my $builder = t::lib::TestBuilder->new;
33
34
subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub {
35
36
    plan tests => 2;
37
38
    $schema->storage->txn_begin;
39
40
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
41
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
42
    my $item    = $builder->build_sample_item( { library => $library->id } );
43
44
    t::lib::Mocks::mock_userenv( { branchcode => $library->id } );
45
    t::lib::Mocks::mock_preference( 'UpdateTotalIssuesOnCirc', 1 );
46
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue',      1 );
47
48
    my $action;
49
50
    my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
51
    $mock->mock(
52
        'enqueue',
53
        sub {
54
            my ( $self, $args ) = @_;
55
            my ( $package, $filename, $line ) = caller;
56
            is_deeply(
57
                $args->{biblio_ids},
58
                [ $item->biblionumber ],
59
                "$action triggers a holds queue update for the related biblio from $package at line $line"
60
            );
61
        }
62
    );
63
64
    $action = 'AddIssue';
65
    AddIssue( $patron, $item->barcode, );
66
67
    $action = 'AddReturn';
68
    AddReturn( $item->barcode );
69
70
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
71
72
    $action = 'AddIssue';
73
    AddIssue( $patron, $item->barcode, );
74
75
    $action = 'AddReturn';
76
    AddReturn( $item->barcode );
77
78
    $schema->storage->txn_rollback;
79
};
(-)a/t/db_dependent/Realtime_holdsqueue.t (-1 / +134 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
use Test::NoWarnings;
22
use Test::MockModule;
23
24
use C4::Circulation qw( AddIssue AddReturn transferbook );
25
use C4::SIP::ILS;
26
use C4::SIP::ILS::Transaction::Checkin qw( do_checkin );
27
28
use Koha::Checkouts;
29
use Koha::Database;
30
31
use t::lib::Mocks;
32
use t::lib::TestBuilder;
33
34
my $schema  = Koha::Database->schema;
35
my $builder = t::lib::TestBuilder->new;
36
37
subtest 'Real-time holds queue tests' => sub {
38
39
    plan tests => 5;
40
41
    $schema->storage->txn_begin;
42
43
    my $library   = $builder->build_object( { class => 'Koha::Libraries' } );
44
    my $library1  = $builder->build_object( { class => 'Koha::Libraries' } );
45
    my $patron    = $builder->build_object( { class => 'Koha::Patrons' } );
46
    my $item      = $builder->build_sample_item( { library => $library->id } );
47
    my $item_type = $item->item_type;
48
    $item_type->automatic_checkin(1)->store();
49
50
    t::lib::Mocks::mock_userenv( { branchcode => $library->id } );
51
    t::lib::Mocks::mock_preference( 'UpdateTotalIssuesOnCirc', 1 );
52
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue',      1 );
53
54
    my $action;
55
56
    my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
57
    $mock->mock(
58
        'enqueue',
59
        sub {
60
            my ( $self, $args ) = @_;
61
            my ( $package, $filename, $line ) = caller;
62
            is_deeply(
63
                $args->{biblio_ids},
64
                [ $item->biblionumber ],
65
                "$action triggers a holds queue update for the related biblio from $package at line $line"
66
            );
67
        }
68
    );
69
70
    # Test 1
71
    $action = 'AddIssue';
72
    AddIssue( $patron, $item->barcode, );
73
74
    # Called to remove item from the queue
75
76
    $action = 'AddReturn';
77
    AddReturn( $item->barcode );
78
79
    # Not called
80
81
    # Test 2
82
    $action = 'transferbook';
83
    transferbook(
84
        {
85
            barcode     => $item->barcode,
86
            to_branch   => $library1->branchcode,
87
            from_branch => $library->branchcode,
88
            trigger     => 'Manual',
89
        }
90
    );
91
92
    # Test 3 + 4
93
    $action = 'do_checkin';
94
    my $mockILS        = Test::MockObject->new;
95
    my $server         = { ils => $mockILS };
96
    my $sip_patron     = C4::SIP::ILS::Patron->new( $patron->cardnumber );
97
    my $sip_item       = C4::SIP::ILS::Item->new( $item->barcode );
98
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
99
    $co_transaction->patron($sip_patron);
100
    $co_transaction->item($sip_item);
101
102
    # Queue rebuilt by checkout
103
    my $checkout       = $co_transaction->do_checkout();
104
    my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new();
105
    $ci_transaction->patron($sip_patron);
106
    $ci_transaction->item($sip_item);
107
108
    # Queue rebuilt on checkin
109
    my $checkin = $ci_transaction->do_checkin( $library->branchcode, C4::SIP::Sip::timestamp );
110
111
    # Test 5+6
112
    $action = 'automatic_checkin';
113
    AddIssue( $patron, $item->barcode, );
114
115
    # Called to remove item from the queue
116
    my $checkouts = Koha::Checkouts->search( { 'me.itemnumber' => $item->itemnumber } );
117
    $checkouts->automatic_checkin;
118
119
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
120
121
    # Below should not generate any tests as queue is deactivated
122
123
    $action = 'AddIssue';
124
    AddIssue( $patron, $item->barcode, );
125
126
    # Not called
127
128
    $action = 'AddReturn';
129
    AddReturn( $item->barcode );
130
131
    # Not called
132
133
    $schema->storage->txn_rollback;
134
};

Return to bug 34596