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

(-)a/t/db_dependent/Koha/Items.t (-80 / +37 lines)
Lines 1554-1633 subtest 'can_be_transferred' => sub { Link Here
1554
       'We get the same result also if we pass the from-library parameter.');
1554
       'We get the same result also if we pass the from-library parameter.');
1555
};
1555
};
1556
1556
1557
subtest 'filter_by_for_hold' => sub {
1558
    plan tests => 12;
1559
1560
    Koha::CirculationRules->search(
1561
        {
1562
            rule_name    => 'holdallowed',
1563
            rule_value   => 'not_allowed',
1564
        }
1565
    )->delete;
1566
1567
    my $biblio = $builder->build_sample_biblio;
1568
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' );
1569
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } );
1570
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' );
1571
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } );
1572
    is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' );
1573
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } );
1574
    is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' );
1575
1576
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 0 } );
1577
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } );
1578
    is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' );
1579
1580
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 0 } );
1581
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } );
1582
    is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' );
1583
1584
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } );
1585
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } );
1586
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0);
1587
    is( $biblio->items->filter_by_for_hold->count, 5, '5 items for hold - not damaged if not AllowHoldsOnDamagedItems' );
1588
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1);
1589
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' );
1590
1591
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
1592
    my $not_holdable_itemtype = $itemtype->itemtype;
1593
    $builder->build_sample_item(
1594
        {
1595
            biblionumber => $biblio->biblionumber,
1596
            itype        => $not_holdable_itemtype,
1597
        }
1598
    );
1599
    Koha::CirculationRules->set_rule(
1600
        {
1601
            branchcode   => undef,
1602
            itemtype     => $not_holdable_itemtype,
1603
            rule_name    => 'holdallowed',
1604
            rule_value   => 'not_allowed',
1605
        }
1606
    );
1607
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - holdallowed=not_allowed' );
1608
1609
    # Remove rule, test notforloan on itemtype
1610
    Koha::CirculationRules->set_rule(
1611
        {
1612
            branchcode   => undef,
1613
            itemtype     => $not_holdable_itemtype,
1614
            rule_name    => 'holdallowed',
1615
            rule_value   => undef,
1616
        }
1617
    );
1618
    is( $biblio->items->filter_by_for_hold->count, 7, '7 items for hold - rule deleted' );
1619
    $itemtype->notforloan(1)->store;
1620
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - notforloan' );
1621
1622
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
1623
    $biblio->biblioitem->itemtype($not_holdable_itemtype)->store;
1624
    is( $biblio->items->filter_by_for_hold->count, 0, '0 item-level_itypes=0' );
1625
1626
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
1627
1628
    $biblio->delete;
1629
};
1630
1631
# Reset nb_of_items prior to testing delete
1557
# Reset nb_of_items prior to testing delete
1632
$nb_of_items = Koha::Items->search->count;
1558
$nb_of_items = Koha::Items->search->count;
1633
1559
Lines 1987-2002 subtest 'search_ordered' => sub { Link Here
1987
1913
1988
subtest 'filter_by_for_hold' => sub {
1914
subtest 'filter_by_for_hold' => sub {
1989
1915
1990
    plan tests => 13;
1916
    plan tests => 15;
1991
1917
1992
    $schema->storage->txn_begin;
1918
    $schema->storage->txn_begin;
1993
1919
1920
    # Set default rule
1921
    Koha::CirculationRules->set_rule(
1922
        {
1923
            branchcode => undef,
1924
            itemtype   => undef,
1925
            rule_name  => 'holdallowed',
1926
            rule_value => 'not_allowed',
1927
        }
1928
    );
1929
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
1930
    my $not_holdable_itemtype = $itemtype->itemtype;
1931
    my $itemtype2 = $builder->build_object({ class => 'Koha::ItemTypes' });
1932
    my $holdable_itemtype = $itemtype2->itemtype;
1933
    Koha::CirculationRules->set_rule(
1934
        {
1935
            branchcode => undef,
1936
            itemtype   => $holdable_itemtype,
1937
            rule_name  => 'holdallowed',
1938
            rule_value => 'from_any_library',
1939
        }
1940
    );
1941
1994
    my $biblio  = $builder->build_sample_biblio;
1942
    my $biblio  = $builder->build_sample_biblio;
1995
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
1943
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
1996
1997
    t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests
1944
    t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests
1998
1999
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' );
1945
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' );
1946
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $not_holdable_itemtype } );
1947
    is( $biblio->items->filter_by_for_hold->count, 0, 'default rule prevents hold' );
1948
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $holdable_itemtype } );
1949
    is( $biblio->items->filter_by_for_hold->count, 1, 'hold allowed despite default rule' );
1950
1951
    # Reset items and circ rules to remove default rule
1952
    $biblio->items->delete;
1953
    Koha::CirculationRules->search(
1954
        {
1955
            rule_name  => 'holdallowed',
1956
            rule_value => 'not_allowed',
1957
        }
1958
    )->delete;
1959
2000
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } );
1960
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } );
2001
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' );
1961
    is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' );
2002
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } );
1962
    $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } );
Lines 2019-2026 subtest 'filter_by_for_hold' => sub { Link Here
2019
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1);
1979
    t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1);
2020
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' );
1980
    is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' );
2021
1981
2022
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
2023
    my $not_holdable_itemtype = $itemtype->itemtype;
2024
    $builder->build_sample_item(
1982
    $builder->build_sample_item(
2025
        {
1983
        {
2026
            biblionumber => $biblio->biblionumber,
1984
            biblionumber => $biblio->biblionumber,
2027
- 

Return to bug 29087