| Lines 20-26
          
      
      
        Link Here | 
        
          | 20 | use Modern::Perl; | 20 | use Modern::Perl; | 
        
          | 21 | use utf8; | 21 | use utf8; | 
        
          | 22 |  | 22 |  | 
          
            
              | 23 | use Test::More tests => 32; | 23 | use Test::More tests => 33; | 
        
          | 24 | use Test::Exception; | 24 | use Test::Exception; | 
        
          | 25 | use Test::MockModule; | 25 | use Test::MockModule; | 
        
          | 26 |  | 26 |  | 
  
    | Lines 2408-2410
          subtest 'bookings' => sub {
      
      
        Link Here | 
        
          | 2408 |  | 2408 |  | 
        
          | 2409 |     $schema->storage->txn_rollback; | 2409 |     $schema->storage->txn_rollback; | 
        
          | 2410 | }; | 2410 | }; | 
          
            
              | 2411 | -  | 2411 |  | 
            
              |  |  | 2412 | subtest 'find_booking' => sub { | 
            
              | 2413 |     plan tests => 6; | 
            
              | 2414 |  | 
            
              | 2415 |     $schema->storage->txn_begin; | 
            
              | 2416 |  | 
            
              | 2417 |     my $biblio        = $builder->build_sample_biblio(); | 
            
              | 2418 |     my $item          = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } ); | 
            
              | 2419 |     my $found_booking = $item->find_booking( | 
            
              | 2420 |         { | 
            
              | 2421 |             checkout_date => dt_from_string(), | 
            
              | 2422 |             due_date      => dt_from_string()->add( days => 7 ), | 
            
              | 2423 |         } | 
            
              | 2424 |     ); | 
            
              | 2425 |  | 
            
              | 2426 |     is( | 
            
              | 2427 |         $found_booking, undef, | 
            
              | 2428 |         "Nothing returned from Koha::Item->find_booking if there are no bookings" | 
            
              | 2429 |     ); | 
            
              | 2430 |  | 
            
              | 2431 |     my $start_1 = dt_from_string()->subtract( days => 7 ); | 
            
              | 2432 |     my $end_1   = dt_from_string()->subtract( days => 1 ); | 
            
              | 2433 |     my $start_2 = dt_from_string(); | 
            
              | 2434 |     my $end_2   = dt_from_string()->add( days => 7 ); | 
            
              | 2435 |     my $start_3 = dt_from_string()->add( days => 8 ); | 
            
              | 2436 |     my $end_3   = dt_from_string()->add( days => 16 ); | 
            
              | 2437 |  | 
            
              | 2438 |     # Past booking | 
            
              | 2439 |     my $booking1 = $builder->build_object( | 
            
              | 2440 |         { | 
            
              | 2441 |             class => 'Koha::Bookings', | 
            
              | 2442 |             value => { | 
            
              | 2443 |                 biblio_id  => $biblio->biblionumber, | 
            
              | 2444 |                 item_id    => $item->itemnumber, | 
            
              | 2445 |                 start_date => $start_1, | 
            
              | 2446 |                 end_date   => $end_1 | 
            
              | 2447 |             } | 
            
              | 2448 |         } | 
            
              | 2449 |     ); | 
            
              | 2450 |  | 
            
              | 2451 |     $found_booking = $item->find_booking( | 
            
              | 2452 |         { | 
            
              | 2453 |             checkout_date => dt_from_string(), | 
            
              | 2454 |             due_date      => dt_from_string()->add( days => 7 ), | 
            
              | 2455 |         } | 
            
              | 2456 |     ); | 
            
              | 2457 |  | 
            
              | 2458 |     is( | 
            
              | 2459 |         $found_booking, | 
            
              | 2460 |         undef, | 
            
              | 2461 |         "Koha::Item->find_booking returns undefined if the passed dates do not conflict with any item bookings" | 
            
              | 2462 |     ); | 
            
              | 2463 |  | 
            
              | 2464 |     # Current booking | 
            
              | 2465 |     my $booking2 = $builder->build_object( | 
            
              | 2466 |         { | 
            
              | 2467 |             class => 'Koha::Bookings', | 
            
              | 2468 |             value => { | 
            
              | 2469 |                 biblio_id  => $biblio->biblionumber, | 
            
              | 2470 |                 item_id    => $item->itemnumber, | 
            
              | 2471 |                 start_date => $start_2, | 
            
              | 2472 |                 end_date   => $end_2 | 
            
              | 2473 |             } | 
            
              | 2474 |         } | 
            
              | 2475 |     ); | 
            
              | 2476 |  | 
            
              | 2477 |     $found_booking = $item->find_booking( | 
            
              | 2478 |         { | 
            
              | 2479 |             checkout_date => dt_from_string(), | 
            
              | 2480 |             due_date      => dt_from_string()->add( days => 7 ), | 
            
              | 2481 |         } | 
            
              | 2482 |     ); | 
            
              | 2483 |     is( | 
            
              | 2484 |         ref($found_booking), | 
            
              | 2485 |         'Koha::Booking', | 
            
              | 2486 |         "Koha::Item->find_booking returns a Koha::Booking if one exists that would clash with the passed dates" | 
            
              | 2487 |     ); | 
            
              | 2488 |     is( $found_booking->booking_id, $booking2->booking_id, "Koha::Item->find_booking returns the current booking" ); | 
            
              | 2489 |  | 
            
              | 2490 |     # Future booking | 
            
              | 2491 |     my $booking3 = $builder->build_object( | 
            
              | 2492 |         { | 
            
              | 2493 |             class => 'Koha::Bookings', | 
            
              | 2494 |             value => { | 
            
              | 2495 |                 biblio_id  => $biblio->biblionumber, | 
            
              | 2496 |                 item_id    => $item->itemnumber, | 
            
              | 2497 |                 start_date => $start_3, | 
            
              | 2498 |                 end_date   => $end_3 | 
            
              | 2499 |             } | 
            
              | 2500 |         } | 
            
              | 2501 |     ); | 
            
              | 2502 |  | 
            
              | 2503 |     $found_booking = $item->find_booking( | 
            
              | 2504 |         { | 
            
              | 2505 |             checkout_date => dt_from_string(), | 
            
              | 2506 |             due_date      => dt_from_string()->add( days => 7 ), | 
            
              | 2507 |         } | 
            
              | 2508 |     ); | 
            
              | 2509 |  | 
            
              | 2510 |     is( | 
            
              | 2511 |         ref($found_booking), | 
            
              | 2512 |         'Koha::Booking', | 
            
              | 2513 |         "Koha::Item->find_booking returns a Koha::Booking if one exists that would clash with the passed dates" | 
            
              | 2514 |     ); | 
            
              | 2515 |     is( | 
            
              | 2516 |         $found_booking->booking_id, $booking2->booking_id, | 
            
              | 2517 |         "Koha::Item->find_booking returns the current booking not a future one" | 
            
              | 2518 |     ); | 
            
              | 2519 |  | 
            
              | 2520 |     $schema->storage->txn_rollback; | 
            
              | 2521 | }; |