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

(-)a/t/db_dependent/SIP/Transaction.t (-2 / +106 lines)
Lines 4-10 Link Here
4
# Current state is very rudimentary. Please help to extend it!
4
# Current state is very rudimentary. Please help to extend it!
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
use Test::More tests => 17;
7
use Test::More tests => 18;
8
8
9
use Koha::Database;
9
use Koha::Database;
10
use t::lib::TestBuilder;
10
use t::lib::TestBuilder;
Lines 22-27 use C4::Reserves qw( AddReserve ModReserve ModReserveAffect RevertWaitingStatus Link Here
22
use Koha::CirculationRules;
22
use Koha::CirculationRules;
23
use Koha::Item::Transfer;
23
use Koha::Item::Transfer;
24
use Koha::DateUtils qw( dt_from_string output_pref );
24
use Koha::DateUtils qw( dt_from_string output_pref );
25
use Koha::Recalls;
25
26
26
my $schema = Koha::Database->new->schema;
27
my $schema = Koha::Database->new->schema;
27
$schema->storage->txn_begin;
28
$schema->storage->txn_begin;
Lines 1043-1046 subtest item_circulation_status => sub { Link Here
1043
    is( $status, '01', "Item circulation status is damaged" );
1044
    is( $status, '01', "Item circulation status is damaged" );
1044
    $item->damaged(0)->store();
1045
    $item->damaged(0)->store();
1045
};
1046
};
1047
1048
subtest do_checkout_with_recalls => sub {
1049
    plan tests => 7;
1050
1051
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1052
    my $patron  = $builder->build_object(
1053
        {
1054
            class => 'Koha::Patrons',
1055
            value => {
1056
                branchcode => $library->branchcode,
1057
            }
1058
        }
1059
    );
1060
    my $patron2 = $builder->build_object(
1061
        {
1062
            class => 'Koha::Patrons',
1063
            value => {
1064
                branchcode => $library->branchcode,
1065
            }
1066
        }
1067
    );
1068
1069
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
1070
1071
    my $item = $builder->build_sample_item(
1072
        {
1073
            library => $library->branchcode,
1074
        }
1075
    );
1076
1077
    t::lib::Mocks::mock_preference( 'UseRecalls', 1 );
1078
    Koha::CirculationRules->set_rule(
1079
        {
1080
            branchcode   => undef,
1081
            categorycode => undef,
1082
            itemtype     => undef,
1083
            rule_name    => 'recalls_allowed',
1084
            rule_value   => '10',
1085
        }
1086
    );
1087
1088
    my $recall1 = Koha::Recall->new(
1089
        {
1090
            patron_id         => $patron2->borrowernumber,
1091
            created_date      => \'NOW()',
1092
            biblio_id         => $item->biblio->biblionumber,
1093
            pickup_library_id => $library->branchcode,
1094
            item_id           => $item->itemnumber,
1095
            expiration_date   => undef,
1096
            item_level        => 1
1097
        }
1098
    )->store;
1099
1100
    my $sip_patron     = C4::SIP::ILS::Patron->new( $patron->cardnumber );
1101
    my $sip_item       = C4::SIP::ILS::Item->new( $item->barcode );
1102
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
1103
    is(
1104
        $co_transaction->patron($sip_patron),
1105
        $sip_patron, "Patron assigned to transaction"
1106
    );
1107
    is(
1108
        $co_transaction->item($sip_item),
1109
        $sip_item, "Item assigned to transaction"
1110
    );
1111
1112
    # Test recalls made by another patron
1113
1114
    $recall1->set_waiting( { item => $item } );
1115
    $co_transaction->do_checkout();
1116
    is( $patron->checkouts->count, 0, 'Checkout was not done due to waiting recall' );
1117
1118
    $recall1->revert_waiting;
1119
    $recall1->start_transfer( { item => $item } );
1120
    $co_transaction->do_checkout();
1121
    is( $patron->checkouts->count, 0, 'Checkout was not done due to recall in transit' );
1122
1123
    $recall1->revert_transfer;
1124
    $recall1->update( { item_id => undef, item_level => 0 } );
1125
    $co_transaction->do_checkout();
1126
    is( $patron->checkouts->count, 0, 'Checkout was not done due to a biblio-level recall that this item could fill' );
1127
1128
    $recall1->set_cancelled;
1129
1130
    my $recall2 = Koha::Recall->new(
1131
        {
1132
            patron_id         => $patron->borrowernumber,
1133
            created_date      => \'NOW()',
1134
            biblio_id         => $item->biblio->biblionumber,
1135
            pickup_library_id => $library->branchcode,
1136
            item_id           => $item->itemnumber,
1137
            expiration_date   => undef,
1138
            item_level        => 1
1139
        }
1140
    )->store;
1141
1142
    # Test recalls made by SIP patron
1143
1144
    $recall2->set_waiting( { item => $item } );
1145
    $co_transaction->do_checkout();
1146
    is( $patron->checkouts->count, 1, 'Checkout was done because recalled item was allocated to them' );
1147
    $recall2 = Koha::Recalls->find( $recall2->id );
1148
    is( $recall2->status, 'fulfilled', 'Recall is fulfilled by checked out item' );
1149
};
1150
1046
$schema->storage->txn_rollback;
1151
$schema->storage->txn_rollback;
1047
- 

Return to bug 34016