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

(-)a/t/db_dependent/Koha/Item.t (-114 / +111 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 7;
23
23
24
use C4::Biblio;
24
use C4::Biblio;
25
use C4::Circulation;
25
use C4::Circulation;
Lines 156-162 subtest "as_marc_field() tests" => sub { Link Here
156
};
156
};
157
157
158
subtest 'pickup_locations' => sub {
158
subtest 'pickup_locations' => sub {
159
    plan tests => 114;
159
    plan tests => 119;
160
160
161
    $schema->storage->txn_begin;
161
    $schema->storage->txn_begin;
162
162
Lines 192-203 subtest 'pickup_locations' => sub { Link Here
192
    my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
192
    my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
193
    my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
193
    my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
194
194
195
    my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { itemtype => 'test' } } );
195
    my $item1 = $builder->build_sample_item(
196
    my $item1 = $builder->build_sample_item(
196
        {
197
        {
197
            homebranch    => $library1->branchcode,
198
            homebranch    => $library1->branchcode,
198
            holdingbranch => $library2->branchcode,
199
            holdingbranch => $library2->branchcode,
199
            barcode       => '1',
200
            barcode       => '1',
200
            itype         => 'test',
201
            itype         => 'test',
202
            ccode         => 'Gollum'
201
        }
203
        }
202
    )->store;
204
    )->store;
203
205
Lines 214-278 subtest 'pickup_locations' => sub { Link Here
214
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
216
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
215
217
216
    my $results = {
218
    my $results = {
217
        "1-1-1-any" => 3,
219
        "1-1-1-any"           => 3,
218
        "1-1-1-holdgroup" => 2,
220
        "1-1-1-holdgroup"     => 2,
219
        "1-1-1-patrongroup" => 2,
221
        "1-1-1-patrongroup"   => 2,
220
        "1-1-1-homebranch" => 1,
222
        "1-1-1-homebranch"    => 1,
221
        "1-1-1-holdingbranch" => 1,
223
        "1-1-1-holdingbranch" => 1,
222
        "1-1-2-any" => 3,
224
        "1-1-2-any"           => 3,
223
        "1-1-2-holdgroup" => 2,
225
        "1-1-2-holdgroup"     => 2,
224
        "1-1-2-patrongroup" => 2,
226
        "1-1-2-patrongroup"   => 2,
225
        "1-1-2-homebranch" => 1,
227
        "1-1-2-homebranch"    => 1,
226
        "1-1-2-holdingbranch" => 1,
228
        "1-1-2-holdingbranch" => 1,
227
        "1-1-3-any" => 3,
229
        "1-1-3-any"           => 3,
228
        "1-1-3-holdgroup" => 2,
230
        "1-1-3-holdgroup"     => 2,
229
        "1-1-3-patrongroup" => 2,
231
        "1-1-3-patrongroup"   => 2,
230
        "1-1-3-homebranch" => 1,
232
        "1-1-3-homebranch"    => 1,
231
        "1-1-3-holdingbranch" => 1,
233
        "1-1-3-holdingbranch" => 1,
232
        "1-4-1-any" => 0,
234
        "1-4-1-any"           => 0,
233
        "1-4-1-holdgroup" => 0,
235
        "1-4-1-holdgroup"     => 0,
234
        "1-4-1-patrongroup" => 0,
236
        "1-4-1-patrongroup"   => 0,
235
        "1-4-1-homebranch" => 0,
237
        "1-4-1-homebranch"    => 0,
236
        "1-4-1-holdingbranch" => 0,
238
        "1-4-1-holdingbranch" => 0,
237
        "1-4-2-any" => 3,
239
        "1-4-2-any"           => 3,
238
        "1-4-2-holdgroup" => 2,
240
        "1-4-2-holdgroup"     => 2,
239
        "1-4-2-patrongroup" => 1,
241
        "1-4-2-patrongroup"   => 1,
240
        "1-4-2-homebranch" => 1,
242
        "1-4-2-homebranch"    => 1,
241
        "1-4-2-holdingbranch" => 1,
243
        "1-4-2-holdingbranch" => 1,
242
        "1-4-3-any" => 0,
244
        "1-4-3-any"           => 0,
243
        "1-4-3-holdgroup" => 0,
245
        "1-4-3-holdgroup"     => 0,
244
        "1-4-3-patrongroup" => 0,
246
        "1-4-3-patrongroup"   => 0,
245
        "1-4-3-homebranch" => 0,
247
        "1-4-3-homebranch"    => 0,
246
        "1-4-3-holdingbranch" => 0,
248
        "1-4-3-holdingbranch" => 0,
247
        "3-1-1-any" => 0,
249
        "3-1-1-any"           => 0,
248
        "3-1-1-holdgroup" => 0,
250
        "3-1-1-holdgroup"     => 0,
249
        "3-1-1-patrongroup" => 0,
251
        "3-1-1-patrongroup"   => 0,
250
        "3-1-1-homebranch" => 0,
252
        "3-1-1-homebranch"    => 0,
251
        "3-1-1-holdingbranch" => 0,
253
        "3-1-1-holdingbranch" => 0,
252
        "3-1-2-any" => 3,
254
        "3-1-2-any"           => 3,
253
        "3-1-2-holdgroup" => 1,
255
        "3-1-2-holdgroup"     => 1,
254
        "3-1-2-patrongroup" => 2,
256
        "3-1-2-patrongroup"   => 2,
255
        "3-1-2-homebranch" => 0,
257
        "3-1-2-homebranch"    => 0,
256
        "3-1-2-holdingbranch" => 1,
258
        "3-1-2-holdingbranch" => 1,
257
        "3-1-3-any" => 0,
259
        "3-1-3-any"           => 0,
258
        "3-1-3-holdgroup" => 0,
260
        "3-1-3-holdgroup"     => 0,
259
        "3-1-3-patrongroup" => 0,
261
        "3-1-3-patrongroup"   => 0,
260
        "3-1-3-homebranch" => 0,
262
        "3-1-3-homebranch"    => 0,
261
        "3-1-3-holdingbranch" => 0,
263
        "3-1-3-holdingbranch" => 0,
262
        "3-4-1-any" => 0,
264
        "3-4-1-any"           => 0,
263
        "3-4-1-holdgroup" => 0,
265
        "3-4-1-holdgroup"     => 0,
264
        "3-4-1-patrongroup" => 0,
266
        "3-4-1-patrongroup"   => 0,
265
        "3-4-1-homebranch" => 0,
267
        "3-4-1-homebranch"    => 0,
266
        "3-4-1-holdingbranch" => 0,
268
        "3-4-1-holdingbranch" => 0,
267
        "3-4-2-any" => 3,
269
        "3-4-2-any"           => 3,
268
        "3-4-2-holdgroup" => 1,
270
        "3-4-2-holdgroup"     => 1,
269
        "3-4-2-patrongroup" => 1,
271
        "3-4-2-patrongroup"   => 1,
270
        "3-4-2-homebranch" => 0,
272
        "3-4-2-homebranch"    => 0,
271
        "3-4-2-holdingbranch" => 1,
273
        "3-4-2-holdingbranch" => 1,
272
        "3-4-3-any" => 3,
274
        "3-4-3-any"           => 3,
273
        "3-4-3-holdgroup" => 1,
275
        "3-4-3-holdgroup"     => 1,
274
        "3-4-3-patrongroup" => 1,
276
        "3-4-3-patrongroup"   => 1,
275
        "3-4-3-homebranch" => 0,
277
        "3-4-3-homebranch"    => 0,
276
        "3-4-3-holdingbranch" => 1
278
        "3-4-3-holdingbranch" => 1
277
    };
279
    };
278
280
Lines 318-324 subtest 'pickup_locations' => sub { Link Here
318
                  . $ha . '-'
320
                  . $ha . '-'
319
                  . $hfp
321
                  . $hfp
320
              }
322
              }
321
              . ' but returns '
323
              . ' and returns '
322
              . scalar(@pl)
324
              . scalar(@pl)
323
        );
325
        );
324
326
Lines 336-426 subtest 'pickup_locations' => sub { Link Here
336
        }
338
        }
337
    }
339
    }
338
340
339
    $schema->storage->txn_rollback;
341
    # Now test that branchtransferlimits will further filter the pickup locations
340
};
341
342
subtest '_can_pickup_locations' => sub {
343
    plan tests =>8;
344
345
    $schema->storage->txn_begin;
346
347
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
348
349
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
350
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
351
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, } } );
352
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
353
354
    my $item = $builder->build_sample_item({
355
        homebranch => $library1->branchcode,
356
        holdingbranch => $library1->branchcode,
357
        ccode => "Gollum"
358
    });
359
360
    my @to = ( $library1, $library2, $library3, $library4 );
361
362
    my $pickup_locations = $item->_can_pickup_locations({ to => \@to });
363
    is( scalar @$pickup_locations, 3, "With no transfer limits we get back the libraries that are pickup locations");
364
365
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
342
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
366
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
343
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
367
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
344
    Koha::CirculationRules->set_rules(
368
        toBranch => $library2->branchcode,
345
        {
369
        fromBranch => $library1->branchcode,
346
            branchcode => undef,
370
        itemtype => $item->itype,
347
            itemtype   => $item1->itype,
371
        ccode => undef,
348
            rules      => {
349
                holdallowed             => 1,
350
                hold_fulfillment_policy => 1,
351
                returnbranch            => 'any'
352
            }
372
        }
353
        }
373
    });
354
    );
355
    $builder->build_object(
356
        {
357
            class => 'Koha::Item::Transfer::Limits',
358
            value => {
359
                toBranch   => $library1->branchcode,
360
                fromBranch => $library2->branchcode,
361
                itemtype   => $item1->itype,
362
                ccode      => undef,
363
            }
364
        }
365
    );
374
366
375
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
367
    my $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
376
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
368
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
377
369
378
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
370
    $builder->build_object(
379
        toBranch => $library4->branchcode,
371
        {
380
        fromBranch => $library1->branchcode,
372
            class => 'Koha::Item::Transfer::Limits',
381
        itemtype => $item->itype,
373
            value => {
382
        ccode => undef,
374
                toBranch   => $library4->branchcode,
375
                fromBranch => $library2->branchcode,
376
                itemtype   => $item1->itype,
377
                ccode      => undef,
378
            }
383
        }
379
        }
384
    });
380
    );
385
381
386
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
382
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
387
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
383
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
388
384
389
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
385
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
390
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
386
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
391
    is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
387
    is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
392
388
393
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
389
    $builder->build_object(
394
        toBranch => $library2->branchcode,
390
        {
395
        fromBranch => $library1->branchcode,
391
            class => 'Koha::Item::Transfer::Limits',
396
        itemtype => undef,
392
            value => {
397
        ccode => $item->ccode,
393
                toBranch   => $library2->branchcode,
394
                fromBranch => $library2->branchcode,
395
                itemtype   => undef,
396
                ccode      => $item1->ccode,
397
            }
398
        }
398
        }
399
    });
399
    );
400
400
401
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
401
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
402
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
402
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
403
403
404
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
404
    $builder->build_object(
405
        toBranch => $library4->branchcode,
405
        {
406
        fromBranch => $library1->branchcode,
406
            class => 'Koha::Item::Transfer::Limits',
407
        itemtype => undef,
407
            value => {
408
        ccode => $item->ccode,
408
                toBranch   => $library4->branchcode,
409
                fromBranch => $library2->branchcode,
410
                itemtype   => undef,
411
                ccode      => $item1->ccode,
412
            }
409
        }
413
        }
410
    });
414
    );
411
415
412
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
416
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
413
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
417
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
414
418
415
416
    $pickup_locations = $item->_can_pickup_locations({ to => \@to, from => $library2 });
417
    is( scalar @$pickup_locations, 3, "With transfer limits enabled but not applying because of 'from' we get back the libraries that are pickup locations");
418
419
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
419
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
420
420
421
    $pickup_locations = $item->_can_pickup_locations({ to => \@to });
421
    $schema->storage->txn_rollback;
422
    is( scalar @$pickup_locations, 3, "With transfer limits disabled we get back the libraries that are pickup locations");
423
424
};
422
};
425
423
426
subtest 'deletion' => sub {
424
subtest 'deletion' => sub {
427
- 

Return to bug 26963