| Lines 19-25
          
      
      
        Link Here | 
        
          | 19 |  | 19 |  | 
        
          | 20 | use Modern::Perl; | 20 | use Modern::Perl; | 
        
          | 21 |  | 21 |  | 
          
            
              | 22 | use Test::More tests => 12; | 22 | use Test::More tests => 13; | 
        
          | 23 | use Test::Exception; | 23 | use Test::Exception; | 
        
          | 24 | use Time::Fake; | 24 | use Time::Fake; | 
        
          | 25 |  | 25 |  | 
  
    | Lines 1318-1320
          $retrieved_item_1->delete;
      
      
        Link Here | 
        
          | 1318 | is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' ); | 1318 | is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' ); | 
        
          | 1319 |  | 1319 |  | 
        
          | 1320 | $schema->storage->txn_rollback; | 1320 | $schema->storage->txn_rollback; | 
          
            
              | 1321 | -  | 1321 |  | 
            
              |  |  | 1322 | subtest 'filter_by_visible_in_opac() tests' => sub { | 
            
              | 1323 |  | 
            
              | 1324 |     plan tests => 8; | 
            
              | 1325 |  | 
            
              | 1326 |     $schema->storage->txn_begin; | 
            
              | 1327 |  | 
            
              | 1328 |     # have a fresh biblio | 
            
              | 1329 |     my $biblio = $builder->build_sample_biblio; | 
            
              | 1330 |     # have two itemtypes | 
            
              | 1331 |     my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); | 
            
              | 1332 |     my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' }); | 
            
              | 1333 |     # have 5 items on that biblio | 
            
              | 1334 |     my $item_1 = $builder->build_sample_item( | 
            
              | 1335 |         { | 
            
              | 1336 |             biblionumber => $biblio->biblionumber, | 
            
              | 1337 |             itemlost     => -1, | 
            
              | 1338 |             itype        => $itype_1->itemtype, | 
            
              | 1339 |             withdrawn    => 1 | 
            
              | 1340 |         } | 
            
              | 1341 |     ); | 
            
              | 1342 |     my $item_2 = $builder->build_sample_item( | 
            
              | 1343 |         { | 
            
              | 1344 |             biblionumber => $biblio->biblionumber, | 
            
              | 1345 |             itemlost     => 0, | 
            
              | 1346 |             itype        => $itype_2->itemtype, | 
            
              | 1347 |             withdrawn    => 2 | 
            
              | 1348 |         } | 
            
              | 1349 |     ); | 
            
              | 1350 |     my $item_3 = $builder->build_sample_item( | 
            
              | 1351 |         { | 
            
              | 1352 |             biblionumber => $biblio->biblionumber, | 
            
              | 1353 |             itemlost     => 1, | 
            
              | 1354 |             itype        => $itype_1->itemtype, | 
            
              | 1355 |             withdrawn    => 3 | 
            
              | 1356 |         } | 
            
              | 1357 |     ); | 
            
              | 1358 |     my $item_4 = $builder->build_sample_item( | 
            
              | 1359 |         { | 
            
              | 1360 |             biblionumber => $biblio->biblionumber, | 
            
              | 1361 |             itemlost     => 0, | 
            
              | 1362 |             itype        => $itype_2->itemtype, | 
            
              | 1363 |             withdrawn    => 4 | 
            
              | 1364 |         } | 
            
              | 1365 |     ); | 
            
              | 1366 |     my $item_5 = $builder->build_sample_item( | 
            
              | 1367 |         { | 
            
              | 1368 |             biblionumber => $biblio->biblionumber, | 
            
              | 1369 |             itemlost     => undef, | 
            
              | 1370 |             itype        => $itype_1->itemtype, | 
            
              | 1371 |             withdrawn    => 5 | 
            
              | 1372 |         } | 
            
              | 1373 |     ); | 
            
              | 1374 |  | 
            
              | 1375 |     my $rules = {}; | 
            
              | 1376 |  | 
            
              | 1377 |     t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); | 
            
              | 1378 |     is( $biblio->items->filter_by_visible_in_opac->count, | 
            
              | 1379 |         5, 'No rules passed, hidelostitems unset' ); | 
            
              | 1380 |  | 
            
              | 1381 |     t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); | 
            
              | 1382 |     is( | 
            
              | 1383 |         $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, | 
            
              | 1384 |         4, | 
            
              | 1385 |         'No rules passed, hidelostitems set' | 
            
              | 1386 |     ); | 
            
              | 1387 |  | 
            
              | 1388 |     $rules = { withdrawn => [ 1, 2 ] }; | 
            
              | 1389 |     is( | 
            
              | 1390 |         $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, | 
            
              | 1391 |         2, | 
            
              | 1392 |         'Rules on withdrawn, hidelostitems set' | 
            
              | 1393 |     ); | 
            
              | 1394 |  | 
            
              | 1395 |     $rules = { itype => [ $itype_1->itemtype ] }; | 
            
              | 1396 |     is( | 
            
              | 1397 |         $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, | 
            
              | 1398 |         2, | 
            
              | 1399 |         'Rules on itype, hidelostitems set' | 
            
              | 1400 |     ); | 
            
              | 1401 |  | 
            
              | 1402 |     $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] }; | 
            
              | 1403 |     is( | 
            
              | 1404 |         $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, | 
            
              | 1405 |         1, | 
            
              | 1406 |         'Rules on itype and withdrawn, hidelostitems set' | 
            
              | 1407 |     ); | 
            
              | 1408 |     is( | 
            
              | 1409 |         $biblio->items->filter_by_visible_in_opac( { rules => $rules } ) | 
            
              | 1410 |           ->next->itemnumber, | 
            
              | 1411 |         $item_4->itemnumber, | 
            
              | 1412 |         'The right item is returned' | 
            
              | 1413 |     ); | 
            
              | 1414 |  | 
            
              | 1415 |     $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] }; | 
            
              | 1416 |     is( | 
            
              | 1417 |         $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, | 
            
              | 1418 |         1, | 
            
              | 1419 |         'Rules on itype and withdrawn, hidelostitems set' | 
            
              | 1420 |     ); | 
            
              | 1421 |     is( | 
            
              | 1422 |         $biblio->items->filter_by_visible_in_opac( { rules => $rules } ) | 
            
              | 1423 |           ->next->itemnumber, | 
            
              | 1424 |         $item_5->itemnumber, | 
            
              | 1425 |         'The right item is returned' | 
            
              | 1426 |     ); | 
            
              | 1427 |  | 
            
              | 1428 |     $schema->storage->txn_rollback; | 
            
              | 1429 | }; |