Lines 2002-2042
subtest 'filter_by_for_hold' => sub {
Link Here
|
2002 |
}; |
2002 |
}; |
2003 |
|
2003 |
|
2004 |
subtest 'filter_by_bookable' => sub { |
2004 |
subtest 'filter_by_bookable' => sub { |
2005 |
plan tests => 3; |
2005 |
plan tests => 4; |
2006 |
|
2006 |
|
2007 |
$schema->storage->txn_begin; |
2007 |
$schema->storage->txn_begin; |
2008 |
|
2008 |
|
2009 |
my $biblio = $builder->build_sample_biblio; |
2009 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
|
|
2010 |
|
2011 |
my $bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2012 |
my $non_bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 0 } } ); |
2013 |
my $biblio = $builder->build_sample_biblio({ itemtype => $bookable_item_type->itemtype }); |
2010 |
|
2014 |
|
2011 |
# bookable items |
2015 |
# bookable items |
2012 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } ); |
2016 |
my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $bookable_item_type->itemtype, bookable => 1 } ); |
2013 |
|
2017 |
|
2014 |
# not bookable items |
2018 |
# not bookable items |
2015 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2019 |
my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2016 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } ); |
2020 |
my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } ); |
2017 |
|
2021 |
|
2018 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items" ); |
2022 |
is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items set at item level" ); |
2019 |
is( |
2023 |
is( |
2020 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2024 |
$biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber, |
2021 |
"the correct item is returned from filter_by_bookable" |
2025 |
"the correct item is returned from filter_by_bookable at the item level" |
2022 |
); |
2026 |
); |
2023 |
|
2027 |
|
2024 |
# unset level booking on item (for itemtype) |
2028 |
$bookable_item1->bookable(undef)->store(); |
2025 |
t::lib::Mocks::mock_preference( 'item-level_booking', 0 ); |
2029 |
$non_bookable_item1->bookable(undef)->store(); |
2026 |
|
2030 |
$non_bookable_item2->bookable(undef)->store(); |
2027 |
# test with itemtype directly bookable |
2031 |
$biblio->get_from_storage; |
2028 |
my $item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); |
2032 |
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" ); |
2029 |
my $biblio2 = $builder->build_sample_biblio( { itemtype => $item_type->itemtype } ); |
|
|
2030 |
|
2033 |
|
2031 |
# bookable items |
2034 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
2032 |
my $bookable_item3 = $builder->build_sample_item( |
2035 |
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" ); |
2033 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 1 } ); |
|
|
2034 |
my $bookable_item4 = $builder->build_sample_item( |
2035 |
{ biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 0 } ); |
2036 |
|
2037 |
# items are bookable even if bookable => 0 on item (due to itemtype bookable => 1) |
2038 |
is( $biblio2->items->filter_by_bookable->count, 2, "filter_by_bookable returns the correct number of items" ); |
2039 |
|
2036 |
|
2040 |
$schema->storage->txn_rollback; |
2037 |
$schema->storage->txn_rollback; |
2041 |
|
|
|
2042 |
}; |
2038 |
}; |
2043 |
- |
|
|