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

(-)a/t/db_dependent/Koha/Hold.t (-19 / +31 lines)
Lines 166-183 subtest 'fill() tests' => sub { Link Here
166
166
167
    subtest 'anonymization behavior tests' => sub {
167
    subtest 'anonymization behavior tests' => sub {
168
168
169
        plan tests => 4;
169
        plan tests => 5;
170
170
171
        # reduce the tests noise
171
        # reduce the tests noise
172
        t::lib::Mocks::mock_preference( 'HoldsLog',    0 );
172
        t::lib::Mocks::mock_preference( 'HoldsLog',    0 );
173
        t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
173
        t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
174
        # unset AnonymousPatron
175
        t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
174
176
175
        # 0 == keep forever
177
        # 0 == keep forever
176
        $patron->privacy(0)->store;
178
        $patron->privacy(0)->store;
177
        my $hold = $builder->build_object(
179
        my $hold = $builder->build_object(
178
            {
180
            {
179
                class => 'Koha::Holds',
181
                class => 'Koha::Holds',
180
                value => { borrowernumber => $patron->id, status => undef }
182
                value => { borrowernumber => $patron->id, found => undef }
181
            }
183
            }
182
        );
184
        );
183
        $hold->fill();
185
        $hold->fill();
Lines 189-195 subtest 'fill() tests' => sub { Link Here
189
        $hold = $builder->build_object(
191
        $hold = $builder->build_object(
190
            {
192
            {
191
                class => 'Koha::Holds',
193
                class => 'Koha::Holds',
192
                value => { borrowernumber => $patron->id, status => undef }
194
                value => { borrowernumber => $patron->id, found => undef }
193
            }
195
            }
194
        );
196
        );
195
        $hold->fill();
197
        $hold->fill();
Lines 201-212 subtest 'fill() tests' => sub { Link Here
201
        $hold = $builder->build_object(
203
        $hold = $builder->build_object(
202
            {
204
            {
203
                class => 'Koha::Holds',
205
                class => 'Koha::Holds',
204
                value => { borrowernumber => $patron->id, status => undef }
206
                value => { borrowernumber => $patron->id, found => undef }
205
            }
207
            }
206
        );
208
        );
207
        $hold->fill();
209
208
        is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
210
        throws_ok
209
            undef, 'Patron link is deleted immediately' );
211
            { $hold->fill(); }
212
            'Koha::Exception',
213
            'AnonymousPatron not set, exception thrown';
214
215
        $hold->discard_changes; # refresh from DB
216
217
        ok( !$hold->is_found, 'Hold is not filled' );
210
218
211
        my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
219
        my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
212
        t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
220
        t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
Lines 214-223 subtest 'fill() tests' => sub { Link Here
214
        $hold = $builder->build_object(
222
        $hold = $builder->build_object(
215
            {
223
            {
216
                class => 'Koha::Holds',
224
                class => 'Koha::Holds',
217
                value => { borrowernumber => $patron->id, status => undef }
225
                value => { borrowernumber => $patron->id, found => undef }
218
            }
226
            }
219
        );
227
        );
220
        $hold->cancel();
228
        $hold->fill();
221
        is(
229
        is(
222
            Koha::Old::Holds->find( $hold->id )->borrowernumber,
230
            Koha::Old::Holds->find( $hold->id )->borrowernumber,
223
            $anonymous_patron->id,
231
            $anonymous_patron->id,
Lines 337-343 subtest 'set_pickup_location() tests' => sub { Link Here
337
        'Koha::Exceptions::MissingParameter',
345
        'Koha::Exceptions::MissingParameter',
338
        'Exception thrown if missing parameter';
346
        'Exception thrown if missing parameter';
339
347
340
    is( "$@", 'The library_id parameter is mandatory', 'Exception message is clear' );
348
    like( "$@", qr/The library_id parameter is mandatory/, 'Exception message is clear' );
341
349
342
    $schema->storage->txn_rollback;
350
    $schema->storage->txn_rollback;
343
};
351
};
Lines 448-454 subtest 'is_pickup_location_valid() tests' => sub { Link Here
448
456
449
subtest 'cancel() tests' => sub {
457
subtest 'cancel() tests' => sub {
450
458
451
    plan tests => 4;
459
    plan tests => 5;
452
460
453
    $schema->storage->txn_begin;
461
    $schema->storage->txn_begin;
454
462
Lines 466-472 subtest 'cancel() tests' => sub { Link Here
466
    my $hold = $builder->build_object(
474
    my $hold = $builder->build_object(
467
        {
475
        {
468
            class => 'Koha::Holds',
476
            class => 'Koha::Holds',
469
            value => { borrowernumber => $patron->id, status => undef }
477
            value => { borrowernumber => $patron->id, found => undef }
470
        }
478
        }
471
    );
479
    );
472
    $hold->cancel();
480
    $hold->cancel();
Lines 478-484 subtest 'cancel() tests' => sub { Link Here
478
    $hold = $builder->build_object(
486
    $hold = $builder->build_object(
479
        {
487
        {
480
            class => 'Koha::Holds',
488
            class => 'Koha::Holds',
481
            value => { borrowernumber => $patron->id, status => undef }
489
            value => { borrowernumber => $patron->id, found => undef }
482
        }
490
        }
483
    );
491
    );
484
    $hold->cancel();
492
    $hold->cancel();
Lines 490-501 subtest 'cancel() tests' => sub { Link Here
490
    $hold = $builder->build_object(
498
    $hold = $builder->build_object(
491
        {
499
        {
492
            class => 'Koha::Holds',
500
            class => 'Koha::Holds',
493
            value => { borrowernumber => $patron->id, status => undef }
501
            value => { borrowernumber => $patron->id, found => undef }
494
        }
502
        }
495
    );
503
    );
496
    $hold->cancel();
504
    throws_ok
497
    is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
505
        { $hold->cancel(); }
498
        undef, 'Patron link is deleted immediately' );
506
        'Koha::Exception',
507
        'AnonymousPatron not set, exception thrown';
508
509
    $hold->discard_changes;
510
511
    ok( !$hold->is_found, 'Hold is not cancelled' );
499
512
500
    my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
513
    my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
501
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
514
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
Lines 503-509 subtest 'cancel() tests' => sub { Link Here
503
    $hold = $builder->build_object(
516
    $hold = $builder->build_object(
504
        {
517
        {
505
            class => 'Koha::Holds',
518
            class => 'Koha::Holds',
506
            value => { borrowernumber => $patron->id, status => undef }
519
            value => { borrowernumber => $patron->id, found => undef }
507
        }
520
        }
508
    );
521
    );
509
    $hold->cancel();
522
    $hold->cancel();
510
- 

Return to bug 30007