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

(-)a/t/db_dependent/Reserves.t (-3 / +189 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 69;
20
use Test::More tests => 72;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 31-37 use C4::Circulation qw( AddReturn AddIssue ); Link Here
31
use C4::Items;
31
use C4::Items;
32
use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio );
32
use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio );
33
use C4::Members;
33
use C4::Members;
34
use C4::Reserves qw( AddReserve CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
34
use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
35
use Koha::ActionLogs;
35
use Koha::ActionLogs;
36
use Koha::Caches;
36
use Koha::Caches;
37
use Koha::DateUtils qw( dt_from_string output_pref );
37
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 1399-1401 subtest 'IsAvailableForItemLevelRequest() tests' => sub { Link Here
1399
1399
1400
    $schema->storage->txn_rollback;
1400
    $schema->storage->txn_rollback;
1401
};
1401
};
1402
- 
1402
1403
subtest 'AlterPriorty() tests' => sub {
1404
1405
    plan tests => 1;
1406
1407
    $schema->storage->txn_begin;
1408
1409
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
1410
    my $patron_1  = $builder->build_object({ class => 'Koha::Patrons' });
1411
    my $patron_2  = $builder->build_object({ class => 'Koha::Patrons' });
1412
    my $patron_3  = $builder->build_object({ class => 'Koha::Patrons' });
1413
    my $biblio  = $builder->build_sample_biblio;
1414
1415
    my $reserve_id = AddReserve(
1416
        {
1417
            branchcode     => $library->branchcode,
1418
            borrowernumber => $patron_1->id,
1419
            biblionumber   => $biblio->id,
1420
        }
1421
    );
1422
    AddReserve(
1423
        {
1424
            branchcode     => $library->branchcode,
1425
            borrowernumber => $patron_2->id,
1426
            biblionumber   => $biblio->id,
1427
        }
1428
    );
1429
    AddReserve(
1430
        {
1431
            branchcode     => $library->branchcode,
1432
            borrowernumber => $patron_3->id,
1433
            biblionumber   => $biblio->id,
1434
        }
1435
    );
1436
1437
    AlterPriority( "bottom", $reserve_id, 1, 2, 1, 3 );
1438
1439
    my $hold = Koha::Holds->find($reserve_id);
1440
1441
    is($hold->priority,3,'Successfully altered priority to bottom');
1442
1443
    $schema->storage->txn_rollback;
1444
};
1445
1446
subtest 'CanBookBeReserved() tests' => sub {
1447
1448
    plan tests => 2;
1449
1450
    $schema->storage->txn_begin;
1451
1452
    my $library = $builder->build_object(
1453
        { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
1454
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1455
    my $itype  = $builder->build_object( { class => 'Koha::ItemTypes' } );
1456
1457
    my $biblio = $builder->build_sample_biblio();
1458
    my $item_1 = $builder->build_sample_item(
1459
        { biblionumber => $biblio->id, itype => $itype->id } );
1460
    my $item_2 = $builder->build_sample_item(
1461
        { biblionumber => $biblio->id, itype => $itype->id } );
1462
1463
    Koha::CirculationRules->delete;
1464
    Koha::CirculationRules->set_rules(
1465
        {
1466
            branchcode   => undef,
1467
            categorycode => undef,
1468
            itemtype     => undef,
1469
            rules        => {
1470
                holds_per_record => 100,
1471
            }
1472
        }
1473
    );
1474
    Koha::CirculationRules->set_rules(
1475
        {
1476
            branchcode   => undef,
1477
            categorycode => undef,
1478
            itemtype     => $itype->id,
1479
            rules        => {
1480
                reservesallowed => 2,
1481
            }
1482
        }
1483
    );
1484
1485
    C4::Reserves::AddReserve(
1486
        {
1487
            branchcode     => $library->id,
1488
            borrowernumber => $patron->id,
1489
            biblionumber   => $biblio->id,
1490
            title          => $biblio->title,
1491
            itemnumber     => $item_1->id
1492
        }
1493
    );
1494
1495
    ## Limit on item type is 2, only one hold, success tests
1496
1497
    my $res = CanBookBeReserved( $patron->id, $biblio->id, $library->id,
1498
        { itemtype => $itype->id } );
1499
    is_deeply( $res, { status => 'OK' },
1500
        'Holds on itemtype limit not reached' );
1501
1502
    # Add a second hold, biblio-level and item type-constrained
1503
    C4::Reserves::AddReserve(
1504
        {
1505
            branchcode     => $library->id,
1506
            borrowernumber => $patron->id,
1507
            biblionumber   => $biblio->id,
1508
            title          => $biblio->title,
1509
            itemtype       => $itype->id,
1510
        }
1511
    );
1512
1513
    ## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained
1514
1515
    $res = CanBookBeReserved( $patron->id, $biblio->id, $library->id,
1516
        { itemtype => $itype->id } );
1517
    is_deeply( $res, { status => '' }, 'Holds on itemtype limit reached' );
1518
1519
    $schema->storage->txn_rollback;
1520
};
1521
1522
subtest 'CanItemBeReserved() tests' => sub {
1523
1524
    plan tests => 2;
1525
1526
    $schema->storage->txn_begin;
1527
1528
    my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
1529
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
1530
    my $itype   = $builder->build_object( { class => 'Koha::ItemTypes' } );
1531
1532
    my $biblio = $builder->build_sample_biblio();
1533
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id });
1534
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id });
1535
1536
    Koha::CirculationRules->delete;
1537
    Koha::CirculationRules->set_rules(
1538
        {   branchcode   => undef,
1539
            categorycode => undef,
1540
            itemtype     => undef,
1541
            rules        => {
1542
                holds_per_record => 100,
1543
            }
1544
        }
1545
    );
1546
    Koha::CirculationRules->set_rules(
1547
        {   branchcode   => undef,
1548
            categorycode => undef,
1549
            itemtype     => $itype->id,
1550
            rules        => {
1551
                reservesallowed => 2,
1552
            }
1553
        }
1554
    );
1555
1556
    C4::Reserves::AddReserve(
1557
        {
1558
            branchcode     => $library->id,
1559
            borrowernumber => $patron->id,
1560
            biblionumber   => $biblio->id,
1561
            title          => $biblio->title,
1562
            itemnumber     => $item_1->id
1563
        }
1564
    );
1565
1566
    ## Limit on item type is 2, only one hold, success tests
1567
1568
    my $res = CanItemBeReserved( $patron->id, $item_2->id, $library->id );
1569
    is_deeply( $res, { status => 'OK' }, 'Holds on itemtype limit not reached' );
1570
1571
    # Add a second hold, biblio-level and item type-constrained
1572
    C4::Reserves::AddReserve(
1573
        {
1574
            branchcode     => $library->id,
1575
            borrowernumber => $patron->id,
1576
            biblionumber   => $biblio->id,
1577
            title          => $biblio->title,
1578
            itemtype       => $itype->id,
1579
        }
1580
    );
1581
1582
    ## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained
1583
1584
    $res = CanItemBeReserved( $patron->id, $item_2->id, $library->id );
1585
    is_deeply( $res, { status => 'tooManyReserves', limit => 2 }, 'Holds on itemtype limit reached' );
1586
1587
    $schema->storage->txn_rollback;
1588
};

Return to bug 28529