Lines 8-14
Link Here
|
8 |
|
8 |
|
9 |
use Modern::Perl; |
9 |
use Modern::Perl; |
10 |
|
10 |
|
11 |
use Test::More tests => 55; |
11 |
use Test::More tests => 56; |
12 |
use Data::Dumper; |
12 |
use Data::Dumper; |
13 |
|
13 |
|
14 |
use C4::Calendar; |
14 |
use C4::Calendar; |
Lines 1522-1527
sub test_queue {
Link Here
|
1522 |
|
1522 |
|
1523 |
} |
1523 |
} |
1524 |
|
1524 |
|
|
|
1525 |
subtest "Test _checkHoldPolicy" => sub { |
1526 |
plan tests => 25; |
1527 |
|
1528 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1529 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1530 |
my $library_nongroup = $builder->build_object( { class => 'Koha::Libraries' } ); |
1531 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1532 |
my $patron = $builder->build_object( |
1533 |
{ |
1534 |
class => "Koha::Patrons", |
1535 |
value => { |
1536 |
branchcode => $library1->branchcode, |
1537 |
categorycode => $category->categorycode, |
1538 |
} |
1539 |
} |
1540 |
); |
1541 |
my $biblio = $builder->build_sample_biblio(); |
1542 |
my $item1 = $builder->build_sample_item( |
1543 |
{ |
1544 |
biblionumber => $biblio->biblionumber, |
1545 |
library => $library1->branchcode, |
1546 |
exclude_from_local_holds_priority => 0, |
1547 |
} |
1548 |
); |
1549 |
|
1550 |
$reserve_id = AddReserve( |
1551 |
{ |
1552 |
branchcode => $item1->homebranch, |
1553 |
borrowernumber => $patron->borrowernumber, |
1554 |
biblionumber => $biblio->id, |
1555 |
priority => 1 |
1556 |
} |
1557 |
); |
1558 |
ok( $reserve_id, "Hold was created"); |
1559 |
my $requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblio->biblionumber); |
1560 |
is( @$requests, 1, "Got correct number of holds"); |
1561 |
|
1562 |
my $request = $requests->[0]; |
1563 |
is( $request->{biblionumber}, $biblio->id, "Hold has correct biblio"); |
1564 |
is( $request->{borrowernumber}, $patron->id, "Hold has correct borrower"); |
1565 |
is( $request->{borrowerbranch}, $patron->branchcode, "Hold has correct borrowerbranch"); |
1566 |
|
1567 |
my $hold = Koha::Holds->find( $reserve_id ); |
1568 |
ok( $hold, "Found hold" ); |
1569 |
|
1570 |
my $item = { |
1571 |
holdallowed => 1, |
1572 |
homebranch => $request->{borrowerbranch}, # library1 |
1573 |
hold_fulfillment_policy => 'any' |
1574 |
}; |
1575 |
|
1576 |
# Base case should work |
1577 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true" ); |
1578 |
|
1579 |
# Test holdallowed = 0 |
1580 |
$item->{holdallowed} = 0; |
1581 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if holdallowed = 0" ); |
1582 |
|
1583 |
# Test holdallowed = 1 |
1584 |
$item->{holdallowed} = 1; |
1585 |
$item->{homebranch} = $library_nongroup->id; |
1586 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if holdallowed = 1 and branches do not match" ); |
1587 |
|
1588 |
$item->{homebranch} = $request->{borrowerbranch}; |
1589 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if holdallowed = 1 and branches do match" ); |
1590 |
|
1591 |
# Test holdallowed = 3 |
1592 |
$item->{holdallowed} = 3; |
1593 |
$item->{homebranch} = $library_nongroup->id; |
1594 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if branchode doesn't match, holdallowed = 3 and no group branches exist" ); |
1595 |
$item->{homebranch} = $request->{borrowerbranch}; |
1596 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if branchode matches, holdallowed = 3 and no group branches exist" ); |
1597 |
|
1598 |
# Create library groups hierarchy |
1599 |
my $rootgroup = $builder->build_object( { class => 'Koha::Library::Groups', value => {ft_local_hold_group => 1} } ); |
1600 |
my $group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); |
1601 |
my $group2 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library2->branchcode}} ); |
1602 |
|
1603 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if holdallowed = 3 and no group branches exist" ); |
1604 |
|
1605 |
$group1->delete; |
1606 |
|
1607 |
# Test hold_fulfillment_policy = holdgroup |
1608 |
$item->{hold_fulfillment_policy} = 'holdgroup'; |
1609 |
$item->{homebranch} = $library_nongroup->id; |
1610 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns true if library is not part of hold group, branches don't match and hfp = holdgroup" ); |
1611 |
$item->{homebranch} = $request->{borrowerbranch}; |
1612 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is not part of hold group, branches match and hfp = holdgroup" ); |
1613 |
|
1614 |
$group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); |
1615 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); |
1616 |
|
1617 |
$item->{homebranch} = $library2->id; |
1618 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); |
1619 |
$item->{homebranch} = $library1->id; |
1620 |
|
1621 |
$group1->delete; |
1622 |
|
1623 |
# Test hold_fulfillment_policy = homebranch |
1624 |
$item->{hold_fulfillment_policy} = 'homebranch'; |
1625 |
$item->{homebranch} = $library_nongroup->id; |
1626 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if hfp = homebranch and pickup branch != item homebranch" ); |
1627 |
|
1628 |
$item->{homebranch} = $request->{borrowerbranch}; |
1629 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if hfp = homebranch and pickup branch = item homebranch" ); |
1630 |
|
1631 |
# Test hold_fulfillment_policy = holdingbranch |
1632 |
$item->{hold_fulfillment_policy} = 'holdingbranch'; |
1633 |
$item->{holdingbranch} = $library_nongroup->id; |
1634 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if hfp = holdingbranch and pickup branch != item holdingbranch" ); |
1635 |
|
1636 |
$item->{holdingbranch} = $request->{borrowerbranch}; |
1637 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if hfp = holdingbranch and pickup branch = item holdingbranch" ); |
1638 |
|
1639 |
# Test hold_fulfillment_policy = patrongroup |
1640 |
$item->{hold_fulfillment_policy} = 'patrongroup'; |
1641 |
$item->{borrowerbranch} = $library1->id; |
1642 |
|
1643 |
$item->{homebranch} = $library_nongroup->id; |
1644 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if library is not part of hold group, branches don't match, hfp = patrongroup" ); |
1645 |
$item->{homebranch} = $request->{borrowerbranch}; |
1646 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns false if library is not part of hold group, branches match, hfp = patrongroup" ); |
1647 |
|
1648 |
$group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); |
1649 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); |
1650 |
|
1651 |
$item->{borrowerbranch} = $library2->id; |
1652 |
is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); |
1653 |
$item->{borrowerbranch} = $library1->id; |
1654 |
}; |
1655 |
|
1525 |
sub dump_records { |
1656 |
sub dump_records { |
1526 |
my ($tablename) = @_; |
1657 |
my ($tablename) = @_; |
1527 |
return $dbh->selectall_arrayref("SELECT * from $tablename where borrowernumber = ?", { Slice => {} }, $borrowernumber); |
1658 |
return $dbh->selectall_arrayref("SELECT * from $tablename where borrowernumber = ?", { Slice => {} }, $borrowernumber); |
1528 |
- |
|
|