| Lines 19-25
          
      
      
        Link Here | 
        
          | 19 |  | 19 |  | 
        
          | 20 | use Modern::Perl; | 20 | use Modern::Perl; | 
        
          | 21 |  | 21 |  | 
          
            
              | 22 | use Test::More tests => 25; | 22 | use Test::More tests => 26; | 
        
          | 23 |  | 23 |  | 
        
          | 24 | use Test::MockModule; | 24 | use Test::MockModule; | 
        
          | 25 | use Test::Exception; | 25 | use Test::Exception; | 
  
    | Lines 2410-2412
          subtest 'filter_by_has_recalls' => sub {
      
      
        Link Here | 
        
          | 2410 |     $schema->storage->txn_rollback; | 2410 |     $schema->storage->txn_rollback; | 
        
          | 2411 |  | 2411 |  | 
        
          | 2412 | }; | 2412 | }; | 
          
            
              | 2413 | -  | 2413 |  | 
            
              |  |  | 2414 | subtest 'filter_by_available' => sub { | 
            
              | 2415 |     plan tests => 6; | 
            
              | 2416 |  | 
            
              | 2417 |     $schema->storage->txn_begin; | 
            
              | 2418 |  | 
            
              | 2419 |     my $library = $builder->build_object( { class => 'Koha::Libraries' } ); | 
            
              | 2420 |     my $biblio  = $builder->build_sample_biblio(); | 
            
              | 2421 |     my $patron  = $builder->build_object( { class => 'Koha::Patrons' } ); | 
            
              | 2422 |     t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); | 
            
              | 2423 |  | 
            
              | 2424 |     my $item_1 = $builder->build_sample_item( | 
            
              | 2425 |         { | 
            
              | 2426 |             biblionumber => $biblio->biblionumber, | 
            
              | 2427 |             library      => $library->branchcode, | 
            
              | 2428 |             itemlost     => 0, | 
            
              | 2429 |             withdrawn    => 0, | 
            
              | 2430 |             damaged      => 0, | 
            
              | 2431 |             notforloan   => 0, | 
            
              | 2432 |             onloan       => undef, | 
            
              | 2433 |         } | 
            
              | 2434 |     ); | 
            
              | 2435 |  | 
            
              | 2436 |     my $item_2 = $builder->build_sample_item( | 
            
              | 2437 |         { | 
            
              | 2438 |             biblionumber => $biblio->biblionumber, | 
            
              | 2439 |             library      => $library->branchcode, | 
            
              | 2440 |             itemlost     => 0, | 
            
              | 2441 |             withdrawn    => 0, | 
            
              | 2442 |             damaged      => 0, | 
            
              | 2443 |             notforloan   => 0, | 
            
              | 2444 |             onloan       => undef, | 
            
              | 2445 |         } | 
            
              | 2446 |     ); | 
            
              | 2447 |  | 
            
              | 2448 |     my $item_3 = $builder->build_sample_item( | 
            
              | 2449 |         { | 
            
              | 2450 |             biblionumber => $biblio->biblionumber, | 
            
              | 2451 |             library      => $library->branchcode, | 
            
              | 2452 |             itemlost     => 0, | 
            
              | 2453 |             withdrawn    => 0, | 
            
              | 2454 |             damaged      => 0, | 
            
              | 2455 |             notforloan   => 0, | 
            
              | 2456 |             onloan       => undef, | 
            
              | 2457 |         } | 
            
              | 2458 |     ); | 
            
              | 2459 |  | 
            
              | 2460 |     my $item_4 = $builder->build_sample_item( | 
            
              | 2461 |         { | 
            
              | 2462 |             biblionumber => $biblio->biblionumber, | 
            
              | 2463 |             library      => $library->branchcode, | 
            
              | 2464 |             itemlost     => 0, | 
            
              | 2465 |             withdrawn    => 0, | 
            
              | 2466 |             damaged      => 0, | 
            
              | 2467 |             notforloan   => 0, | 
            
              | 2468 |             onloan       => undef, | 
            
              | 2469 |         } | 
            
              | 2470 |     ); | 
            
              | 2471 |  | 
            
              | 2472 |     my $item_5 = $builder->build_sample_item( | 
            
              | 2473 |         { | 
            
              | 2474 |             biblionumber => $biblio->biblionumber, | 
            
              | 2475 |             library      => $library->branchcode, | 
            
              | 2476 |             itemlost     => 0, | 
            
              | 2477 |             withdrawn    => 0, | 
            
              | 2478 |             damaged      => 0, | 
            
              | 2479 |             notforloan   => 0, | 
            
              | 2480 |             onloan       => undef, | 
            
              | 2481 |         } | 
            
              | 2482 |     ); | 
            
              | 2483 |  | 
            
              | 2484 |     # Create items with varying states | 
            
              | 2485 |     # Test: Initial available items | 
            
              | 2486 |     is( | 
            
              | 2487 |         $biblio->items->filter_by_available->count, | 
            
              | 2488 |         5, | 
            
              | 2489 |         "Filtered to 4 available items" | 
            
              | 2490 |     ); | 
            
              | 2491 |  | 
            
              | 2492 |     # Mark item_1 as lost | 
            
              | 2493 |     $item_1->itemlost(3)->store; | 
            
              | 2494 |     C4::Circulation::LostItem( $item_1->itemnumber, 1 ); | 
            
              | 2495 |  | 
            
              | 2496 |     is( | 
            
              | 2497 |         $biblio->items->filter_by_available->count, | 
            
              | 2498 |         4, | 
            
              | 2499 |         "Filtered to 4 available items, 1 is lost" | 
            
              | 2500 |     ); | 
            
              | 2501 |  | 
            
              | 2502 |     #Mark item_2 as damaged | 
            
              | 2503 |     $item_2->damaged(1)->store; | 
            
              | 2504 |  | 
            
              | 2505 |     is( | 
            
              | 2506 |         $biblio->items->filter_by_available->count, | 
            
              | 2507 |         3, | 
            
              | 2508 |         "Filtered to 3 available items, 1 is lost, 1 is damaged" | 
            
              | 2509 |     ); | 
            
              | 2510 |  | 
            
              | 2511 |     #Mark item_3 as withdrawn | 
            
              | 2512 |     $item_3->withdrawn(1)->store; | 
            
              | 2513 |  | 
            
              | 2514 |     is( | 
            
              | 2515 |         $biblio->items->filter_by_available->count, | 
            
              | 2516 |         2, | 
            
              | 2517 |         "Filtered to 2 available items, 1 is lost, 1 is damaged, 1 is withdrawn" | 
            
              | 2518 |     ); | 
            
              | 2519 |  | 
            
              | 2520 |     #Checkout item_4 | 
            
              | 2521 |     C4::Circulation::AddIssue( $patron, $item_4->barcode ); | 
            
              | 2522 |     is( | 
            
              | 2523 |         $biblio->items->filter_by_available->count, | 
            
              | 2524 |         1, | 
            
              | 2525 |         "Filtered to 1 available items, 1 is lost, 1 is damaged, 1 is withdrawn, 1 is checked out" | 
            
              | 2526 |     ); | 
            
              | 2527 |  | 
            
              | 2528 |     #Mark item_5 as notforloan | 
            
              | 2529 |     $item_5->notforloan(1)->store; | 
            
              | 2530 |     is( | 
            
              | 2531 |         $biblio->items->filter_by_available->count, | 
            
              | 2532 |         0, | 
            
              | 2533 |         "Filtered to 0 available items, 1 is lost, 1 is damaged, 1 is withdrawn, 1 is checked out, 1 is notforloan" | 
            
              | 2534 |     ); | 
            
              | 2535 |  | 
            
              | 2536 |     $schema->storage->txn_rollback; | 
            
              | 2537 | }; |