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

(-)a/t/db_dependent/Koha/Holds.t (-2 / +106 lines)
Lines 19-31 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 7;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Circulation qw( AddIssue );
25
use C4::Circulation qw( AddIssue );
26
use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll );
26
use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll );
27
use Koha::AuthorisedValueCategory;
27
use Koha::AuthorisedValueCategory;
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::DateUtils qw( dt_from_string );
29
use Koha::Holds;
30
use Koha::Holds;
30
31
31
use t::lib::Mocks;
32
use t::lib::Mocks;
Lines 500-505 subtest 'get_items_that_can_fill' => sub { Link Here
500
501
501
};
502
};
502
503
504
subtest 'set_waiting+patron_expiration_date' => sub {
505
    plan tests => 2;
506
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
507
508
    my $item =
509
      $builder->build_sample_item( { library => $library->branchcode } );
510
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
511
    t::lib::Mocks::mock_userenv(
512
        { patron => $manager, branchcode => $manager->branchcode } );
513
514
    my $patron = $builder->build_object(
515
        {
516
            class => 'Koha::Patrons',
517
            value => { branchcode => $library->branchcode, }
518
        }
519
    );
520
521
    subtest 'patron_expiration_date < expiration_date' => sub {
522
        plan tests => 6;
523
        t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 5 );
524
        my $patron_expiration_date = dt_from_string->add( days => 3 )->ymd;
525
        my $reserve_id             = C4::Reserves::AddReserve(
526
            {
527
                branchcode      => $library->branchcode,
528
                borrowernumber  => $patron->borrowernumber,
529
                biblionumber    => $item->biblionumber,
530
                priority        => 1,
531
                itemnumber      => $item->itemnumber,
532
                expiration_date => $patron_expiration_date,
533
            }
534
        );
535
536
        my $hold = Koha::Holds->find($reserve_id);
537
538
        is(
539
            $hold->expirationdate,
540
            $patron_expiration_date,
541
            'expiration date set to patron expiration date'
542
        );
543
        is(
544
            $hold->patron_expiration_date, $patron_expiration_date,
545
            'patron expiration date correctly set'
546
        );
547
548
        $hold->set_waiting;
549
550
        $hold = $hold->get_from_storage;
551
        is( $hold->expirationdate,         $patron_expiration_date );
552
        is( $hold->patron_expiration_date, $patron_expiration_date );
553
554
        C4::Reserves::RevertWaitingStatus(
555
            { itemnumber => $item->itemnumber }
556
        );
557
558
        $hold = $hold->get_from_storage;
559
        is( $hold->expirationdate,         $patron_expiration_date );
560
        is( $hold->patron_expiration_date, $patron_expiration_date );
561
    };
562
563
    subtest 'patron_expiration_date > expiration_date' => sub {
564
        plan tests => 6;
565
        t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 5 );
566
        my $new_expiration_date = dt_from_string->add( days => 5 )->ymd;
567
        my $patron_expiration_date = dt_from_string->add( days => 6 )->ymd;
568
        my $reserve_id             = C4::Reserves::AddReserve(
569
            {
570
                branchcode      => $library->branchcode,
571
                borrowernumber  => $patron->borrowernumber,
572
                biblionumber    => $item->biblionumber,
573
                priority        => 1,
574
                itemnumber      => $item->itemnumber,
575
                expiration_date => $patron_expiration_date,
576
            }
577
        );
578
579
        my $hold = Koha::Holds->find($reserve_id);
580
581
        is(
582
            $hold->expirationdate,
583
            $patron_expiration_date,
584
            'expiration date set to patron expiration date'
585
        );
586
        is(
587
            $hold->patron_expiration_date, $patron_expiration_date,
588
            'patron expiration date correctly set'
589
        );
590
591
        $hold->set_waiting;
592
593
        $hold = $hold->get_from_storage;
594
        is( $hold->expirationdate,         $new_expiration_date );
595
        is( $hold->patron_expiration_date, $patron_expiration_date );
596
597
        C4::Reserves::RevertWaitingStatus(
598
            { itemnumber => $item->itemnumber }
599
        );
600
601
        $hold = $hold->get_from_storage;
602
        is( $hold->expirationdate,         $patron_expiration_date );
603
        is( $hold->patron_expiration_date, $patron_expiration_date );
604
    };
605
};
606
607
503
$schema->storage->txn_rollback;
608
$schema->storage->txn_rollback;
504
609
505
1;
610
1;
506
- 

Return to bug 21729