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

(-)a/t/db_dependent/Koha/Hold.t (-2 / +94 lines)
Lines 19-29 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
23
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
use Test::Warn;
26
27
28
use t::lib::Mocks;
27
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
28
30
29
use Koha::Libraries;
31
use Koha::Libraries;
Lines 202-204 subtest 'is_pickup_location_valid() tests' => sub { Link Here
202
204
203
    $schema->storage->txn_rollback;
205
    $schema->storage->txn_rollback;
204
};
206
};
205
- 
207
208
subtest 'cancel() tests' => sub {
209
210
    plan tests => 12;
211
212
    $schema->storage->txn_begin;
213
214
    my $get_prepared_letter_called;
215
216
    # Mock GetPreparedLetter so it raises a warning we can look for
217
    # and returns undef, so no call to EnqueueLetter happens
218
    my $mocked_letter = Test::MockModule->new("C4::Letters");
219
    $mocked_letter->mock( 'GetPreparedLetter', sub {
220
        $get_prepared_letter_called = 1;
221
        return;
222
    });
223
224
    my $hold = $builder->build_object(
225
        {
226
            class => 'Koha::Holds',
227
            value => {
228
                cancellationdate    => undef,
229
                priority            => 1,
230
                cancellation_reason => undef,
231
            }
232
        }
233
    );
234
235
    # leave this things out of the test
236
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 0 );
237
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
238
239
    $hold = $builder->build_object(
240
        {
241
            class => 'Koha::Holds',
242
            value => {
243
                cancellationdate    => undef,
244
                priority            => 1,
245
                cancellation_reason => undef,
246
            }
247
        }
248
    );
249
250
    $get_prepared_letter_called = 0;
251
    $hold->cancel({ cancellation_reason => 'Some reason' });
252
    ok( !$get_prepared_letter_called, 'GetPreparedLetter not called' );
253
254
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
255
    is( $hold->priority, 0, 'priority gets set to 0' );
256
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
257
258
    $hold = $builder->build_object(
259
        {
260
            class => 'Koha::Holds',
261
            value => {
262
                cancellationdate    => undef,
263
                priority            => 1,
264
                cancellation_reason => undef,
265
            }
266
        }
267
    );
268
269
    $get_prepared_letter_called = 0;
270
    $hold->cancel({ cancellation_reason => 'Some reason', notify_patron => 1 });
271
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron and cancellation_reason passed' );
272
273
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
274
    is( $hold->priority, 0, 'priority gets set to 0' );
275
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
276
277
    $hold = $builder->build_object(
278
        {
279
            class => 'Koha::Holds',
280
            value => {
281
                cancellationdate    => undef,
282
                priority            => 1,
283
                cancellation_reason => undef,
284
            }
285
        }
286
    );
287
288
    $get_prepared_letter_called = 0;
289
    $hold->cancel({ notify_patron => 1 });
290
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron passed' );
291
292
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
293
    is( $hold->priority, 0, 'priority gets set to 0' );
294
    is( $hold->cancellation_reason, undef, 'cancellation_reason not passed' );
295
296
    $schema->storage->txn_rollback;
297
};

Return to bug 26282