Lines 2112-2152
subtest 'filter_by_for_hold' => sub {
Link Here
|
2112 |
}; |
2112 |
}; |
2113 |
|
2113 |
|
2114 |
subtest 'filter_by_bookable' => sub { |
2114 |
subtest 'filter_by_bookable' => sub { |
2115 |
plan tests => 3; |
2115 |
plan tests => 4; |
2116 |
|
2116 |
|
2117 |
$schema->storage->txn_begin; |
2117 |
$schema->storage->txn_begin; |
2118 |
|
2118 |
|
2119 |
my $biblio = $builder->build_sample_biblio; |
2119 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
|
|
2120 |
|
2121 |
my $bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2122 |
my $non_bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 0 } } ); |
2123 |
my $biblio = $builder->build_sample_biblio({ itemtype => $bookable_item_type->itemtype }); |
2120 |
|
2124 |
|
2121 |
# bookable items |
2125 |
# bookable items |
2122 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } ); |
2126 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $bookable_item_type->itemtype, bookable => 1 } ); |
2123 |
|
2127 |
|
2124 |
# not bookable items |
2128 |
# not bookable items |
2125 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2129 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2126 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2130 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2127 |
|
2131 |
|
2128 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items" ); |
2132 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items set at item level" ); |
2129 |
is( |
2133 |
is( |
2130 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2134 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2131 |
"the correct item is returned from filter_by_bookable" |
2135 |
"the correct item is returned from filter_by_bookable at the item level" |
2132 |
); |
2136 |
); |
2133 |
|
2137 |
|
2134 |
# unset level booking on item (for itemtype) |
2138 |
$bookable_item1->bookable(undef)->store(); |
2135 |
t::lib::Mocks::mock_preference( 'item-level_booking', 0 ); |
2139 |
$non_bookable_item1->bookable(undef)->store(); |
2136 |
|
2140 |
$non_bookable_item2->bookable(undef)->store(); |
2137 |
# test with itemtype directly bookable |
2141 |
$biblio->get_from_storage; |
2138 |
my $item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2142 |
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" ); |
2139 |
my $biblio2 = $builder->build_sample_biblio( { itemtype => $item_type->itemtype } ); |
|
|
2140 |
|
2143 |
|
2141 |
# bookable items |
2144 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
2142 |
my $bookable_item3 = $builder->build_sample_item( |
2145 |
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" ); |
2143 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 1 } ); |
|
|
2144 |
my $bookable_item4 = $builder->build_sample_item( |
2145 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 0 } ); |
2146 |
|
2147 |
# items are bookable even if bookable => 0 on item (due to itemtype bookable => 1) |
2148 |
is( $biblio2->items->filter_by_bookable->count, 2, "filter_by_bookable returns the correct number of items" ); |
2149 |
|
2146 |
|
2150 |
$schema->storage->txn_rollback; |
2147 |
$schema->storage->txn_rollback; |
2151 |
|
|
|
2152 |
}; |
2148 |
}; |
2153 |
- |
|
|