View | Details | Raw Unified | Return to bug 29087
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Items.t (-6 / +37 lines)
Lines 1998-2013 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 => 13;
2001
    plan tests => 15;
2002
2002
2003
    $schema->storage->txn_begin;
2003
    $schema->storage->txn_begin;
2004
2004
2005
    # Set default rule
2006
    Koha::CirculationRules->set_rule(
2007
        {
2008
            branchcode => undef,
2009
            itemtype   => undef,
2010
            rule_name  => 'holdallowed',
2011
            rule_value => 'not_allowed',
2012
        }
2013
    );
2014
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
2015
    my $not_holdable_itemtype = $itemtype->itemtype;
2016
    my $itemtype2 = $builder->build_object({ class => 'Koha::ItemTypes' });
2017
    my $holdable_itemtype = $itemtype2->itemtype;
2018
    Koha::CirculationRules->set_rule(
2019
        {
2020
            branchcode => undef,
2021
            itemtype   => $holdable_itemtype,
2022
            rule_name  => 'holdallowed',
2023
            rule_value => 'from_any_library',
2024
        }
2025
    );
2026
2005
    my $biblio  = $builder->build_sample_biblio;
2027
    my $biblio  = $builder->build_sample_biblio;
2006
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
2028
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
2007
2008
    t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests
2029
    t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests
2009
2010
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' );
2030
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' );
2031
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $not_holdable_itemtype } );
2032
    is( $biblio->items->filter_by_for_hold->count, 0, 'default rule prevents hold' );
2033
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $holdable_itemtype } );
2034
    is( $biblio->items->filter_by_for_hold->count, 1, 'hold allowed despite default rule' );
2035
2036
    # Reset items and circ rules to remove default rule
2037
    $biblio->items->delete;
2038
    Koha::CirculationRules->search(
2039
        {
2040
            rule_name  => 'holdallowed',
2041
            rule_value => 'not_allowed',
2042
        }
2043
    )->delete;
2044
2011
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } );
2045
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } );
2012
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' );
2046
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' );
2013
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } );
2047
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } );
Lines 2030-2037 subtest 'filter_by_for_hold' => sub { Link Here
2030
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1);
2064
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1);
2031
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' );
2065
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' );
2032
2066
2033
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
2034
    my $not_holdable_itemtype = $itemtype->itemtype;
2035
    $builder->build_sample_item(
2067
    $builder->build_sample_item(
2036
        {
2068
        {
2037
            biblionumber => $biblio->biblionumber,
2069
            biblionumber => $biblio->biblionumber,
2038
- 

Return to bug 29087