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

(-)a/t/db_dependent/Circulation.t (-37 / +39 lines)
Lines 2633-2691 subtest 'CanBookBeIssued + Statistic patrons "X"' => sub { Link Here
2633
};
2633
};
2634
2634
2635
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
2635
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
2636
    plan tests => 8;
2636
    plan tests => 1;
2637
2637
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2638
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2638
    t::lib::Mocks::mock_userenv( { branchcode => $library2->{branchcode} } );
2639
    t::lib::Mocks::mock_userenv( { branchcode => $library2->{branchcode} } );
2639
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue',         1 );
2640
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue',         1 );
2640
    t::lib::Mocks::mock_preference( 'AutoClaimReturnStatusOnCheckin', 1 );
2641
    t::lib::Mocks::mock_preference( 'AutoClaimReturnStatusOnCheckin', '' );
2641
    my $item     = $builder->build_sample_item( { library => $library2->{branchcode} } );
2642
    my $item     = $builder->build_sample_item( { library => $library2->{branchcode} } );
2642
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
2643
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
2643
    my $checkout = AddIssue( $patron, $item->barcode );
2644
    my $future   = dt_from_string()->add( days => 7 );
2644
2645
    my $checkout = $builder->build_object(
2645
    my $claim = $checkout->claim_returned(
2646
        {
2646
        {
2647
            created_by => $patron->id,
2647
            class => 'Koha::Checkouts',
2648
            notes      => "Test note",
2648
            value => {
2649
                returndate      => undef,
2650
                renewals_count  => 0,
2651
                auto_renew      => 0,
2652
                borrowernumber  => $patron->borrowernumber,
2653
                itemnumber      => $item->itemnumber,
2654
                onsite_checkout => 0,
2655
                date_due        => $future,
2656
            }
2649
        }
2657
        }
2650
    );
2658
    );
2651
    is( $claim->issue_id,       $checkout->id, "Claim issue id matches" );
2652
    is( $claim->itemnumber,     $item->id,     "Claim itemnumber matches" );
2653
    is( $claim->borrowernumber, $patron->id,   "Claim borrowernumber matches" );
2654
    is( $claim->notes,          "Test note",   "Claim notes match" );
2655
    is( $claim->created_by,     $patron->id,   "Claim created_by matches" );
2656
    ok( $claim->created_on, "Claim created_on is set" );
2657
2658
    my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode} );
2659
    is( ref $messages->{ClaimAutoResolved}, 'Koha::Checkouts::ReturnClaim', "Claim auto resolved upon checkin" );
2660
    $claim->discard_changes;
2661
    ok( $claim->resolved_by, "Claim is resolved" );
2662
};
2663
2664
subtest "Bug 27753 - Add AutoTestClaimReturnStatusOnCheckin" => sub {
2665
    plan tests => 7;
2666
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2667
    t::lib::Mocks::mock_userenv( { branchcode => $library2->{branchcode} } );
2668
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue',         1 );
2669
    t::lib::Mocks::mock_preference( 'AutoClaimReturnStatusOnCheckin', 0 );
2670
    my $item     = $builder->build_sample_item( { library => $library2->{branchcode} } );
2671
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
2672
    my $checkout = AddIssue( $patron, $item->barcode );
2673
2659
2660
    # Claim return
2674
    my $claim = $checkout->claim_returned(
2661
    my $claim = $checkout->claim_returned(
2675
        {
2662
        {
2676
            created_by => $patron->id,
2663
            created_by => $patron->id,
2677
            notes      => "Test note",
2664
            notes      => "Test note",
2678
        }
2665
        }
2679
    );
2666
    );
2680
    is( $claim->issue_id,       $checkout->id, "Claim issue id matches" );
2667
    is( $claim->issue_id, $checkout->id,    "Return claim created for issue" );
2681
    is( $claim->itemnumber,     $item->id,     "Claim itemnumber matches" );
2668
    $item->discard_changes;
2682
    is( $claim->borrowernumber, $patron->id,   "Claim borrowernumber matches" );
2669
    is( $item->itemlost,  1, "Item set to lost as 1" );
2683
    is( $claim->notes,          "Test note",   "Claim notes match" );
2684
    is( $claim->created_by,     $patron->id,   "Claim created_by matches" );
2685
    ok( $claim->created_on, "Claim created_on is set" );
2686
2670
2671
    # Return tests with feature disabled
2687
    my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode} );
2672
    my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode} );
2688
    is( ref $messages->{ReturnClaims}, 'Koha::Checkouts::ReturnClaim', "Claim was returned" );
2673
    is(
2674
        ref $messages->{ReturnClaims}, 'Koha::Checkouts::ReturnClaim',
2675
        "AddReturn returns message 'ReturnClaims' containing the ReturnClaim object"
2676
    );
2677
    # FIXME: We should reset the checkout here else we hit a 'No patron' defined issue in the AutoClaim code.
2678
    #        This might highligt a bug in the code however.. should we allow trigger this code when the return
2679
    #        spots that there isn't a current issue
2680
2681
    # Now test with the feature enabled
2682
    t::lib::Mocks::mock_preference( 'AutoClaimReturnStatusOnCheckin', 'RETURNED_ON_CLAIM' );
2683
    ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode} );
2684
    is(
2685
        ref $messages->{ClaimAutoResolved}, 'Koha::Checkouts::ReturnClaim',
2686
        "AddReturn returns message 'ClaimAutoResolved' containing the ReturnClaim object"
2687
    );
2688
    $claim->discard_changes;
2689
    is( $claim->resolved_by, '', "Claim marked as resolved by '' when AutoClaimReturnStatusOnCheckin set" );
2690
    # FIXME: The code sets the resolved_by to the patron who was issued the item.. should this be the librarian performing the return instead?
2691
    is( $claim->resolution, 'RETURNED_ON_CLAIM', "Claim resolution set to match AutoClaimReturnStatusOnCheckin value" );
2689
};
2692
};
2690
2693
2691
subtest 'MultipleReserves' => sub {
2694
subtest 'MultipleReserves' => sub {
2692
- 

Return to bug 27753