Lines 1998-2004
subtest 'search_ordered' => sub {
Link Here
|
1998 |
|
1998 |
|
1999 |
subtest 'filter_by_for_hold' => sub { |
1999 |
subtest 'filter_by_for_hold' => sub { |
2000 |
|
2000 |
|
2001 |
plan tests => 15; |
2001 |
plan tests => 10; |
2002 |
|
2002 |
|
2003 |
$schema->storage->txn_begin; |
2003 |
$schema->storage->txn_begin; |
2004 |
|
2004 |
|
Lines 2035-2070
subtest 'filter_by_for_hold' => sub {
Link Here
|
2035 |
{ biblionumber => $biblio->biblionumber, notforloan => 0, itype => $holdable_itemtype } ); |
2035 |
{ biblionumber => $biblio->biblionumber, notforloan => 0, itype => $holdable_itemtype } ); |
2036 |
is( $biblio->items->filter_by_for_hold->count, 1, 'hold allowed despite default rule' ); |
2036 |
is( $biblio->items->filter_by_for_hold->count, 1, 'hold allowed despite default rule' ); |
2037 |
|
2037 |
|
2038 |
# Reset items and circ rules to remove default rule |
2038 |
subtest "No default rule" => sub { |
2039 |
$biblio->items->delete; |
2039 |
plan tests => 7; |
2040 |
Koha::CirculationRules->search( |
2040 |
|
2041 |
{ |
2041 |
# Reset items and circ rules to remove default rule |
2042 |
rule_name => 'holdallowed', |
2042 |
$biblio->items->delete; |
2043 |
rule_value => 'not_allowed', |
2043 |
Koha::CirculationRules->search( |
2044 |
} |
2044 |
{ |
2045 |
)->delete; |
2045 |
rule_name => 'holdallowed', |
2046 |
|
2046 |
rule_value => 'not_allowed', |
2047 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); |
2047 |
} |
2048 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); |
2048 |
)->delete; |
2049 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); |
2049 |
|
2050 |
is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' ); |
2050 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); |
2051 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } ); |
2051 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); |
2052 |
is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' ); |
2052 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); |
2053 |
|
2053 |
is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' ); |
2054 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 0, library => $library->id } ); |
2054 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } ); |
2055 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1, library => $library->id } ); |
2055 |
is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' ); |
2056 |
is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' ); |
2056 |
|
2057 |
|
2057 |
$builder->build_sample_item( |
2058 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 0, library => $library->id } ); |
2058 |
{ biblionumber => $biblio->biblionumber, itemlost => 0, library => $library->id } ); |
2059 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1, library => $library->id } ); |
2059 |
$builder->build_sample_item( |
2060 |
is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' ); |
2060 |
{ biblionumber => $biblio->biblionumber, itemlost => 1, library => $library->id } ); |
2061 |
|
2061 |
is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' ); |
2062 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } ); |
2062 |
|
2063 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } ); |
2063 |
$builder->build_sample_item( |
2064 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0); |
2064 |
{ biblionumber => $biblio->biblionumber, withdrawn => 0, library => $library->id } ); |
2065 |
is( $biblio->items->filter_by_for_hold->count, 5, '5 items for hold - not damaged if not AllowHoldsOnDamagedItems' ); |
2065 |
$builder->build_sample_item( |
2066 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); |
2066 |
{ biblionumber => $biblio->biblionumber, withdrawn => 1, library => $library->id } ); |
2067 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); |
2067 |
is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' ); |
|
|
2068 |
|
2069 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } ); |
2070 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } ); |
2071 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); |
2072 |
is( |
2073 |
$biblio->items->filter_by_for_hold->count, 5, |
2074 |
'5 items for hold - not damaged if not AllowHoldsOnDamagedItems' |
2075 |
); |
2076 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
2077 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); |
2078 |
}; |
2079 |
|
2080 |
subtest "Default rule from_any_library" => sub { |
2081 |
|
2082 |
plan tests => 7; |
2083 |
|
2084 |
$biblio->items->delete; |
2085 |
Koha::CirculationRules->set_rule( |
2086 |
{ |
2087 |
branchcode => undef, |
2088 |
itemtype => undef, |
2089 |
rule_name => 'holdallowed', |
2090 |
rule_value => 'from_any_library', |
2091 |
} |
2092 |
); |
2093 |
|
2094 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); |
2095 |
is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); |
2096 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); |
2097 |
is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' ); |
2098 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } ); |
2099 |
is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' ); |
2100 |
|
2101 |
$builder->build_sample_item( |
2102 |
{ biblionumber => $biblio->biblionumber, itemlost => 0, library => $library->id } ); |
2103 |
$builder->build_sample_item( |
2104 |
{ biblionumber => $biblio->biblionumber, itemlost => 1, library => $library->id } ); |
2105 |
is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' ); |
2106 |
|
2107 |
$builder->build_sample_item( |
2108 |
{ biblionumber => $biblio->biblionumber, withdrawn => 0, library => $library->id } ); |
2109 |
$builder->build_sample_item( |
2110 |
{ biblionumber => $biblio->biblionumber, withdrawn => 1, library => $library->id } ); |
2111 |
is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' ); |
2112 |
|
2113 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } ); |
2114 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } ); |
2115 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); |
2116 |
is( |
2117 |
$biblio->items->filter_by_for_hold->count, 5, |
2118 |
'5 items for hold - not damaged if not AllowHoldsOnDamagedItems' |
2119 |
); |
2120 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
2121 |
is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); |
2122 |
|
2123 |
Koha::CirculationRules->search( |
2124 |
{ |
2125 |
rule_name => 'holdallowed', |
2126 |
branchcode => undef, |
2127 |
itemtype => undef, |
2128 |
rule_value => 'from_any_library', |
2129 |
} |
2130 |
)->delete; |
2131 |
}; |
2068 |
|
2132 |
|
2069 |
$builder->build_sample_item( |
2133 |
$builder->build_sample_item( |
2070 |
{ |
2134 |
{ |
2071 |
- |
|
|