Bug 20434: Update UNIMARC framework - authorised values
[koha.git] / t / db_dependent / Reserves / AutoUnsuspendReserves.t
blobd5703cc4e9e86c3e6f7719ddabc3892a98ef0ddc
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 1;
22 use t::lib::Mocks;
23 use t::lib::TestBuilder;
25 use C4::Reserves;
26 use Koha::Database;
27 use Koha::DateUtils;
28 use Koha::Holds;
30 my $schema = Koha::Database->new->schema;
31 my $builder = t::lib::TestBuilder->new;
33 subtest 'AutoUnsuspendReserves test' => sub {
35 plan tests => 4;
37 $schema->storage->txn_begin;
39 my $today = dt_from_string();
40 my $tomorrow = $today->clone->add(days=>1);
42 # Not expired hold
43 my $hold_1 = $builder->build_object({
44 class => 'Koha::Holds',
45 value => {
46 expirationdate => undef,
47 cancellationdate => undef,
48 priority => 5,
49 found => undef,
51 });
53 $hold_1->suspend_hold( $today );
55 # Expired hold
56 my $hold_2 = $builder->build_object({
57 class => 'Koha::Holds',
58 value => {
59 expirationdate => undef,
60 cancellationdate => undef,
61 priority => 6,
62 found => undef,
64 });
66 $hold_2->suspend_hold( $tomorrow );
68 AutoUnsuspendReserves();
70 # refresh
71 $hold_1->discard_changes;
72 $hold_2->discard_changes;
74 ok(!$hold_1->is_suspended, 'Hold suspended until today should be unsuspended.');
75 ok( $hold_2->is_suspended, 'Hold suspended after today should be suspended.');
77 subtest 'logging enabled' => sub {
79 plan tests => 2;
81 # Enable logging
82 t::lib::Mocks::mock_preference( 'HoldsLog', 1 );
84 my $hold_3 = $builder->build_object(
85 { class => 'Koha::Holds',
86 value => {
87 expirationdate => undef,
88 cancellationdate => undef,
89 priority => 5,
90 found => undef,
91 suspend_until => undef,
95 $hold_3->suspend_hold( $today );
97 my $logs_count = $schema->resultset('ActionLog')
98 ->search( { module => 'HOLDS', action => 'RESUME' } )->count;
100 AutoUnsuspendReserves();
102 $hold_3->discard_changes;
103 ok(!$hold_3->is_suspended, 'Hold suspended until today should be unsuspended.');
105 my $new_logs_count = $schema->resultset('ActionLog')
106 ->search( { module => 'HOLDS', action => 'RESUME' } )->count;
108 is( $new_logs_count,
109 $logs_count + 1,
110 'If logging is enabled, calling AutoUnsuspendReserves gets logged'
114 subtest 'logging disabled' => sub {
116 plan tests => 2;
118 # Enable logging
119 t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
121 my $hold_4 = $builder->build_object(
122 { class => 'Koha::Holds',
123 value => {
124 expirationdate => undef,
125 cancellationdate => undef,
126 priority => 5,
127 found => undef
132 my $logs_count = $schema->resultset('ActionLog')
133 ->search( { module => 'HOLDS', action => 'RESUME' } )->count;
135 $hold_4->suspend_hold( $today );
137 AutoUnsuspendReserves();
139 $hold_4->discard_changes;
140 ok(!defined($hold_4->suspend_until), 'Hold suspended until today should be unsuspended.');
142 my $new_logs_count = $schema->resultset('ActionLog')
143 ->search( { module => 'HOLDS', action => 'RESUME' } )->count;
145 is( $new_logs_count,
146 $logs_count,
147 'If logging is not enabled, no logging from AutoUnsuspendReserves calls'
151 $schema->storage->txn_rollback;