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

(-)a/t/db_dependent/Koha/Item.t (-2 / +122 lines)
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 => 33;
23
use Test::More tests => 34;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
26
Lines 2519-2521 subtest 'find_booking' => sub { Link Here
2519
2519
2520
    $schema->storage->txn_rollback;
2520
    $schema->storage->txn_rollback;
2521
};
2521
};
2522
- 
2522
2523
subtest 'check_booking tests' => sub {
2524
    plan tests => 5;
2525
2526
    $schema->storage->txn_begin;
2527
2528
    my $biblio   = $builder->build_sample_biblio();
2529
    my $item     = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } );
2530
    my $can_book = $item->check_booking(
2531
        {
2532
            start_date => dt_from_string(),
2533
            end_date   => dt_from_string()->add( days => 7 )
2534
        }
2535
    );
2536
2537
    is(
2538
        $can_book, 1,
2539
        "True returned from Koha::Item->check_booking if there are no bookings that would clash"
2540
    );
2541
2542
    my $start_1 = dt_from_string()->subtract( days => 7 );
2543
    my $end_1   = dt_from_string()->subtract( days => 1 );
2544
    my $start_2 = dt_from_string();
2545
    my $end_2   = dt_from_string()->add( days => 7 );
2546
    my $start_3 = dt_from_string()->add( days => 8 );
2547
    my $end_3   = dt_from_string()->add( days => 16 );
2548
2549
    # Past booking
2550
    my $booking1 = $builder->build_object(
2551
        {
2552
            class => 'Koha::Bookings',
2553
            value => {
2554
                biblio_id  => $biblio->biblionumber,
2555
                item_id    => $item->itemnumber,
2556
                start_date => $start_1,
2557
                end_date   => $end_1
2558
            }
2559
        }
2560
    );
2561
2562
    $can_book = $item->check_booking(
2563
        {
2564
            start_date => dt_from_string(),
2565
            end_date   => dt_from_string()->add( days => 7 ),
2566
        }
2567
    );
2568
2569
    is(
2570
        $can_book,
2571
        1,
2572
        "Koha::Item->check_booking returns true when we don't conflict with a past booking"
2573
    );
2574
2575
    # Current booking
2576
    my $booking2 = $builder->build_object(
2577
        {
2578
            class => 'Koha::Bookings',
2579
            value => {
2580
                biblio_id  => $biblio->biblionumber,
2581
                item_id    => $item->itemnumber,
2582
                start_date => $start_2,
2583
                end_date   => $end_2
2584
            }
2585
        }
2586
    );
2587
2588
    $can_book = $item->check_booking(
2589
        {
2590
            start_date => dt_from_string(),
2591
            end_date   => dt_from_string()->add( days => 7 ),
2592
        }
2593
    );
2594
    is(
2595
        $can_book,
2596
        0,
2597
        "Koha::Item->check_booking returns false if the booking would conflict"
2598
    );
2599
2600
    $can_book = $item->check_booking(
2601
        {
2602
            start_date => dt_from_string(),
2603
            end_date   => dt_from_string()->add( days => 7 ),
2604
            booking_id => $booking2->booking_id
2605
        }
2606
    );
2607
    is(
2608
        $can_book,
2609
        1,
2610
        "Koha::Item->check_booking returns true if we pass the booking_id that would conflict"
2611
    );
2612
2613
    $booking2->delete();
2614
2615
    # Future booking
2616
    my $booking3 = $builder->build_object(
2617
        {
2618
            class => 'Koha::Bookings',
2619
            value => {
2620
                biblio_id  => $biblio->biblionumber,
2621
                item_id    => $item->itemnumber,
2622
                start_date => $start_3,
2623
                end_date   => $end_3
2624
            }
2625
        }
2626
    );
2627
2628
    $can_book = $item->check_booking(
2629
        {
2630
            start_date => dt_from_string(),
2631
            end_date   => dt_from_string()->add( days => 7 ),
2632
        }
2633
    );
2634
2635
    is(
2636
        $can_book,
2637
        1,
2638
        "Koha::Item->check_booking returns true when we don't conflict with a future booking"
2639
    );
2640
2641
    $schema->storage->txn_rollback;
2642
};

Return to bug 35248