| Lines 1510-1582
          subtest 'can_be_transferred' => sub {
      
      
        Link Here | 
        
          | 1510 |        'We get the same result also if we pass the from-library parameter.'); | 1510 |        'We get the same result also if we pass the from-library parameter.'); | 
        
          | 1511 | }; | 1511 | }; | 
        
          | 1512 |  | 1512 |  | 
            
              | 1513 | subtest 'filter_by_for_hold' => sub { |  |  | 
            
              | 1514 |     plan tests => 12; | 
            
              | 1515 |  | 
            
              | 1516 |     my $biblio = $builder->build_sample_biblio; | 
            
              | 1517 |     is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' ); | 
            
              | 1518 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); | 
            
              | 1519 |     is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); | 
            
              | 1520 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); | 
            
              | 1521 |     is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' ); | 
            
              | 1522 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } ); | 
            
              | 1523 |     is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' ); | 
            
              | 1524 |  | 
            
              | 1525 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 0 } ); | 
            
              | 1526 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } ); | 
            
              | 1527 |     is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' ); | 
            
              | 1528 |  | 
            
              | 1529 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 0 } ); | 
            
              | 1530 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } ); | 
            
              | 1531 |     is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' ); | 
            
              | 1532 |  | 
            
              | 1533 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } ); | 
            
              | 1534 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } ); | 
            
              | 1535 |     t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0); | 
            
              | 1536 |     is( $biblio->items->filter_by_for_hold->count, 5, '5 items for hold - not damaged if not AllowHoldsOnDamagedItems' ); | 
            
              | 1537 |     t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); | 
            
              | 1538 |     is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); | 
            
              | 1539 |  | 
            
              | 1540 |     my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); | 
            
              | 1541 |     my $not_holdable_itemtype = $itemtype->itemtype; | 
            
              | 1542 |     $builder->build_sample_item( | 
            
              | 1543 |         { | 
            
              | 1544 |             biblionumber => $biblio->biblionumber, | 
            
              | 1545 |             itype        => $not_holdable_itemtype, | 
            
              | 1546 |         } | 
            
              | 1547 |     ); | 
            
              | 1548 |     Koha::CirculationRules->set_rule( | 
            
              | 1549 |         { | 
            
              | 1550 |             branchcode   => undef, | 
            
              | 1551 |             itemtype     => $not_holdable_itemtype, | 
            
              | 1552 |             rule_name    => 'holdallowed', | 
            
              | 1553 |             rule_value   => 'not_allowed', | 
            
              | 1554 |         } | 
            
              | 1555 |     ); | 
            
              | 1556 |     is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - holdallowed=not_allowed' ); | 
            
              | 1557 |  | 
            
              | 1558 |     # Remove rule, test notforloan on itemtype | 
            
              | 1559 |     Koha::CirculationRules->set_rule( | 
            
              | 1560 |         { | 
            
              | 1561 |             branchcode   => undef, | 
            
              | 1562 |             itemtype     => $not_holdable_itemtype, | 
            
              | 1563 |             rule_name    => 'holdallowed', | 
            
              | 1564 |             rule_value   => undef, | 
            
              | 1565 |         } | 
            
              | 1566 |     ); | 
            
              | 1567 |     is( $biblio->items->filter_by_for_hold->count, 7, '7 items for hold - rule deleted' ); | 
            
              | 1568 |     $itemtype->notforloan(1)->store; | 
            
              | 1569 |     is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - notforloan' ); | 
            
              | 1570 |  | 
            
              | 1571 |     t::lib::Mocks::mock_preference('item-level_itypes', 0); | 
            
              | 1572 |     $biblio->biblioitem->itemtype($not_holdable_itemtype)->store; | 
            
              | 1573 |     is( $biblio->items->filter_by_for_hold->count, 0, '0 item-level_itypes=0' ); | 
            
              | 1574 |  | 
            
              | 1575 |     t::lib::Mocks::mock_preference('item-level_itypes', 1); | 
            
              | 1576 |  | 
            
              | 1577 |     $biblio->delete; | 
            
              | 1578 | }; | 
            
              | 1579 |  | 
        
          | 1580 | # Reset nb_of_items prior to testing delete | 1513 | # Reset nb_of_items prior to testing delete | 
        
          | 1581 | $nb_of_items = Koha::Items->search->count; | 1514 | $nb_of_items = Koha::Items->search->count; | 
        
          | 1582 |  | 1515 |  | 
  
    | Lines 1937-1939
          subtest 'search_ordered' => sub {
      
      
        Link Here | 
        
          | 1937 |     $schema->storage->txn_rollback; | 1870 |     $schema->storage->txn_rollback; | 
        
          | 1938 |  | 1871 |  | 
        
          | 1939 | }; | 1872 | }; | 
          
            
              | 1940 | -  | 1873 |  | 
            
              |  |  | 1874 | subtest 'filter_by_for_hold' => sub { | 
            
              | 1875 |  | 
            
              | 1876 |     plan tests => 13; | 
            
              | 1877 |  | 
            
              | 1878 |     $schema->storage->txn_begin; | 
            
              | 1879 |  | 
            
              | 1880 |     my $biblio  = $builder->build_sample_biblio; | 
            
              | 1881 |     my $library = $builder->build_object({ class => 'Koha::Libraries' }); | 
            
              | 1882 |  | 
            
              | 1883 |     t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests | 
            
              | 1884 |  | 
            
              | 1885 |     is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' ); | 
            
              | 1886 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); | 
            
              | 1887 |     is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); | 
            
              | 1888 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); | 
            
              | 1889 |     is( $biblio->items->filter_by_for_hold->count, 1, '1 item for hold' ); | 
            
              | 1890 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } ); | 
            
              | 1891 |     is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' ); | 
            
              | 1892 |  | 
            
              | 1893 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 0, library => $library->id } ); | 
            
              | 1894 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1, library => $library->id } ); | 
            
              | 1895 |     is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' ); | 
            
              | 1896 |  | 
            
              | 1897 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 0, library => $library->id } ); | 
            
              | 1898 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1, library => $library->id } ); | 
            
              | 1899 |     is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' ); | 
            
              | 1900 |  | 
            
              | 1901 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } ); | 
            
              | 1902 |     $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } ); | 
            
              | 1903 |     t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0); | 
            
              | 1904 |     is( $biblio->items->filter_by_for_hold->count, 5, '5 items for hold - not damaged if not AllowHoldsOnDamagedItems' ); | 
            
              | 1905 |     t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); | 
            
              | 1906 |     is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); | 
            
              | 1907 |  | 
            
              | 1908 |     my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); | 
            
              | 1909 |     my $not_holdable_itemtype = $itemtype->itemtype; | 
            
              | 1910 |     $builder->build_sample_item( | 
            
              | 1911 |         { | 
            
              | 1912 |             biblionumber => $biblio->biblionumber, | 
            
              | 1913 |             itype        => $not_holdable_itemtype, | 
            
              | 1914 |         } | 
            
              | 1915 |     ); | 
            
              | 1916 |     Koha::CirculationRules->set_rule( | 
            
              | 1917 |         { | 
            
              | 1918 |             branchcode   => undef, | 
            
              | 1919 |             itemtype     => $not_holdable_itemtype, | 
            
              | 1920 |             rule_name    => 'holdallowed', | 
            
              | 1921 |             rule_value   => 'not_allowed', | 
            
              | 1922 |         } | 
            
              | 1923 |     ); | 
            
              | 1924 |     is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - holdallowed=not_allowed' ); | 
            
              | 1925 |  | 
            
              | 1926 |     # Remove rule, test notforloan on itemtype | 
            
              | 1927 |     Koha::CirculationRules->set_rule( | 
            
              | 1928 |         { | 
            
              | 1929 |             branchcode   => undef, | 
            
              | 1930 |             itemtype     => $not_holdable_itemtype, | 
            
              | 1931 |             rule_name    => 'holdallowed', | 
            
              | 1932 |             rule_value   => undef, | 
            
              | 1933 |         } | 
            
              | 1934 |     ); | 
            
              | 1935 |     is( $biblio->items->filter_by_for_hold->count, 7, '7 items for hold - rule deleted' ); | 
            
              | 1936 |     $itemtype->notforloan(1)->store; | 
            
              | 1937 |     is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - notforloan' ); | 
            
              | 1938 |  | 
            
              | 1939 |     { | 
            
              | 1940 |         my $mock_context = Test::MockModule->new('C4::Context'); | 
            
              | 1941 |         $mock_context->mock( 'only_my_library', 1 ); | 
            
              | 1942 |         $mock_context->mock( 'mybranch',        $library->id ); | 
            
              | 1943 |         is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold, filtered by IndependentBranches' ); | 
            
              | 1944 |     } | 
            
              | 1945 |  | 
            
              | 1946 |     t::lib::Mocks::mock_preference('item-level_itypes', 0); | 
            
              | 1947 |     $biblio->biblioitem->itemtype($not_holdable_itemtype)->store; | 
            
              | 1948 |     is( $biblio->items->filter_by_for_hold->count, 0, '0 item-level_itypes=0' ); | 
            
              | 1949 |  | 
            
              | 1950 |     t::lib::Mocks::mock_preference('item-level_itypes', 1); | 
            
              | 1951 |  | 
            
              | 1952 |     $schema->storage->txn_rollback; | 
            
              | 1953 | }; |