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

(-)a/t/db_dependent/Holds.t (-20 / +56 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 71;
10
use Test::More tests => 67;
11
use MARC::Record;
11
use MARC::Record;
12
12
13
use C4::Biblio;
13
use C4::Biblio;
Lines 325-350 ok( Link Here
325
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
325
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
326
}
326
}
327
327
328
Koha::Items->find($itemnumber)->damaged(1)->store; # FIXME The $itemnumber is a bit confusing here
328
subtest 'AllowHoldsOnDamagedItems' => sub {
329
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
329
    plan tests => 5;
330
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
331
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
332
330
333
$hold = Koha::Hold->new(
331
    my $library    = $builder->build_object( { class => 'Koha::Libraries' } );
334
    {
332
    my $biblio     = $builder->build_sample_biblio;
335
        borrowernumber => $borrowernumbers[0],
333
    my $patron     = $builder->build_object( { class => 'Koha::Patrons' } );
336
        itemnumber     => $itemnumber,
334
    my $reserveid1 = AddReserve(
337
        biblionumber   => $biblio->biblionumber,
335
        {
338
    }
336
            branchcode     => $library->branchcode,
339
)->store();
337
            borrowernumber => $patron->borrowernumber,
340
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
338
            biblionumber   => $biblio->biblionumber,
341
    'itemAlreadyOnHold',
339
            priority       => 1
342
    "Patron cannot place a second item level hold for a given item" );
340
        }
343
$hold->delete();
341
    );
344
342
345
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
343
    my $itemnumber = $builder->build_sample_item(
346
ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" );
344
        {
347
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
345
            library      => $library->branchcode,
346
            biblionumber => $biblio->biblionumber,
347
            damaged      => 1
348
        }
349
    )->itemnumber;
350
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
351
    is(
352
        CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status},
353
        'OK',
354
        "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled"
355
    );
356
    ok(
357
        defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled"
358
    );
359
360
    $hold = Koha::Hold->new(
361
        {
362
            borrowernumber => $patron->borrowernumber,
363
            itemnumber     => $itemnumber,
364
            biblionumber   => $biblio->biblionumber,
365
        }
366
    )->store();
367
    is(
368
        CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status},
369
        'itemAlreadyOnHold',
370
        "Patron cannot place a second item level hold for a given item"
371
    );
372
    $hold->delete();
373
374
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
375
    is(
376
        CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status},
377
        'damaged',
378
        "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled"
379
    );
380
    ok(
381
        !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled"
382
    );
383
384
};
348
385
349
# Items that are not for loan, but holdable should not be trapped until they are available for loan
386
# Items that are not for loan, but holdable should not be trapped until they are available for loan
350
t::lib::Mocks::mock_preference( 'TrapHoldsOnOrder', 0 );
387
t::lib::Mocks::mock_preference( 'TrapHoldsOnOrder', 0 );
351
- 

Return to bug 28206