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

(-)a/t/db_dependent/Koha/Patrons.t (-10 / +31 lines)
Lines 617-623 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
617
};
617
};
618
618
619
subtest 'checkouts + pending_checkouts + overdues + old_checkouts' => sub {
619
subtest 'checkouts + pending_checkouts + overdues + old_checkouts' => sub {
620
    plan tests => 17;
620
    plan tests => 19;
621
621
622
    my $library = $builder->build( { source => 'Branch' } );
622
    my $library = $builder->build( { source => 'Branch' } );
623
    my $biblionumber_1 = $builder->build_sample_biblio->biblionumber;
623
    my $biblionumber_1 = $builder->build_sample_biblio->biblionumber;
Lines 660-678 subtest 'checkouts + pending_checkouts + overdues + old_checkouts' => sub { Link Here
660
660
661
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
661
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
662
662
663
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
663
    my $issue_1 = AddIssue(
664
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
664
        $patron, $item_1->barcode, dt_from_string()->subtract( days => 1 ), undef,
665
    AddIssue( $patron, $item_3->barcode );
665
        dt_from_string()->subtract( days => 10 )
666
    );
667
    sleep(1);    # Pause to ensure timestamps differ and that they do not affect ordering
668
    AddIssue(
669
        $patron, $item_2->barcode, dt_from_string()->subtract( days => 5 ), undef,
670
        dt_from_string()->subtract( days => 1 )
671
    );
672
    sleep(1);
673
    AddIssue( $patron, $item_3->barcode, undef, undef, dt_from_string()->subtract( days => 5 ) );
674
    sleep(1);
666
675
667
    $checkouts = $patron->checkouts;
676
    $checkouts = $patron->checkouts;
668
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
677
    is( $checkouts->count, 3,                 'checkouts should return 3 issues for that patron' );
669
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
678
    is( ref($checkouts),   'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
670
    $pending_checkouts = $patron->pending_checkouts;
679
    $pending_checkouts = $patron->pending_checkouts;
671
    is( $pending_checkouts->count, 3, 'pending_checkouts should return 3 issues for that patron' );
680
    is( $pending_checkouts->count, 3,                 'pending_checkouts should return 3 issues for that patron' );
672
    is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
681
    is( ref($pending_checkouts),   'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
682
683
    my @itemnumbers = $pending_checkouts->get_column('itemnumber');
684
    is_deeply(
685
        \@itemnumbers, [ $item_2->itemnumber, $item_3->itemnumber, $item_1->itemnumber ],
686
        "Checkouts are ordered by the date issued"
687
    );
688
    $issue_1->auto_renew_error("Updated")->store;
689
    $pending_checkouts = $patron->pending_checkouts;
690
    @itemnumbers       = $pending_checkouts->get_column('itemnumber');
691
    is_deeply(
692
        \@itemnumbers, [ $item_2->itemnumber, $item_3->itemnumber, $item_1->itemnumber ],
693
        "Checkouts are still ordered by the date issued, updates do not reorder"
694
    );
673
695
674
    my $first_checkout = $pending_checkouts->next;
696
    my $first_checkout = $pending_checkouts->next;
675
    is( $first_checkout->unblessed_all_relateds->{biblionumber}, $item_3->biblionumber, 'pending_checkouts should prefetch values from other tables (here biblio)' );
697
    is( $first_checkout->unblessed_all_relateds->{biblionumber}, $item_2->biblionumber, 'pending_checkouts should prefetch values from other tables (here biblio)' );
676
698
677
    my $overdues = $patron->overdues;
699
    my $overdues = $patron->overdues;
678
    is( $overdues->count, 2, 'Patron should have 2 overdues');
700
    is( $overdues->count, 2, 'Patron should have 2 overdues');
679
- 

Return to bug 37636