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

(-)a/t/db_dependent/Hold.t (-10 / +96 lines)
Lines 29-35 use Koha::Item; Link Here
29
use Koha::DateUtils;
29
use Koha::DateUtils;
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
32
use Test::More tests => 33;
32
use Test::More tests => 29;
33
use Test::Exception;
33
use Test::Warn;
34
use Test::Warn;
34
35
35
use_ok('Koha::Hold');
36
use_ok('Koha::Hold');
Lines 98-107 is( $hold->suspend_until, undef, "Hold is suspended without a date" ); Link Here
98
$hold->resume();
99
$hold->resume();
99
is( $hold->suspend, 0, "Hold is not suspended" );
100
is( $hold->suspend, 0, "Hold is not suspended" );
100
is( $hold->suspend_until, undef, "Hold no longer has suspend_until date" );
101
is( $hold->suspend_until, undef, "Hold no longer has suspend_until date" );
101
$hold->found('W');
102
warning_like { $hold->suspend_hold }
103
    qr/Unable to suspend waiting hold!/, 'Catch warn about failed suspend';
104
is( $hold->suspend, 0, "Waiting hold cannot be suspended" );
105
102
106
$item = $hold->item();
103
$item = $hold->item();
107
104
Lines 109-118 my $hold_borrower = $hold->borrower(); Link Here
109
ok( $hold_borrower, 'Got hold borrower' );
106
ok( $hold_borrower, 'Got hold borrower' );
110
is( $hold_borrower->borrowernumber(), $borrower->{borrowernumber}, 'Hold borrower matches correct borrower' );
107
is( $hold_borrower->borrowernumber(), $borrower->{borrowernumber}, 'Hold borrower matches correct borrower' );
111
108
112
is( $hold->is_waiting, 1, 'The hold is waiting' );
113
is( $hold->is_found, 1, 'The hold is found');
114
ok( !$hold->is_in_transit, 'The hold is not in transit' );
115
116
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', '5' );
109
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', '5' );
117
$hold->found('T');
110
$hold->found('T');
118
isnt( $hold->is_waiting, 1, 'The hold is not waiting (T)' );
111
isnt( $hold->is_waiting, 1, 'The hold is not waiting (T)' );
Lines 183-185 subtest "delete() tests" => sub { Link Here
183
    $schema->storage->txn_rollback();
176
    $schema->storage->txn_rollback();
184
 };
177
 };
185
178
186
- 
179
subtest 'suspend() tests' => sub {
180
181
    plan tests => 16;
182
183
    $schema->storage->txn_begin;
184
185
    # Disable logging
186
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
187
188
    my $hold = $builder->build_object(
189
        {   class => 'Koha::Holds',
190
            value => { suspend => 0, suspend_until => undef, waitingdate => undef }
191
        }
192
    );
193
194
    ok( !$hold->is_suspended, 'Hold is not suspended' );
195
    my $suspended = $hold->suspend_hold;
196
    is( ref($suspended) , 'Koha::Hold', 'suspend returns the Koha::Hold object' );
197
    is( $suspended->id, $hold->id, 'suspend returns the same object' );
198
    ok( $suspended->is_suspended, 'The hold is suspended' );
199
    is( $suspended->suspend_until, undef, 'It is an indefinite suspension' );
200
201
    # resume the hold
202
    $suspended->resume;
203
    $hold->discard_changes;
204
205
    # create a DT
206
    my $date = dt_from_string()->add( days => 1 );
207
    $suspended = $hold->suspend_hold( $date );
208
    is( ref($suspended) , 'Koha::Hold', 'suspend returns the Koha::Hold object' );
209
    is( $suspended->id, $hold->id, 'suspend returns the same object' );
210
    ok( $suspended->is_suspended, 'The hold is suspended' );
211
    is( $suspended->suspend_until, $date->truncate( to => 'day' ), 'It is an indefinite suspension' );
212
213
    # resume the hold
214
    $suspended->resume;
215
    $hold->discard_changes;
216
217
    # set hold found=W
218
    $hold->set_waiting;
219
    throws_ok
220
        { $hold->suspend_hold; }
221
        'Koha::Exceptions::Hold::CannotSuspendFound',
222
        'Exception is thrown when a found hold is tried to suspend';
223
224
    is( $@->status, 'W', 'Exception gets the \'status\' parameter set correctly' );
225
226
    # set hold found=T
227
    $hold->set_waiting(1);
228
    throws_ok
229
        { $hold->suspend_hold; }
230
        'Koha::Exceptions::Hold::CannotSuspendFound',
231
        'Exception is thrown when a found hold is tried to suspend';
232
233
    is( $@->status, 'T', 'Exception gets the \'status\' parameter set correctly' );
234
235
    my $holds_module = Test::MockModule->new('Koha::Hold');
236
    $holds_module->mock( 'is_found', 1 );
237
238
    # bad data case
239
    $hold->found('X');
240
    throws_ok
241
        { $hold->suspend_hold }
242
        'Koha::Exceptions::Hold::CannotSuspendFound',
243
        'Exception is thrown when a found hold is tried to suspend';
244
245
    is( $@->error, 'Unhandled data exception on found hold (id='
246
                    . $hold->id
247
                    . ', found='
248
                    . $hold->found
249
                    . ')' , 'Exception gets the \'status\' parameter set correctly' );
250
251
    $holds_module->unmock( 'is_found' );
252
253
    # Enable logging
254
    t::lib::Mocks::mock_preference( 'HoldsLog', 1 );
255
256
    my $logs_count = $schema->resultset('ActionLog')->search(
257
            { module => 'HOLDS', action => 'SUSPEND', object => $hold->id } )->count;
258
259
    $hold = $builder->build_object(
260
        {   class => 'Koha::Holds',
261
            value => { suspend => 0, suspend_until => undef, waitingdate => undef, found => undef }
262
        }
263
    );
264
265
    $hold->suspend_hold;
266
    my $new_logs_count = $schema->resultset('ActionLog')->search(
267
            { module => 'HOLDS', action => 'SUSPEND', object => $hold->id } )->count;
268
269
    is( $new_logs_count, $logs_count + 1, 'If logging is enabled, suspending a hold gets logged' );
270
271
    $schema->storage->txn_rollback;
272
};

Return to bug 21478