Lines 2176-2216
subtest 'filter_by_for_hold' => sub {
Link Here
|
2176 |
}; |
2176 |
}; |
2177 |
|
2177 |
|
2178 |
subtest 'filter_by_bookable' => sub { |
2178 |
subtest 'filter_by_bookable' => sub { |
2179 |
plan tests => 3; |
2179 |
plan tests => 4; |
2180 |
|
2180 |
|
2181 |
$schema->storage->txn_begin; |
2181 |
$schema->storage->txn_begin; |
2182 |
|
2182 |
|
2183 |
my $biblio = $builder->build_sample_biblio; |
2183 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
|
|
2184 |
|
2185 |
my $bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2186 |
my $non_bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 0 } } ); |
2187 |
my $biblio = $builder->build_sample_biblio({ itemtype => $bookable_item_type->itemtype }); |
2184 |
|
2188 |
|
2185 |
# bookable items |
2189 |
# bookable items |
2186 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } ); |
2190 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $bookable_item_type->itemtype, bookable => 1 } ); |
2187 |
|
2191 |
|
2188 |
# not bookable items |
2192 |
# not bookable items |
2189 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2193 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2190 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2194 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2191 |
|
2195 |
|
2192 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items" ); |
2196 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items set at item level" ); |
2193 |
is( |
2197 |
is( |
2194 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2198 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2195 |
"the correct item is returned from filter_by_bookable" |
2199 |
"the correct item is returned from filter_by_bookable at the item level" |
2196 |
); |
2200 |
); |
2197 |
|
2201 |
|
2198 |
# unset level booking on item (for itemtype) |
2202 |
$bookable_item1->bookable(undef)->store(); |
2199 |
t::lib::Mocks::mock_preference( 'item-level_booking', 0 ); |
2203 |
$non_bookable_item1->bookable(undef)->store(); |
2200 |
|
2204 |
$non_bookable_item2->bookable(undef)->store(); |
2201 |
# test with itemtype directly bookable |
2205 |
$biblio->get_from_storage; |
2202 |
my $item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2206 |
is( $biblio->items->filter_by_bookable->count, 3, "filter_by_bookable returns the correct number of items when not set at item level and using biblio level itemtypes" ); |
2203 |
my $biblio2 = $builder->build_sample_biblio( { itemtype => $item_type->itemtype } ); |
|
|
2204 |
|
2207 |
|
2205 |
# bookable items |
2208 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
2206 |
my $bookable_item3 = $builder->build_sample_item( |
2209 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items when not set at item level and using item level itemtypes" ); |
2207 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 1 } ); |
|
|
2208 |
my $bookable_item4 = $builder->build_sample_item( |
2209 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 0 } ); |
2210 |
|
2211 |
# items are bookable even if bookable => 0 on item (due to itemtype bookable => 1) |
2212 |
is( $biblio2->items->filter_by_bookable->count, 2, "filter_by_bookable returns the correct number of items" ); |
2213 |
|
2210 |
|
2214 |
$schema->storage->txn_rollback; |
2211 |
$schema->storage->txn_rollback; |
2215 |
|
|
|
2216 |
}; |
2212 |
}; |
2217 |
- |
|
|