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

(-)a/t/db_dependent/HoldsQueue.t (-2 / +151 lines)
Lines 8-14 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 58;
11
use Test::More tests => 59;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Calendar qw( new insert_single_holiday );
14
use C4::Calendar qw( new insert_single_holiday );
Lines 1473-1478 subtest 'Excludes from local holds priority' => sub { Link Here
1473
    $next = $queue_rs->next;
1473
    $next = $queue_rs->next;
1474
    is($next->borrowernumber->borrowernumber, $local_patron_excluded->borrowernumber, 'Excluded local patron is queued');
1474
    is($next->borrowernumber->borrowernumber, $local_patron_excluded->borrowernumber, 'Excluded local patron is queued');
1475
};
1475
};
1476
1477
subtest "Test item group holds" => sub {
1478
1479
    plan tests => 4;
1480
1481
    $dbh->do("DELETE FROM tmp_holdsqueue");
1482
    $dbh->do("DELETE FROM hold_fill_targets");
1483
    $dbh->do("DELETE FROM reserves");
1484
    $dbh->do("DELETE FROM circulation_rules");
1485
1486
    t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0);
1487
    t::lib::Mocks::mock_preference('LocalHoldsPriority', 0);
1488
1489
    my $library  = $builder->build_object({ class => 'Koha::Libraries' });
1490
    my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
1491
    my $patron_1 = $builder->build_object(
1492
        {
1493
            class => "Koha::Patrons",
1494
            value => {
1495
                branchcode => $library->branchcode,
1496
                categorycode => $category->categorycode
1497
            }
1498
        }
1499
    );
1500
1501
    my $patron_2 = $builder->build_object(
1502
        {
1503
            class => "Koha::Patrons",
1504
            value => {
1505
                branchcode => $library->branchcode,
1506
                categorycode => $category->categorycode
1507
            }
1508
        }
1509
    );
1510
1511
    my $patron_3 = $builder->build_object(
1512
        {
1513
            class => "Koha::Patrons",
1514
            value => {
1515
                branchcode => $library->branchcode,
1516
                categorycode => $category->categorycode
1517
            }
1518
        }
1519
    );
1520
1521
    my $patron_4 = $builder->build_object(
1522
        {
1523
            class => "Koha::Patrons",
1524
            value => {
1525
                branchcode => $library->branchcode,
1526
                categorycode => $category->categorycode
1527
            }
1528
        }
1529
    );
1530
1531
    my $biblio = $builder->build_sample_biblio();
1532
1533
    my $item_1 = $builder->build_sample_item(
1534
        {
1535
            biblionumber => $biblio->biblionumber,
1536
            library      => $library->branchcode,
1537
            exclude_from_local_holds_priority => 0,
1538
        }
1539
    );
1540
    my $item_2 = $builder->build_sample_item(
1541
        {
1542
            biblionumber => $biblio->biblionumber,
1543
            library      => $library->branchcode,
1544
            exclude_from_local_holds_priority => 0,
1545
        }
1546
    );
1547
    my $item_3 = $builder->build_sample_item(
1548
        {
1549
            biblionumber => $biblio->biblionumber,
1550
            library      => $library->branchcode,
1551
            exclude_from_local_holds_priority => 0,
1552
        }
1553
    );
1554
    my $item_4 = $builder->build_sample_item(
1555
        {
1556
            biblionumber => $biblio->biblionumber,
1557
            library      => $library->branchcode,
1558
            exclude_from_local_holds_priority => 0,
1559
        }
1560
    );
1561
1562
    my $item_group_1 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
1563
    my $item_group_2 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
1564
1565
    $item_group_1->add_item({ item_id => $item_1->id });
1566
    $item_group_1->add_item({ item_id => $item_2->id });
1567
1568
    # Add item-level hold for patron_1
1569
    my $reserve_id_1 = AddReserve(
1570
        {
1571
            branchcode     => $library->branchcode,
1572
            borrowernumber => $patron_1->borrowernumber,
1573
            biblionumber   => $biblio->id,
1574
            itemnumber     => $item_1->itemnumber,
1575
            priority       => 1,
1576
            item_group_id  => $item_group_1->id
1577
        }
1578
    );
1579
1580
    my $reserve_id_2 = AddReserve(
1581
        {
1582
            branchcode     => $library->branchcode,
1583
            borrowernumber => $patron_2->borrowernumber,
1584
            biblionumber   => $biblio->id,
1585
            priority       => 2,
1586
            item_group_id  => $item_group_2->id
1587
        }
1588
    );
1589
1590
    my $reserve_id_3 = AddReserve(
1591
        {
1592
            branchcode     => $library->branchcode,
1593
            borrowernumber => $patron_3->borrowernumber,
1594
            biblionumber   => $biblio->id,
1595
            priority       => 3,
1596
            item_group_id  => $item_group_1->id
1597
        }
1598
    );
1599
1600
    my $reserve_id_4 = AddReserve(
1601
        {
1602
            branchcode     => $library->branchcode,
1603
            borrowernumber => $patron_4->borrowernumber,
1604
            biblionumber   => $biblio->id,
1605
            priority       => 4,
1606
            item_group_id  => undef
1607
        }
1608
    );
1609
1610
    C4::HoldsQueue::CreateQueue();
1611
1612
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
1613
1614
    is( $queue_rs->count(), 3, "Hold queue contains two holds" );
1615
1616
    my $queue_line_1 = $queue_rs->next;
1617
    is( $queue_line_1->borrowernumber->id, $patron_1->id, "Correct Hold was filled for the correct patron, item group 1, priority 1" );
1618
1619
    my $queue_line_2 = $queue_rs->next;
1620
    is( $queue_line_2->borrowernumber->id, $patron_3->id, "Correct Hold was filled for the correct patron, item group 1, priority 2" );
1621
1622
    my $queue_line_3 = $queue_rs->next;
1623
    is( $queue_line_3->borrowernumber->id, $patron_4->id, "Correct Hold was filled for the correct patron, no item group" );
1624
};
1625
1476
# Cleanup
1626
# Cleanup
1477
$schema->storage->txn_rollback;
1627
$schema->storage->txn_rollback;
1478
1628
1479
- 

Return to bug 24860