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

Return to bug 26282