Lines 1639-1718
subtest 'can_be_transferred' => sub {
Link Here
|
1639 |
'We get the same result also if we pass the from-library parameter.'); |
1639 |
'We get the same result also if we pass the from-library parameter.'); |
1640 |
}; |
1640 |
}; |
1641 |
|
1641 |
|
1642 |
subtest 'filter_by_for_hold' => sub { |
|
|
1643 |
plan tests => 12; |
1644 |
|
1645 |
Koha::CirculationRules->search( |
1646 |
{ |
1647 |
rule_name => 'holdallowed', |
1648 |
rule_value => 'not_allowed', |
1649 |
} |
1650 |
)->delete; |
1651 |
|
1652 |
my $biblio = $builder->build_sample_biblio; |
1653 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' ); |
1654 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); |
1655 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); |
1656 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); |
1657 |
is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' ); |
1658 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } ); |
1659 |
is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' ); |
1660 |
|
1661 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 0 } ); |
1662 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } ); |
1663 |
is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' ); |
1664 |
|
1665 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 0 } ); |
1666 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } ); |
1667 |
is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' ); |
1668 |
|
1669 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } ); |
1670 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } ); |
1671 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0); |
1672 |
is( $biblio->items->filter_by_for_hold->count, 5, '5 items for hold - not damaged if not AllowHoldsOnDamagedItems' ); |
1673 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); |
1674 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); |
1675 |
|
1676 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
1677 |
my $not_holdable_itemtype = $itemtype->itemtype; |
1678 |
$builder->build_sample_item( |
1679 |
{ |
1680 |
biblionumber => $biblio->biblionumber, |
1681 |
itype => $not_holdable_itemtype, |
1682 |
} |
1683 |
); |
1684 |
Koha::CirculationRules->set_rule( |
1685 |
{ |
1686 |
branchcode => undef, |
1687 |
itemtype => $not_holdable_itemtype, |
1688 |
rule_name => 'holdallowed', |
1689 |
rule_value => 'not_allowed', |
1690 |
} |
1691 |
); |
1692 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - holdallowed=not_allowed' ); |
1693 |
|
1694 |
# Remove rule, test notforloan on itemtype |
1695 |
Koha::CirculationRules->set_rule( |
1696 |
{ |
1697 |
branchcode => undef, |
1698 |
itemtype => $not_holdable_itemtype, |
1699 |
rule_name => 'holdallowed', |
1700 |
rule_value => undef, |
1701 |
} |
1702 |
); |
1703 |
is( $biblio->items->filter_by_for_hold->count, 7, '7 items for hold - rule deleted' ); |
1704 |
$itemtype->notforloan(1)->store; |
1705 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - notforloan' ); |
1706 |
|
1707 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
1708 |
$biblio->biblioitem->itemtype($not_holdable_itemtype)->store; |
1709 |
is( $biblio->items->filter_by_for_hold->count, 0, '0 item-level_itypes=0' ); |
1710 |
|
1711 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
1712 |
|
1713 |
$biblio->delete; |
1714 |
}; |
1715 |
|
1716 |
# Reset nb_of_items prior to testing delete |
1642 |
# Reset nb_of_items prior to testing delete |
1717 |
$nb_of_items = Koha::Items->search->count; |
1643 |
$nb_of_items = Koha::Items->search->count; |
1718 |
|
1644 |
|
Lines 2072-2087
subtest 'search_ordered' => sub {
Link Here
|
2072 |
|
1998 |
|
2073 |
subtest 'filter_by_for_hold' => sub { |
1999 |
subtest 'filter_by_for_hold' => sub { |
2074 |
|
2000 |
|
2075 |
plan tests => 13; |
2001 |
plan tests => 15; |
2076 |
|
2002 |
|
2077 |
$schema->storage->txn_begin; |
2003 |
$schema->storage->txn_begin; |
2078 |
|
2004 |
|
|
|
2005 |
# Set default rule |
2006 |
Koha::CirculationRules->set_rule( |
2007 |
{ |
2008 |
branchcode => undef, |
2009 |
itemtype => undef, |
2010 |
rule_name => 'holdallowed', |
2011 |
rule_value => 'not_allowed', |
2012 |
} |
2013 |
); |
2014 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
2015 |
my $not_holdable_itemtype = $itemtype->itemtype; |
2016 |
my $itemtype2 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
2017 |
my $holdable_itemtype = $itemtype2->itemtype; |
2018 |
Koha::CirculationRules->set_rule( |
2019 |
{ |
2020 |
branchcode => undef, |
2021 |
itemtype => $holdable_itemtype, |
2022 |
rule_name => 'holdallowed', |
2023 |
rule_value => 'from_any_library', |
2024 |
} |
2025 |
); |
2026 |
|
2079 |
my $biblio = $builder->build_sample_biblio; |
2027 |
my $biblio = $builder->build_sample_biblio; |
2080 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
2028 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
2081 |
|
|
|
2082 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests |
2029 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests |
2083 |
|
|
|
2084 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' ); |
2030 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' ); |
|
|
2031 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $not_holdable_itemtype } ); |
2032 |
is( $biblio->items->filter_by_for_hold->count, 0, 'default rule prevents hold' ); |
2033 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $holdable_itemtype } ); |
2034 |
is( $biblio->items->filter_by_for_hold->count, 1, 'hold allowed despite default rule' ); |
2035 |
|
2036 |
# Reset items and circ rules to remove default rule |
2037 |
$biblio->items->delete; |
2038 |
Koha::CirculationRules->search( |
2039 |
{ |
2040 |
rule_name => 'holdallowed', |
2041 |
rule_value => 'not_allowed', |
2042 |
} |
2043 |
)->delete; |
2044 |
|
2085 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); |
2045 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); |
2086 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); |
2046 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); |
2087 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); |
2047 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); |
Lines 2104-2111
subtest 'filter_by_for_hold' => sub {
Link Here
|
2104 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); |
2064 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); |
2105 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); |
2065 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); |
2106 |
|
2066 |
|
2107 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
|
|
2108 |
my $not_holdable_itemtype = $itemtype->itemtype; |
2109 |
$builder->build_sample_item( |
2067 |
$builder->build_sample_item( |
2110 |
{ |
2068 |
{ |
2111 |
biblionumber => $biblio->biblionumber, |
2069 |
biblionumber => $biblio->biblionumber, |
2112 |
- |
|
|