Lines 2078-2118
subtest 'filter_by_for_hold' => sub {
Link Here
|
2078 |
}; |
2078 |
}; |
2079 |
|
2079 |
|
2080 |
subtest 'filter_by_bookable' => sub { |
2080 |
subtest 'filter_by_bookable' => sub { |
2081 |
plan tests => 3; |
2081 |
plan tests => 4; |
2082 |
|
2082 |
|
2083 |
$schema->storage->txn_begin; |
2083 |
$schema->storage->txn_begin; |
2084 |
|
2084 |
|
2085 |
my $biblio = $builder->build_sample_biblio; |
2085 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
|
|
2086 |
|
2087 |
my $bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2088 |
my $non_bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 0 } } ); |
2089 |
my $biblio = $builder->build_sample_biblio({ itemtype => $bookable_item_type->itemtype }); |
2086 |
|
2090 |
|
2087 |
# bookable items |
2091 |
# bookable items |
2088 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } ); |
2092 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $bookable_item_type->itemtype, bookable => 1 } ); |
2089 |
|
2093 |
|
2090 |
# not bookable items |
2094 |
# not bookable items |
2091 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2095 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2092 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2096 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2093 |
|
2097 |
|
2094 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items" ); |
2098 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items set at item level" ); |
2095 |
is( |
2099 |
is( |
2096 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2100 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2097 |
"the correct item is returned from filter_by_bookable" |
2101 |
"the correct item is returned from filter_by_bookable at the item level" |
2098 |
); |
2102 |
); |
2099 |
|
2103 |
|
2100 |
# unset level booking on item (for itemtype) |
2104 |
$bookable_item1->bookable(undef)->store(); |
2101 |
t::lib::Mocks::mock_preference( 'item-level_booking', 0 ); |
2105 |
$non_bookable_item1->bookable(undef)->store(); |
2102 |
|
2106 |
$non_bookable_item2->bookable(undef)->store(); |
2103 |
# test with itemtype directly bookable |
2107 |
$biblio->get_from_storage; |
2104 |
my $item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2108 |
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" ); |
2105 |
my $biblio2 = $builder->build_sample_biblio( { itemtype => $item_type->itemtype } ); |
|
|
2106 |
|
2109 |
|
2107 |
# bookable items |
2110 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
2108 |
my $bookable_item3 = $builder->build_sample_item( |
2111 |
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" ); |
2109 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 1 } ); |
|
|
2110 |
my $bookable_item4 = $builder->build_sample_item( |
2111 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 0 } ); |
2112 |
|
2113 |
# items are bookable even if bookable => 0 on item (due to itemtype bookable => 1) |
2114 |
is( $biblio2->items->filter_by_bookable->count, 2, "filter_by_bookable returns the correct number of items" ); |
2115 |
|
2112 |
|
2116 |
$schema->storage->txn_rollback; |
2113 |
$schema->storage->txn_rollback; |
2117 |
|
|
|
2118 |
}; |
2114 |
}; |
2119 |
- |
|
|