|
Lines 1-6
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
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 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
|
|
19 |
|
| 4 |
use Test::More tests => 1; |
20 |
use Test::More tests => 1; |
| 5 |
|
21 |
|
| 6 |
use t::lib::Mocks; |
22 |
use t::lib::Mocks; |
|
Lines 12-57
use Koha::DateUtils;
Link Here
|
| 12 |
use Koha::Holds; |
28 |
use Koha::Holds; |
| 13 |
|
29 |
|
| 14 |
my $schema = Koha::Database->new->schema; |
30 |
my $schema = Koha::Database->new->schema; |
| 15 |
$schema->storage->txn_begin; |
31 |
my $builder = t::lib::TestBuilder->new; |
| 16 |
|
32 |
|
| 17 |
subtest 'AutoUnsuspendReserves test' => sub { |
33 |
subtest 'AutoUnsuspendReserves test' => sub { |
| 18 |
plan tests => 2; |
|
|
| 19 |
|
34 |
|
| 20 |
my $builder = t::lib::TestBuilder->new(); |
35 |
plan tests => 4; |
| 21 |
|
36 |
|
| 22 |
my $today = dt_from_string(); |
37 |
$schema->storage->txn_begin; |
| 23 |
my $today_date = output_pref({ dateformat => 'sql' }); |
|
|
| 24 |
my $tomorrow_date = output_pref({ dt => $today->add(days=>1), dateformat=>'sql' }); |
| 25 |
|
38 |
|
| 26 |
# Reserve not expired |
39 |
my $today = dt_from_string(); |
| 27 |
my $reserve1 = $builder->build({ |
40 |
my $tomorrow = $today->clone->add(days=>1); |
| 28 |
source => 'Reserve', |
41 |
|
|
|
42 |
# Not expired hold |
| 43 |
my $hold_1 = $builder->build_object({ |
| 44 |
class => 'Koha::Holds', |
| 29 |
value => { |
45 |
value => { |
| 30 |
expirationdate => undef, |
46 |
expirationdate => undef, |
| 31 |
cancellationdate => undef, |
47 |
cancellationdate => undef, |
| 32 |
priority => 5, |
48 |
priority => 5, |
| 33 |
found => undef, |
49 |
found => undef, |
| 34 |
suspend_until => $today_date, |
|
|
| 35 |
}, |
50 |
}, |
| 36 |
}); |
51 |
}); |
| 37 |
# Reserve expired |
52 |
|
| 38 |
my $reserve2 = $builder->build({ |
53 |
$hold_1->suspend_hold( $today ); |
| 39 |
source => 'Reserve', |
54 |
|
|
|
55 |
# Expired hold |
| 56 |
my $hold_2 = $builder->build_object({ |
| 57 |
class => 'Koha::Holds', |
| 40 |
value => { |
58 |
value => { |
| 41 |
expirationdate => undef, |
59 |
expirationdate => undef, |
| 42 |
cancellationdate => undef, |
60 |
cancellationdate => undef, |
| 43 |
priority => 6, |
61 |
priority => 6, |
| 44 |
found => undef, |
62 |
found => undef, |
| 45 |
suspend_until => $tomorrow_date, |
|
|
| 46 |
}, |
63 |
}, |
| 47 |
}); |
64 |
}); |
| 48 |
|
65 |
|
|
|
66 |
$hold_2->suspend_hold( $tomorrow ); |
| 67 |
|
| 49 |
AutoUnsuspendReserves(); |
68 |
AutoUnsuspendReserves(); |
| 50 |
my $r1 = Koha::Holds->find($reserve1->{reserve_id}); |
|
|
| 51 |
my $r2 = Koha::Holds->find($reserve2->{reserve_id}); |
| 52 |
ok(!defined($r1->suspend_until), 'Reserve suspended until today should be unsuspended.'); |
| 53 |
ok(defined($r2->suspend_until), 'Reserve suspended after today should be suspended.'); |
| 54 |
|
69 |
|
| 55 |
}; |
70 |
# refresh |
|
|
71 |
$hold_1->discard_changes; |
| 72 |
$hold_2->discard_changes; |
| 73 |
|
| 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.'); |
| 76 |
|
| 77 |
subtest 'logging enabled' => sub { |
| 78 |
|
| 79 |
plan tests => 2; |
| 80 |
|
| 81 |
# Enable logging |
| 82 |
t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); |
| 83 |
|
| 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, |
| 92 |
} |
| 93 |
} |
| 94 |
); |
| 95 |
$hold_3->suspend_hold( $today ); |
| 96 |
|
| 97 |
my $logs_count = $schema->resultset('ActionLog') |
| 98 |
->search( { module => 'HOLDS', action => 'RESUME' } )->count; |
| 99 |
|
| 100 |
AutoUnsuspendReserves(); |
| 56 |
|
101 |
|
| 57 |
$schema->storage->txn_rollback; |
102 |
$hold_3->discard_changes; |
|
|
103 |
ok(!$hold_3->is_suspended, 'Hold suspended until today should be unsuspended.'); |
| 104 |
|
| 105 |
my $new_logs_count = $schema->resultset('ActionLog') |
| 106 |
->search( { module => 'HOLDS', action => 'RESUME' } )->count; |
| 107 |
|
| 108 |
is( $new_logs_count, |
| 109 |
$logs_count + 1, |
| 110 |
'If logging is enabled, calling AutoUnsuspendReserves gets logged' |
| 111 |
); |
| 112 |
}; |
| 113 |
|
| 114 |
subtest 'logging disabled' => sub { |
| 115 |
|
| 116 |
plan tests => 2; |
| 117 |
|
| 118 |
# Enable logging |
| 119 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 120 |
|
| 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 |
| 128 |
} |
| 129 |
} |
| 130 |
); |
| 131 |
|
| 132 |
my $logs_count = $schema->resultset('ActionLog') |
| 133 |
->search( { module => 'HOLDS', action => 'RESUME' } )->count; |
| 134 |
|
| 135 |
$hold_4->suspend_hold( $today ); |
| 136 |
|
| 137 |
AutoUnsuspendReserves(); |
| 138 |
|
| 139 |
$hold_4->discard_changes; |
| 140 |
ok(!defined($hold_4->suspend_until), 'Hold suspended until today should be unsuspended.'); |
| 141 |
|
| 142 |
my $new_logs_count = $schema->resultset('ActionLog') |
| 143 |
->search( { module => 'HOLDS', action => 'RESUME' } )->count; |
| 144 |
|
| 145 |
is( $new_logs_count, |
| 146 |
$logs_count, |
| 147 |
'If logging is not enabled, no logging from AutoUnsuspendReserves calls' |
| 148 |
); |
| 149 |
}; |
| 150 |
|
| 151 |
$schema->storage->txn_rollback; |
| 152 |
}; |
| 58 |
- |
|
|