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

(-)a/t/db_dependent/Circulation.t (-26 / +1 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 50;
21
use Test::More tests => 49;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Deep qw( cmp_deeply );
23
use Test::Deep qw( cmp_deeply );
24
24
Lines 3296-3326 subtest 'Cancel transfers on lost items' => sub { Link Here
3296
3296
3297
};
3297
};
3298
3298
3299
subtest 'transferbook test' => sub {
3300
    plan tests => 5;
3301
3302
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
3303
    my $item = $builder->build_sample_item();
3304
    ok( $item->holdingbranch ne $library->branchcode && $item->homebranch ne $library->branchcode, "Item is not held or owned by library");
3305
    C4::Circulation::transferbook({
3306
        from_branch => $library->branchcode,
3307
        to_branch => $item->homebranch,
3308
        barcode   => $item->barcode,
3309
    });
3310
    my ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
3311
    is( $from_branch, $library->branchcode, 'The transfer is initiated from the specified branch, not the items home or holdingbranch');
3312
    is( $to_branch, $item->homebranch, 'The transfer is initiated to the specified branch');
3313
    C4::Circulation::transferbook({
3314
        from_branch => $item->homebranch,
3315
        to_branch => $library->branchcode,
3316
        barcode   => $item->barcode,
3317
    });
3318
    ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
3319
    is( $from_branch, $item->homebranch, 'The transfer is initiated from the specified branch');
3320
    is( $to_branch, $library->branchcode, 'The transfer is initiated to the specified branch');
3321
3322
};
3323
3324
subtest 'CanBookBeIssued | is_overdue' => sub {
3299
subtest 'CanBookBeIssued | is_overdue' => sub {
3325
    plan tests => 3;
3300
    plan tests => 3;
3326
3301
(-)a/t/db_dependent/Circulation/transferbook.t (-11 / +74 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
use t::lib::Mocks;
22
use t::lib::Mocks;
23
23
Lines 39-45 subtest 'transfer a non-existant item' => sub { Link Here
39
    $item->delete;
39
    $item->delete;
40
40
41
    my ( $dotransfer, $messages ) =
41
    my ( $dotransfer, $messages ) =
42
      C4::Circulation::transferbook( $library->{branchcode}, $badbc );
42
      C4::Circulation::transferbook({
43
          from_branch => $item->homebranch,
44
          to_branch => $library->{branchcode},
45
          barcode => $badbc
46
      });
43
    is( $dotransfer, 0, "Can't transfer a bad barcode" );
47
    is( $dotransfer, 0, "Can't transfer a bad barcode" );
44
    is_deeply(
48
    is_deeply(
45
        $messages,
49
        $messages,
Lines 70-76 subtest 'field population tests' => sub { Link Here
70
    );
74
    );
71
75
72
    my $trigger = "Manual";
76
    my $trigger = "Manual";
73
    my ($dotransfer, $messages ) = transferbook( $library2->branchcode, $item->barcode, undef, $trigger );
77
    my ($dotransfer, $messages ) = transferbook({
78
        from_branch => $item->homebranch,
79
        to_branch => $library2->branchcode,
80
        barcode => $item->barcode,
81
        trigger => $trigger
82
    });
74
    is( $dotransfer, 1, 'Transfer succeeded' );
83
    is( $dotransfer, 1, 'Transfer succeeded' );
75
    is_deeply(
84
    is_deeply(
76
        $messages,
85
        $messages,
Lines 108-114 subtest 'transfer already at destination' => sub { Link Here
108
        }
117
        }
109
    );
118
    );
110
119
111
    my ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
120
    my ($dotransfer, $messages ) = transferbook({
121
        from_branch => $item->homebranch,
122
        to_branch => $library->branchcode,
123
        barcode => $item->barcode
124
    });
112
    is( $dotransfer, 0, 'Transfer of item failed when destination equals holding branch' );
125
    is( $dotransfer, 0, 'Transfer of item failed when destination equals holding branch' );
113
    is_deeply(
126
    is_deeply(
114
        $messages,
127
        $messages,
Lines 126-132 subtest 'transfer already at destination' => sub { Link Here
126
        itemnumber     => $item->itemnumber,
139
        itemnumber     => $item->itemnumber,
127
    });
140
    });
128
141
129
    ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
142
    ($dotransfer, $messages ) = transferbook({
143
        from_branch => $item->homebranch,
144
        to_branch => $library->branchcode,
145
        barcode => $item->barcode
146
    });
130
    is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
147
    is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
131
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
148
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
132
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
149
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
Lines 157-163 subtest 'transfer an issued item' => sub { Link Here
157
    # We are making sure there is no regression, feel free to change the behavior if needed.
174
    # We are making sure there is no regression, feel free to change the behavior if needed.
158
    # * WasReturned does not seem like a variable that should contain a borrowernumber
175
    # * WasReturned does not seem like a variable that should contain a borrowernumber
159
    # * Should we return even if the transfer did not happen? (same branches)
176
    # * Should we return even if the transfer did not happen? (same branches)
160
    my ($dotransfer, $messages) = transferbook( $library->branchcode, $item->barcode );
177
    my ($dotransfer, $messages) = transferbook({
178
        from_branch => $item->homebranch,
179
        to_branch => $library->branchcode,
180
        barcode => $item->barcode
181
    });
161
    is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
182
    is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
162
183
163
    # Reset issue
184
    # Reset issue
Lines 173-179 subtest 'transfer an issued item' => sub { Link Here
173
        itemnumber     => $item->itemnumber,
194
        itemnumber     => $item->itemnumber,
174
    });
195
    });
175
196
176
    ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
197
    ($dotransfer, $messages ) = transferbook({
198
        from_branch => $item->homebranch,
199
        to_branch => $library->branchcode,
200
        barcode => $item->barcode
201
    });
177
    is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
202
    is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
178
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
203
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
179
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
204
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
Lines 208-226 subtest 'ignore_reserves flag' => sub { Link Here
208
    # We are making sure there is no regression, feel free to change the behavior if needed.
233
    # We are making sure there is no regression, feel free to change the behavior if needed.
209
    # * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve
234
    # * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve
210
    #   found will override all other measures that may prevent transfer and force a transfer.
235
    #   found will override all other measures that may prevent transfer and force a transfer.
211
    my ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
236
    my ($dotransfer, $messages ) = transferbook({
237
        from_branch => $item->homebranch,
238
        to_branch => $library->branchcode,
239
        barcode => $item->barcode
240
    });
212
    is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
241
    is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
213
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
242
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
214
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
243
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
215
244
216
    my $ignore_reserves = 0;
245
    my $ignore_reserves = 0;
217
    ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode, $ignore_reserves );
246
    ($dotransfer, $messages ) = transferbook({
247
        from_branch => $item->homebranch,
248
        to_branch => $library->branchcode,
249
        barcode => $item->barcode,
250
        ignore_reserves => $ignore_reserves
251
    });
218
    is( $dotransfer, 1, 'Transfer of reserved item succeeded with ignore reserves: false' );
252
    is( $dotransfer, 1, 'Transfer of reserved item succeeded with ignore reserves: false' );
219
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
253
    is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
220
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
254
    is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
221
255
222
    $ignore_reserves = 1;
256
    $ignore_reserves = 1;
223
    ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode, $ignore_reserves );
257
    ($dotransfer, $messages ) = transferbook({
258
        from_branch => $item->homebranch,
259
        to_branch => $library->branchcode,
260
        barcode => $item->barcode,
261
        ignore_reserves => $ignore_reserves
262
    });
224
    is( $dotransfer, 0, 'Transfer of reserved item failed with ignore reserves: true' );
263
    is( $dotransfer, 0, 'Transfer of reserved item failed with ignore reserves: true' );
225
    is_deeply(
264
    is_deeply(
226
        $messages,
265
        $messages,
Lines 230-232 subtest 'ignore_reserves flag' => sub { Link Here
230
    isnt( $messages->{ResFound}->{ResFound}, 'Reserved', "We did not return that we found a reserve");
269
    isnt( $messages->{ResFound}->{ResFound}, 'Reserved', "We did not return that we found a reserve");
231
    isnt( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We did not return the reserve info");
270
    isnt( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We did not return the reserve info");
232
};
271
};
233
- 
272
273
subtest 'transferbook test from branch' => sub {
274
    plan tests => 5;
275
276
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
277
    my $item = $builder->build_sample_item();
278
    ok( $item->holdingbranch ne $library->branchcode && $item->homebranch ne $library->branchcode, "Item is not held or owned by library");
279
    C4::Circulation::transferbook({
280
        from_branch => $library->branchcode,
281
        to_branch => $item->homebranch,
282
        barcode   => $item->barcode,
283
    });
284
    my ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
285
    is( $from_branch, $library->branchcode, 'The transfer is initiated from the specified branch, not the items home or holdingbranch');
286
    is( $to_branch, $item->homebranch, 'The transfer is initiated to the specified branch');
287
    C4::Circulation::transferbook({
288
        from_branch => $item->homebranch,
289
        to_branch => $library->branchcode,
290
        barcode   => $item->barcode,
291
    });
292
    ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
293
    is( $from_branch, $item->homebranch, 'The transfer is initiated from the specified branch');
294
    is( $to_branch, $library->branchcode, 'The transfer is initiated to the specified branch');
295
296
};

Return to bug 23695