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

(-)a/t/db_dependent/Circulation.t (-84 / +54 lines)
Lines 227-234 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
227
# CanBookBeRenewed tests
227
# CanBookBeRenewed tests
228
    C4::Context->set_preference('ItemsDeniedRenewal','');
228
    C4::Context->set_preference('ItemsDeniedRenewal','');
229
    # Generate test biblio
229
    # Generate test biblio
230
    my $title = 'Silence in the library';
230
    my $biblio = $builder->gimme_a_biblio();
231
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
232
231
233
    my $barcode = 'R00000342';
232
    my $barcode = 'R00000342';
234
    my $branch = $library2->{branchcode};
233
    my $branch = $library2->{branchcode};
Lines 241-247 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
241
            replacementprice => 12.00,
240
            replacementprice => 12.00,
242
            itype            => $itemtype
241
            itype            => $itemtype
243
        },
242
        },
244
        $biblionumber
243
        $biblio->biblionumber
245
    );
244
    );
246
245
247
    my $barcode2 = 'R00000343';
246
    my $barcode2 = 'R00000343';
Lines 253-259 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
253
            replacementprice => 23.00,
252
            replacementprice => 23.00,
254
            itype            => $itemtype
253
            itype            => $itemtype
255
        },
254
        },
256
        $biblionumber
255
        $biblio->biblionumber
257
    );
256
    );
258
257
259
    my $barcode3 = 'R00000346';
258
    my $barcode3 = 'R00000346';
Lines 265-271 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
265
            replacementprice => 23.00,
264
            replacementprice => 23.00,
266
            itype            => $itemtype
265
            itype            => $itemtype
267
        },
266
        },
268
        $biblionumber
267
        $biblio->biblionumber
269
    );
268
    );
270
269
271
    # Create borrowers
270
    # Create borrowers
Lines 342-350 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
342
341
343
    # Biblio-level hold, renewal test
342
    # Biblio-level hold, renewal test
344
    AddReserve(
343
    AddReserve(
345
        $branch, $reserving_borrowernumber, $biblionumber,
344
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
346
        $bibitems,  $priority, $resdate, $expdate, $notes,
345
        $bibitems,  $priority, $resdate, $expdate, $notes,
347
        $title, $checkitem, $found
346
        'a title', $checkitem, $found
348
    );
347
    );
349
348
350
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
349
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
Lines 359-365 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
359
    my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
358
    my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
360
        {
359
        {
361
            borrowernumber => $hold_waiting_borrowernumber,
360
            borrowernumber => $hold_waiting_borrowernumber,
362
            biblionumber   => $biblionumber,
361
            biblionumber   => $biblio->biblionumber,
363
            itemnumber     => $itemnumber,
362
            itemnumber     => $itemnumber,
364
            branchcode     => $branch,
363
            branchcode     => $branch,
365
            priority       => 3,
364
            priority       => 3,
Lines 374-380 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
374
    $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
373
    $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
375
        {
374
        {
376
            borrowernumber => $hold_waiting_borrowernumber,
375
            borrowernumber => $hold_waiting_borrowernumber,
377
            biblionumber   => $biblionumber,
376
            biblionumber   => $biblio->biblionumber,
378
            itemnumber     => $itemnumber3,
377
            itemnumber     => $itemnumber3,
379
            branchcode     => $branch,
378
            branchcode     => $branch,
380
            priority       => 0,
379
            priority       => 0,
Lines 395-401 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
395
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
394
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
396
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
395
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
397
396
398
    my $reserveid = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
397
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
399
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
398
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
400
    AddIssue($reserving_borrower, $barcode3);
399
    AddIssue($reserving_borrower, $barcode3);
401
    my $reserve = $dbh->selectrow_hashref(
400
    my $reserve = $dbh->selectrow_hashref(
Lines 407-415 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
407
406
408
    # Item-level hold, renewal test
407
    # Item-level hold, renewal test
409
    AddReserve(
408
    AddReserve(
410
        $branch, $reserving_borrowernumber, $biblionumber,
409
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
411
        $bibitems,  $priority, $resdate, $expdate, $notes,
410
        $bibitems,  $priority, $resdate, $expdate, $notes,
412
        $title, $itemnumber, $found
411
        'a title', $itemnumber, $found
413
    );
412
    );
414
413
415
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
414
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
Lines 420-429 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
420
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
419
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
421
420
422
    # Items can't fill hold for reasons
421
    # Items can't fill hold for reasons
423
    ModItem({ notforloan => 1 }, $biblionumber, $itemnumber);
422
    ModItem({ notforloan => 1 }, $biblio->biblionumber, $itemnumber);
424
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
423
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
425
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
424
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
426
    ModItem({ notforloan => 0, itype => $itemtype }, $biblionumber, $itemnumber);
425
    ModItem({ notforloan => 0, itype => $itemtype }, $biblio->biblionumber, $itemnumber);
427
426
428
    # FIXME: Add more for itemtype not for loan etc.
427
    # FIXME: Add more for itemtype not for loan etc.
429
428
Lines 437-443 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
437
            replacementprice => 23.00,
436
            replacementprice => 23.00,
438
            itype            => $itemtype
437
            itype            => $itemtype
439
        },
438
        },
440
        $biblionumber
439
        $biblio->biblionumber
441
    );
440
    );
442
    my $datedue5 = AddIssue($restricted_borrower, $barcode5);
441
    my $datedue5 = AddIssue($restricted_borrower, $barcode5);
443
    is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
442
    is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
Lines 458-464 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
458
            replacementprice => 23.00,
457
            replacementprice => 23.00,
459
            itype            => $itemtype
458
            itype            => $itemtype
460
        },
459
        },
461
        $biblionumber
460
        $biblio->biblionumber
462
    );
461
    );
463
462
464
    my $barcode7 = 'R00000349';
463
    my $barcode7 = 'R00000349';
Lines 470-476 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
470
            replacementprice => 23.00,
469
            replacementprice => 23.00,
471
            itype            => $itemtype
470
            itype            => $itemtype
472
        },
471
        },
473
        $biblionumber
472
        $biblio->biblionumber
474
    );
473
    );
475
    my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
474
    my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
476
    is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
475
    is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
Lines 534-540 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
534
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
533
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
535
534
536
535
537
    $hold = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next;
536
    $hold = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next;
538
    $hold->cancel;
537
    $hold->cancel;
539
538
540
    # Bug 14101
539
    # Bug 14101
Lines 549-555 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
549
            replacementprice => 16.00,
548
            replacementprice => 16.00,
550
            itype            => $itemtype
549
            itype            => $itemtype
551
        },
550
        },
552
        $biblionumber
551
        $biblio->biblionumber
553
    );
552
    );
554
553
555
    $issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
554
    $issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
Lines 619-625 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
619
        my $item_to_auto_renew = $builder->build(
618
        my $item_to_auto_renew = $builder->build(
620
            {   source => 'Item',
619
            {   source => 'Item',
621
                value  => {
620
                value  => {
622
                    biblionumber  => $biblionumber,
621
                    biblionumber  => $biblio->biblionumber,
623
                    homebranch    => $branch,
622
                    homebranch    => $branch,
624
                    holdingbranch => $branch,
623
                    holdingbranch => $branch,
625
                }
624
                }
Lines 678-684 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
678
        my $item_to_auto_renew = $builder->build({
677
        my $item_to_auto_renew = $builder->build({
679
            source => 'Item',
678
            source => 'Item',
680
            value => {
679
            value => {
681
                biblionumber => $biblionumber,
680
                biblionumber => $biblio->biblionumber,
682
                homebranch       => $branch,
681
                homebranch       => $branch,
683
                holdingbranch    => $branch,
682
                holdingbranch    => $branch,
684
            }
683
            }
Lines 718-724 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
718
        my $item_to_auto_renew = $builder->build({
717
        my $item_to_auto_renew = $builder->build({
719
            source => 'Item',
718
            source => 'Item',
720
            value => {
719
            value => {
721
                biblionumber => $biblionumber,
720
                biblionumber => $biblio->biblionumber,
722
                homebranch       => $branch,
721
                homebranch       => $branch,
723
                holdingbranch    => $branch,
722
                holdingbranch    => $branch,
724
            }
723
            }
Lines 770-776 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
770
        my $item_to_auto_renew = $builder->build(
769
        my $item_to_auto_renew = $builder->build(
771
            {   source => 'Item',
770
            {   source => 'Item',
772
                value  => {
771
                value  => {
773
                    biblionumber  => $biblionumber,
772
                    biblionumber  => $biblio->biblionumber,
774
                    homebranch    => $branch,
773
                    homebranch    => $branch,
775
                    holdingbranch => $branch,
774
                    holdingbranch => $branch,
776
                }
775
                }
Lines 913-920 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
913
    my $branch   = $library2->{branchcode};
912
    my $branch   = $library2->{branchcode};
914
913
915
    #Create another record
914
    #Create another record
916
    my $title2 = 'Something is worng here';
915
    my $biblio2 = $builder->gimme_a_biblio();
917
    my ($biblionumber2, $biblioitemnumber2) = add_biblio($title2, 'Anonymous');
918
916
919
    #Create third item
917
    #Create third item
920
    AddItem(
918
    AddItem(
Lines 924-930 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
924
            barcode          => $barcode3,
922
            barcode          => $barcode3,
925
            itype            => $itemtype
923
            itype            => $itemtype
926
        },
924
        },
927
        $biblionumber2
925
        $biblio2->biblionumber
928
    );
926
    );
929
927
930
    # Create a borrower
928
    # Create a borrower
Lines 993-999 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
993
    my $barcode  = '1234567890';
991
    my $barcode  = '1234567890';
994
    my $branch   = $library2->{branchcode};
992
    my $branch   = $library2->{branchcode};
995
993
996
    my ($biblionumber, $biblioitemnumber) = add_biblio();
994
    my $biblio = $builder->gimme_a_biblio();
997
995
998
    #Create third item
996
    #Create third item
999
    my ( undef, undef, $itemnumber ) = AddItem(
997
    my ( undef, undef, $itemnumber ) = AddItem(
Lines 1003-1009 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1003
            barcode          => $barcode,
1001
            barcode          => $barcode,
1004
            itype            => $itemtype
1002
            itype            => $itemtype
1005
        },
1003
        },
1006
        $biblionumber
1004
        $biblio->biblionumber
1007
    );
1005
    );
1008
1006
1009
    # Create a borrower
1007
    # Create a borrower
Lines 1050-1056 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1050
        undef,  0,
1048
        undef,  0,
1051
        .10, 1
1049
        .10, 1
1052
    );
1050
    );
1053
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1051
    my $biblio = $builder->gimme_a_biblio();
1054
1052
1055
    my $barcode1 = '1234';
1053
    my $barcode1 = '1234';
1056
    my ( undef, undef, $itemnumber1 ) = AddItem(
1054
    my ( undef, undef, $itemnumber1 ) = AddItem(
Lines 1060-1066 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1060
            barcode       => $barcode1,
1058
            barcode       => $barcode1,
1061
            itype         => $itemtype
1059
            itype         => $itemtype
1062
        },
1060
        },
1063
        $biblionumber
1061
        $biblio->biblionumber
1064
    );
1062
    );
1065
    my $barcode2 = '4321';
1063
    my $barcode2 = '4321';
1066
    my ( undef, undef, $itemnumber2 ) = AddItem(
1064
    my ( undef, undef, $itemnumber2 ) = AddItem(
Lines 1070-1076 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1070
            barcode       => $barcode2,
1068
            barcode       => $barcode2,
1071
            itype         => $itemtype
1069
            itype         => $itemtype
1072
        },
1070
        },
1073
        $biblionumber
1071
        $biblio->biblionumber
1074
    );
1072
    );
1075
1073
1076
    my $borrowernumber1 = Koha::Patron->new({
1074
    my $borrowernumber1 = Koha::Patron->new({
Lines 1095-1101 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1095
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1093
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1096
1094
1097
    AddReserve(
1095
    AddReserve(
1098
        $library2->{branchcode}, $borrowernumber2, $biblionumber,
1096
        $library2->{branchcode}, $borrowernumber2, $biblio->biblionumber,
1099
        '',  1, undef, undef, '',
1097
        '',  1, undef, undef, '',
1100
        undef, undef, undef
1098
        undef, undef, undef
1101
    );
1099
    );
Lines 1121-1127 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1121
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1119
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1122
1120
1123
    # Setting item not checked out to be not for loan but holdable
1121
    # Setting item not checked out to be not for loan but holdable
1124
    ModItem({ notforloan => -1 }, $biblionumber, $itemnumber2);
1122
    ModItem({ notforloan => -1 }, $biblio->biblionumber, $itemnumber2);
1125
1123
1126
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1124
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1127
    is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
1125
    is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
Lines 1133-1139 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1133
    my $branch   = $library->{branchcode};
1131
    my $branch   = $library->{branchcode};
1134
1132
1135
    #Create another record
1133
    #Create another record
1136
    my ($biblionumber, $biblioitemnumber) = add_biblio('A title', 'Anonymous');
1134
    my $biblio = $builder->gimme_a_biblio();
1137
1135
1138
    my (undef, undef, $itemnumber) = AddItem(
1136
    my (undef, undef, $itemnumber) = AddItem(
1139
        {
1137
        {
Lines 1142-1148 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1142
            barcode          => $barcode,
1140
            barcode          => $barcode,
1143
            itype            => $itemtype
1141
            itype            => $itemtype
1144
        },
1142
        },
1145
        $biblionumber
1143
        $biblio->biblionumber
1146
    );
1144
    );
1147
1145
1148
    my $borrowernumber = Koha::Patron->new({
1146
    my $borrowernumber = Koha::Patron->new({
Lines 1163-1169 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1163
{
1161
{
1164
    my $library = $builder->build({ source => 'Branch' });
1162
    my $library = $builder->build({ source => 'Branch' });
1165
1163
1166
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1164
    my $biblio = $builder->gimme_a_biblio();
1167
1165
1168
    my $barcode = 'just a barcode';
1166
    my $barcode = 'just a barcode';
1169
    my ( undef, undef, $itemnumber ) = AddItem(
1167
    my ( undef, undef, $itemnumber ) = AddItem(
Lines 1173-1179 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1173
            barcode          => $barcode,
1171
            barcode          => $barcode,
1174
            itype            => $itemtype
1172
            itype            => $itemtype
1175
        },
1173
        },
1176
        $biblionumber,
1174
        $biblio->biblionumber,
1177
    );
1175
    );
1178
1176
1179
    my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1177
    my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
Lines 1463-1470 subtest 'CanBookBeIssued + Statistic patrons "X"' => sub { Link Here
1463
subtest 'MultipleReserves' => sub {
1461
subtest 'MultipleReserves' => sub {
1464
    plan tests => 3;
1462
    plan tests => 3;
1465
1463
1466
    my $title = 'Silence in the library';
1464
    my $biblio = $builder->gimme_a_biblio();
1467
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
1468
1465
1469
    my $branch = $library2->{branchcode};
1466
    my $branch = $library2->{branchcode};
1470
1467
Lines 1477-1483 subtest 'MultipleReserves' => sub { Link Here
1477
            replacementprice => 12.00,
1474
            replacementprice => 12.00,
1478
            itype            => $itemtype
1475
            itype            => $itemtype
1479
        },
1476
        },
1480
        $biblionumber
1477
        $biblio->biblionumber
1481
    );
1478
    );
1482
1479
1483
    my $barcode2 = 'R00110002';
1480
    my $barcode2 = 'R00110002';
Lines 1489-1495 subtest 'MultipleReserves' => sub { Link Here
1489
            replacementprice => 12.00,
1486
            replacementprice => 12.00,
1490
            itype            => $itemtype
1487
            itype            => $itemtype
1491
        },
1488
        },
1492
        $biblionumber
1489
        $biblio->biblionumber
1493
    );
1490
    );
1494
1491
1495
    my $bibitems       = '';
1492
    my $bibitems       = '';
Lines 1521-1529 subtest 'MultipleReserves' => sub { Link Here
1521
    );
1518
    );
1522
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1519
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1523
    AddReserve(
1520
    AddReserve(
1524
        $branch, $reserving_borrowernumber1, $biblionumber,
1521
        $branch, $reserving_borrowernumber1, $biblio->biblionumber,
1525
        $bibitems,  $priority, $resdate, $expdate, $notes,
1522
        $bibitems,  $priority, $resdate, $expdate, $notes,
1526
        $title, $checkitem, $found
1523
        'a title', $checkitem, $found
1527
    );
1524
    );
1528
1525
1529
    my %reserving_borrower_data2 = (
1526
    my %reserving_borrower_data2 = (
Lines 1534-1542 subtest 'MultipleReserves' => sub { Link Here
1534
    );
1531
    );
1535
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1532
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1536
    AddReserve(
1533
    AddReserve(
1537
        $branch, $reserving_borrowernumber2, $biblionumber,
1534
        $branch, $reserving_borrowernumber2, $biblio->biblionumber,
1538
        $bibitems,  $priority, $resdate, $expdate, $notes,
1535
        $bibitems,  $priority, $resdate, $expdate, $notes,
1539
        $title, $checkitem, $found
1536
        'a title', $checkitem, $found
1540
    );
1537
    );
1541
1538
1542
    {
1539
    {
Lines 1553-1559 subtest 'MultipleReserves' => sub { Link Here
1553
            replacementprice => 12.00,
1550
            replacementprice => 12.00,
1554
            itype            => $itemtype
1551
            itype            => $itemtype
1555
        },
1552
        },
1556
        $biblionumber
1553
        $biblio->biblionumber
1557
    );
1554
    );
1558
1555
1559
    {
1556
    {
Lines 2001-2009 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2001
    );
1998
    );
2002
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1999
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
2003
2000
2004
    # Generate test biblio
2001
    my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Daria' });
2005
    my $title = 'Koha for Dummies';
2006
    my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, 'Hall, Daria' );
2007
2002
2008
    subtest 'Full write-off tests' => sub {
2003
    subtest 'Full write-off tests' => sub {
2009
2004
Lines 2019-2031 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2019
                replacementprice => $replacement_amount,
2014
                replacementprice => $replacement_amount,
2020
                itype            => $item_type->itemtype
2015
                itype            => $item_type->itemtype
2021
            },
2016
            },
2022
            $biblionumber
2017
            $biblio->biblionumber
2023
        );
2018
        );
2024
2019
2025
        AddIssue( $patron->unblessed, $barcode );
2020
        AddIssue( $patron->unblessed, $barcode );
2026
2021
2027
        # Simulate item marked as lost
2022
        # Simulate item marked as lost
2028
        ModItem( { itemlost => 3 }, $biblionumber, $item_id );
2023
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
2029
        LostItem( $item_id, 1 );
2024
        LostItem( $item_id, 1 );
2030
2025
2031
        my $processing_fee_lines = Koha::Account::Lines->search(
2026
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2081-2093 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2081
                replacementprice => $replacement_amount,
2076
                replacementprice => $replacement_amount,
2082
                itype            => $item_type->itemtype
2077
                itype            => $item_type->itemtype
2083
            },
2078
            },
2084
            $biblionumber
2079
            $biblio->biblionumber
2085
        );
2080
        );
2086
2081
2087
        AddIssue( $patron->unblessed, $barcode );
2082
        AddIssue( $patron->unblessed, $barcode );
2088
2083
2089
        # Simulate item marked as lost
2084
        # Simulate item marked as lost
2090
        ModItem( { itemlost => 1 }, $biblionumber, $item_id );
2085
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
2091
        LostItem( $item_id, 1 );
2086
        LostItem( $item_id, 1 );
2092
2087
2093
        my $processing_fee_lines = Koha::Account::Lines->search(
2088
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2150-2162 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2150
                replacementprice => $replacement_amount,
2145
                replacementprice => $replacement_amount,
2151
                itype            => $item_type->itemtype
2146
                itype            => $item_type->itemtype
2152
            },
2147
            },
2153
            $biblionumber
2148
            $biblio->biblionumber
2154
        );
2149
        );
2155
2150
2156
        AddIssue( $patron->unblessed, $barcode );
2151
        AddIssue( $patron->unblessed, $barcode );
2157
2152
2158
        # Simulate item marked as lost
2153
        # Simulate item marked as lost
2159
        ModItem( { itemlost => 3 }, $biblionumber, $item_id );
2154
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
2160
        LostItem( $item_id, 1 );
2155
        LostItem( $item_id, 1 );
2161
2156
2162
        my $processing_fee_lines = Koha::Account::Lines->search(
2157
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2200-2212 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2200
                replacementprice => $replacement_amount,
2195
                replacementprice => $replacement_amount,
2201
                itype            => $item_type->itemtype
2196
                itype            => $item_type->itemtype
2202
            },
2197
            },
2203
            $biblionumber
2198
            $biblio->biblionumber
2204
        );
2199
        );
2205
2200
2206
        AddIssue( $patron->unblessed, $barcode );
2201
        AddIssue( $patron->unblessed, $barcode );
2207
2202
2208
        # Simulate item marked as lost
2203
        # Simulate item marked as lost
2209
        ModItem( { itemlost => 1 }, $biblionumber, $item_id );
2204
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
2210
        LostItem( $item_id, 1 );
2205
        LostItem( $item_id, 1 );
2211
2206
2212
        my $processing_fee_lines = Koha::Account::Lines->search(
2207
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2283-2291 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2283
subtest '_FixOverduesOnReturn' => sub {
2278
subtest '_FixOverduesOnReturn' => sub {
2284
    plan tests => 6;
2279
    plan tests => 6;
2285
2280
2286
    # Generate test biblio
2281
    my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Kylie' });
2287
    my $title  = 'Koha for Dummies';
2288
    my ( $biblionumber, $biblioitemnumber ) = add_biblio($title, 'Hall, Kylie');
2289
2282
2290
    my $barcode = 'KD987654321';
2283
    my $barcode = 'KD987654321';
2291
    my $branchcode  = $library2->{branchcode};
2284
    my $branchcode  = $library2->{branchcode};
Lines 2298-2304 subtest '_FixOverduesOnReturn' => sub { Link Here
2298
            replacementprice => 99.00,
2291
            replacementprice => 99.00,
2299
            itype            => $itemtype
2292
            itype            => $itemtype
2300
        },
2293
        },
2301
        $biblionumber
2294
        $biblio->biblionumber
2302
    );
2295
    );
2303
2296
2304
    my $patron = $builder->build( { source => 'Borrower' } );
2297
    my $patron = $builder->build( { source => 'Borrower' } );
Lines 2761-2789 sub str { Link Here
2761
    return $s;
2754
    return $s;
2762
}
2755
}
2763
2756
2764
sub add_biblio {
2765
    my ($title, $author) = @_;
2766
2767
    my $marcflavour = C4::Context->preference('marcflavour');
2768
2769
    my $biblio = MARC::Record->new();
2770
    if ($title) {
2771
        my $tag = $marcflavour eq 'UNIMARC' ? '200' : '245';
2772
        $biblio->append_fields(
2773
            MARC::Field->new($tag, ' ', ' ', a => $title),
2774
        );
2775
    }
2776
2777
    if ($author) {
2778
        my ($tag, $code) = $marcflavour eq 'UNIMARC' ? (200, 'f') : (100, 'a');
2779
        $biblio->append_fields(
2780
            MARC::Field->new($tag, ' ', ' ', $code => $author),
2781
        );
2782
    }
2783
2784
    return AddBiblio($biblio, '');
2785
}
2786
2787
sub test_debarment_on_checkout {
2757
sub test_debarment_on_checkout {
2788
    my ($params) = @_;
2758
    my ($params) = @_;
2789
    my $item     = $params->{item};
2759
    my $item     = $params->{item};
(-)a/t/db_dependent/Holds.t (-66 / +48 lines)
Lines 52-63 $insert_sth->execute('DUMMY'); Link Here
52
$insert_sth->execute('ONLY1');
52
$insert_sth->execute('ONLY1');
53
53
54
# Setup Test------------------------
54
# Setup Test------------------------
55
# Create a biblio instance for testing
55
my $biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
56
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
57
56
58
# Create item instance for testing.
57
# Create item instance for testing.
59
my ($item_bibnum, $item_bibitemnum, $itemnumber)
58
my ($item_bibnum, $item_bibitemnum, $itemnumber)
60
    = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
59
    = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
61
60
62
# Create some borrowers
61
# Create some borrowers
63
my @borrowernumbers;
62
my @borrowernumbers;
Lines 71-96 foreach (1..$borrowers_count) { Link Here
71
    push @borrowernumbers, $borrowernumber;
70
    push @borrowernumbers, $borrowernumber;
72
}
71
}
73
72
74
my $biblionumber = $bibnum;
75
76
# Create five item level holds
73
# Create five item level holds
77
foreach my $borrowernumber ( @borrowernumbers ) {
74
foreach my $borrowernumber ( @borrowernumbers ) {
78
    AddReserve(
75
    AddReserve(
79
        $branch_1,
76
        $branch_1,
80
        $borrowernumber,
77
        $borrowernumber,
81
        $biblionumber,
78
        $biblio->biblionumber,
82
        my $bibitems = q{},
79
        my $bibitems = q{},
83
        my $priority = C4::Reserves::CalculatePriority( $biblionumber ),
80
        my $priority = C4::Reserves::CalculatePriority( $biblio->biblionumber ),
84
        my $resdate,
81
        my $resdate,
85
        my $expdate,
82
        my $expdate,
86
        my $notes = q{},
83
        my $notes = q{},
87
        $title,
84
        'a title',
88
        my $checkitem = $itemnumber,
85
        my $checkitem = $itemnumber,
89
        my $found,
86
        my $found,
90
    );
87
    );
91
}
88
}
92
89
93
my $biblio = Koha::Biblios->find( $biblionumber );
94
my $holds = $biblio->holds;
90
my $holds = $biblio->holds;
95
is( $holds->count, $borrowers_count, 'Test GetReserves()' );
91
is( $holds->count, $borrowers_count, 'Test GetReserves()' );
96
is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
92
is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
Lines 174-180 ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" ); Link Here
174
170
175
SuspendAll(
171
SuspendAll(
176
    borrowernumber => $borrowernumber,
172
    borrowernumber => $borrowernumber,
177
    biblionumber   => $biblionumber,
173
    biblionumber   => $biblio->biblionumber,
178
    suspend => 1,
174
    suspend => 1,
179
    suspend_until => '2012-01-01',
175
    suspend_until => '2012-01-01',
180
);
176
);
Lines 184-190 is( $hold->suspend_until, '2012-01-01 00:00:00', "Test SuspendAll(), with date" Link Here
184
180
185
SuspendAll(
181
SuspendAll(
186
    borrowernumber => $borrowernumber,
182
    borrowernumber => $borrowernumber,
187
    biblionumber   => $biblionumber,
183
    biblionumber   => $biblio->biblionumber,
188
    suspend => 0,
184
    suspend => 0,
189
);
185
);
190
$hold = Koha::Holds->find( $reserve_id );
186
$hold = Koha::Holds->find( $reserve_id );
Lines 195-213 is( $hold->suspend_until, undef, "Test resuming with SuspendAll(), should have n Link Here
195
AddReserve(
191
AddReserve(
196
    $branch_1,
192
    $branch_1,
197
    $borrowernumbers[0],
193
    $borrowernumbers[0],
198
    $biblionumber,
194
    $biblio->biblionumber,
199
    my $bibitems = q{},
195
    my $bibitems = q{},
200
    my $priority,
196
    my $priority,
201
    my $resdate,
197
    my $resdate,
202
    my $expdate,
198
    my $expdate,
203
    my $notes = q{},
199
    my $notes = q{},
204
    $title,
200
    'a title',
205
    my $checkitem,
201
    my $checkitem,
206
    my $found,
202
    my $found,
207
);
203
);
208
$patron = Koha::Patrons->find( $borrowernumber );
204
$patron = Koha::Patrons->find( $borrowernumber );
209
$holds = $patron->holds;
205
$holds = $patron->holds;
210
my $reserveid = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
206
my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
211
ModReserveMinusPriority( $itemnumber, $reserveid );
207
ModReserveMinusPriority( $itemnumber, $reserveid );
212
$holds = $patron->holds;
208
$holds = $patron->holds;
213
is( $holds->next->itemnumber, $itemnumber, "Test ModReserveMinusPriority()" );
209
is( $holds->next->itemnumber, $itemnumber, "Test ModReserveMinusPriority()" );
Lines 241-249 is( $hold->priority, '6', "Test AlterPriority(), move to bottom" ); Link Here
241
# Note that canreservefromotherbranches has no effect if
237
# Note that canreservefromotherbranches has no effect if
242
# IndependentBranches is OFF.
238
# IndependentBranches is OFF.
243
239
244
my ($foreign_bibnum, $foreign_title, $foreign_bibitemnum) = create_helper_biblio('DUMMY');
240
my $foreign_biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
245
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
241
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
246
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_bibnum);
242
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
247
$dbh->do('DELETE FROM issuingrules');
243
$dbh->do('DELETE FROM issuingrules');
248
$dbh->do(
244
$dbh->do(
249
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
245
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 286-299 ok( Link Here
286
282
287
{
283
{
288
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
284
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
289
    ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
285
    $biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
290
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
286
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
291
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $bibnum, '', 1);
287
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
292
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
288
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
293
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $bibnum, '', 2);
289
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
294
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
290
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
295
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $bibnum, '', 3);
291
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
296
    my $hhh = Koha::Holds->search({ biblionumber => $bibnum });
292
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
297
    my $hold3 = Koha::Holds->find( $reserveid3 );
293
    my $hold3 = Koha::Holds->find( $reserveid3 );
298
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
294
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
299
    ModReserve({ reserve_id => $reserveid1, rank => 'del' });
295
    ModReserve({ reserve_id => $reserveid1, rank => 'del' });
Lines 323-334 ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', Link Here
323
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
319
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
324
320
325
# Regression test for bug 9532
321
# Regression test for bug 9532
326
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
322
$biblio = $builder->gimme_a_biblio({ itemtype => 'CANNOT' });
327
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
323
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
328
AddReserve(
324
AddReserve(
329
    $branch_1,
325
    $branch_1,
330
    $borrowernumbers[0],
326
    $borrowernumbers[0],
331
    $bibnum,
327
    $biblio->biblionumber,
332
    '',
328
    '',
333
    1,
329
    1,
334
);
330
);
Lines 371-390 $dbh->do(q{ Link Here
371
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
367
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
372
    VALUES (?, ?, ?, ?)
368
    VALUES (?, ?, ?, ?)
373
}, {}, $branch_1, 'CAN', 1, 'homebranch');
369
}, {}, $branch_1, 'CAN', 1, 'homebranch');
374
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
370
$biblio = $builder->gimme_a_biblio({ itemtype => 'CANNOT' });
375
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
371
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
376
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
372
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
377
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
373
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
378
    "CanItemBeReserved should return 'notReservable'");
374
    "CanItemBeReserved should return 'notReservable'");
379
375
380
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
376
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
381
    { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
377
    { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
382
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
378
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
383
    'cannotReserveFromOtherBranches',
379
    'cannotReserveFromOtherBranches',
384
    "CanItemBeReserved should return 'cannotReserveFromOtherBranches'");
380
    "CanItemBeReserved should return 'cannotReserveFromOtherBranches'");
385
381
386
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
382
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
387
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
383
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
388
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
384
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
389
    "CanItemBeReserved should return 'OK'");
385
    "CanItemBeReserved should return 'OK'");
390
386
Lines 397-405 $dbh->do('DELETE FROM issues'); Link Here
397
$dbh->do('DELETE FROM items');
393
$dbh->do('DELETE FROM items');
398
$dbh->do('DELETE FROM biblio');
394
$dbh->do('DELETE FROM biblio');
399
395
400
( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
396
$biblio = $builder->gimme_a_biblio({ itemtype => 'ONLY1' });
401
( $item_bibnum, $item_bibitemnum, $itemnumber )
397
( $item_bibnum, $item_bibitemnum, $itemnumber )
402
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
398
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
403
399
404
$dbh->do(
400
$dbh->do(
405
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
401
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 410-416 $dbh->do( Link Here
410
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
406
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
411
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
407
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
412
408
413
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
409
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
414
410
415
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
411
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
416
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
412
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
Lines 422-431 subtest 'Test max_holds per library/patron category' => sub { Link Here
422
    $dbh->do('DELETE FROM issuingrules');
418
    $dbh->do('DELETE FROM issuingrules');
423
    $dbh->do('DELETE FROM circulation_rules');
419
    $dbh->do('DELETE FROM circulation_rules');
424
420
425
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
421
    $biblio = $builder->gimme_a_biblio({ itemtype => 'TEST' });
426
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
422
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
427
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
423
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
428
        $bibnum );
424
        $biblio->biblionumber );
429
    $dbh->do(
425
    $dbh->do(
430
        q{
426
        q{
431
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
427
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 434-442 subtest 'Test max_holds per library/patron category' => sub { Link Here
434
        {},
430
        {},
435
        '*', '*', 'TEST', 99, 99
431
        '*', '*', 'TEST', 99, 99
436
    );
432
    );
437
    AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
433
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
438
    AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
434
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
439
    AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
435
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
440
436
441
    my $count =
437
    my $count =
442
      Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
438
      Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
Lines 492-500 subtest 'Test max_holds per library/patron category' => sub { Link Here
492
subtest 'Pickup location availability tests' => sub {
488
subtest 'Pickup location availability tests' => sub {
493
    plan tests => 3;
489
    plan tests => 3;
494
490
495
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
491
    $biblio = $builder->gimme_a_biblio({ itemtype => 'ONLY1' });
496
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
492
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
497
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
493
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
498
    #Add a default rule to allow some holds
494
    #Add a default rule to allow some holds
499
    $dbh->do(
495
    $dbh->do(
500
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
496
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 537-562 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
537
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
533
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
538
534
539
    # Create 3 biblios with items
535
    # Create 3 biblios with items
540
    my ($bibnum_1) = create_helper_biblio( $itemtype->itemtype );
536
    my $biblio_1 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
541
    my ( undef, undef, $itemnumber_1 ) = AddItem(
537
    my ( undef, undef, $itemnumber_1 ) = AddItem(
542
        {   homebranch    => $library->branchcode,
538
        {   homebranch    => $library->branchcode,
543
            holdingbranch => $library->branchcode
539
            holdingbranch => $library->branchcode
544
        },
540
        },
545
        $bibnum
541
        $biblio_1->biblionumber
546
    );
542
    );
547
    my ($bibnum_2) = create_helper_biblio( $itemtype->itemtype );
543
    my $biblio_2 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
548
    my ( undef, undef, $itemnumber_2 ) = AddItem(
544
    my ( undef, undef, $itemnumber_2 ) = AddItem(
549
        {   homebranch    => $library->branchcode,
545
        {   homebranch    => $library->branchcode,
550
            holdingbranch => $library->branchcode
546
            holdingbranch => $library->branchcode
551
        },
547
        },
552
        $bibnum_2
548
        $biblio_2->biblionumber
553
    );
549
    );
554
    my ($bibnum_3) = create_helper_biblio( $itemtype->itemtype );
550
    my $biblio_3 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
555
    my ( undef, undef, $itemnumber_3 ) = AddItem(
551
    my ( undef, undef, $itemnumber_3 ) = AddItem(
556
        {   homebranch    => $library->branchcode,
552
        {   homebranch    => $library->branchcode,
557
            holdingbranch => $library->branchcode
553
            holdingbranch => $library->branchcode
558
        },
554
        },
559
        $bibnum_3
555
        $biblio_3->biblionumber
560
    );
556
    );
561
557
562
    Koha::IssuingRules->search->delete;
558
    Koha::IssuingRules->search->delete;
Lines 576-582 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
576
        'Patron can reserve item with hold limit of 1, no holds placed'
572
        'Patron can reserve item with hold limit of 1, no holds placed'
577
    );
573
    );
578
574
579
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, );
575
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
580
576
581
    is_deeply(
577
    is_deeply(
582
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ),
578
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ),
Lines 594-600 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
594
    );
590
    );
595
591
596
    # Add a second reserve
592
    # Add a second reserve
597
    my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, );
593
    my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
598
    is_deeply(
594
    is_deeply(
599
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
595
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
600
        { status => 'tooManyReservesToday', limit => 2 },
596
        { status => 'tooManyReservesToday', limit => 2 },
Lines 630-643 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
630
        { status => 'OK' },
626
        { status => 'OK' },
631
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
627
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
632
    );
628
    );
633
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, );
629
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
634
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, );
630
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
635
    is_deeply(
631
    is_deeply(
636
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
632
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
637
        { status => 'OK' },
633
        { status => 'OK' },
638
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
634
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
639
    );
635
    );
640
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_3, '', 1, );
636
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_3->biblionumber, '', 1, );
641
    is_deeply(
637
    is_deeply(
642
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
638
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
643
        { status => 'tooManyReserves', limit => 3 },
639
        { status => 'tooManyReserves', limit => 3 },
Lines 646-662 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
646
642
647
    $schema->storage->txn_rollback;
643
    $schema->storage->txn_rollback;
648
};
644
};
649
650
651
# Helper method to set up a Biblio.
652
sub create_helper_biblio {
653
    my $itemtype = shift;
654
    my $bib = MARC::Record->new();
655
    my $title = 'Silence in the library';
656
    $bib->append_fields(
657
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
658
        MARC::Field->new('245', ' ', ' ', a => $title),
659
        MARC::Field->new('942', ' ', ' ', c => $itemtype),
660
    );
661
    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
662
}
(-)a/t/db_dependent/Holds/LocalHoldsPriority.t (-19 / +4 lines)
Lines 40-54 my $itemtype = $builder->build( Link Here
40
40
41
my $borrowers_count = 5;
41
my $borrowers_count = 5;
42
42
43
# Create a helper biblio
43
my $biblio = $builder->gimme_a_biblio();
44
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
45
# Create a helper item for the biblio.
46
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
44
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
47
    {   homebranch    => $library4->{branchcode},
45
    {   homebranch    => $library4->{branchcode},
48
        holdingbranch => $library3->{branchcode},
46
        holdingbranch => $library3->{branchcode},
49
        itype         => $itemtype
47
        itype         => $itemtype
50
    },
48
    },
51
    $bibnum
49
    $biblio->biblionumber,
52
);
50
);
53
51
54
52
Lines 67-87 foreach ( 1 .. $borrowers_count ) { Link Here
67
    push @borrowernumbers, $borrowernumber;
65
    push @borrowernumbers, $borrowernumber;
68
}
66
}
69
67
70
my $biblionumber = $bibnum;
71
72
# Create five item level holds
68
# Create five item level holds
73
my $i = 1;
69
my $i = 1;
74
foreach my $borrowernumber (@borrowernumbers) {
70
foreach my $borrowernumber (@borrowernumbers) {
75
    AddReserve(
71
    AddReserve(
76
        $branchcodes[$i],
72
        $branchcodes[$i],
77
        $borrowernumber,
73
        $borrowernumber,
78
        $biblionumber,
74
        $biblio->biblionumber,
79
        my $bibitems   = q{},
75
        my $bibitems   = q{},
80
        my $priority = $i,
76
        my $priority = $i,
81
        my $resdate,
77
        my $resdate,
82
        my $expdate,
78
        my $expdate,
83
        my $notes = q{},
79
        my $notes = q{},
84
        $title,
80
        'a title',
85
        my $checkitem,
81
        my $checkitem,
86
        my $found,
82
        my $found,
87
    );
83
    );
Lines 116-129 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' Link Here
116
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
112
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
117
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
113
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
118
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
114
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
119
120
# Helper method to set up a Biblio.
121
sub create_helper_biblio {
122
    my $bib   = MARC::Record->new();
123
    my $title = 'Silence in the library';
124
    $bib->append_fields(
125
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
126
        MARC::Field->new( '245', ' ', ' ', a => $title ),
127
    );
128
    return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
129
}
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-20 / +4 lines)
Lines 46-55 t::lib::Mocks::mock_userenv({ flags => 1, userid => '1', branchcode => $branchco Link Here
46
46
47
my $borrowers_count = 3;
47
my $borrowers_count = 3;
48
48
49
# Create a biblio instance
49
my $biblio = $builder->gimme_a_biblio();
50
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
51
52
# Create an item
53
my $item_barcode = 'my_barcode';
50
my $item_barcode = 'my_barcode';
54
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
51
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
55
    {   homebranch    => $branchcode,
52
    {   homebranch    => $branchcode,
Lines 57-63 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( Link Here
57
        barcode       => $item_barcode,
54
        barcode       => $item_barcode,
58
        itype         => $itemtype
55
        itype         => $itemtype
59
    },
56
    },
60
    $bibnum
57
    $biblio->biblionumber,
61
);
58
);
62
59
63
# Create some borrowers
60
# Create some borrowers
Lines 73-92 foreach my $i ( 1 .. $borrowers_count ) { Link Here
73
    push @borrowernumbers, $borrowernumber;
70
    push @borrowernumbers, $borrowernumber;
74
}
71
}
75
72
76
my $biblionumber = $bibnum;
77
78
# Create five item level holds
73
# Create five item level holds
79
foreach my $borrowernumber (@borrowernumbers) {
74
foreach my $borrowernumber (@borrowernumbers) {
80
    AddReserve(
75
    AddReserve(
81
        $branchcode,
76
        $branchcode,
82
        $borrowernumber,
77
        $borrowernumber,
83
        $biblionumber,
78
        $biblio->biblionumber,
84
        my $bibitems   = q{},
79
        my $bibitems   = q{},
85
        my $priority,
80
        my $priority,
86
        my $resdate,
81
        my $resdate,
87
        my $expdate,
82
        my $expdate,
88
        my $notes = q{},
83
        my $notes = q{},
89
        $title,
84
        'a title',
90
        my $checkitem,
85
        my $checkitem,
91
        my $found,
86
        my $found,
92
    );
87
    );
Lines 104-117 ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' ); Link Here
104
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
99
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
105
100
106
$schema->storage->txn_rollback;
101
$schema->storage->txn_rollback;
107
108
# Helper method to set up a Biblio.
109
sub create_helper_biblio {
110
    my $bib   = MARC::Record->new();
111
    my $title = 'Silence in the library';
112
    $bib->append_fields(
113
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
114
        MARC::Field->new( '245', ' ', ' ', a => $title ),
115
    );
116
    return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
117
}
(-)a/t/db_dependent/Items.t (-56 / +43 lines)
Lines 56-67 subtest 'General Add, Get and Del tests' => sub { Link Here
56
56
57
    # Create a biblio instance for testing
57
    # Create a biblio instance for testing
58
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
58
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
59
    my ($bibnum, $bibitemnum) = get_biblio();
59
    my $biblio = $builder->gimme_a_biblio();
60
60
61
    # Add an item.
61
    # Add an item.
62
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
62
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
63
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
63
    cmp_ok($item_bibnum, '==', $biblio->biblionumber, "New item is linked to correct biblionumber.");
64
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
64
    cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
65
65
66
    # Get item.
66
    # Get item.
67
    my $getitem = GetItem($itemnumber);
67
    my $getitem = GetItem($itemnumber);
Lines 74-102 subtest 'General Add, Get and Del tests' => sub { Link Here
74
    # Do not modify anything, and do not explode!
74
    # Do not modify anything, and do not explode!
75
    my $dbh = C4::Context->dbh;
75
    my $dbh = C4::Context->dbh;
76
    local $dbh->{RaiseError} = 1;
76
    local $dbh->{RaiseError} = 1;
77
    ModItem({}, $bibnum, $itemnumber);
77
    ModItem({}, $biblio->biblionumber, $itemnumber);
78
78
79
    # Modify item; setting barcode.
79
    # Modify item; setting barcode.
80
    ModItem({ barcode => '987654321' }, $bibnum, $itemnumber);
80
    ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber);
81
    my $moditem = GetItem($itemnumber);
81
    my $moditem = GetItem($itemnumber);
82
    cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
82
    cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
83
83
84
    # Delete item.
84
    # Delete item.
85
    DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber });
85
    DelItem({ biblionumber => $biblio->biblionumber, itemnumber => $itemnumber });
86
    my $getdeleted = GetItem($itemnumber);
86
    my $getdeleted = GetItem($itemnumber);
87
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
87
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
88
88
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum);
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
90
    $getitem = GetItem($itemnumber);
90
    $getitem = GetItem($itemnumber);
91
    is( $getitem->{location}, $location, "The location should not have been modified" );
91
    is( $getitem->{location}, $location, "The location should not have been modified" );
92
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
92
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
93
93
94
    ModItem({ location => $location }, $bibnum, $itemnumber);
94
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
95
    $getitem = GetItem($itemnumber);
95
    $getitem = GetItem($itemnumber);
96
    is( $getitem->{location}, $location, "The location should have been set to correct location" );
96
    is( $getitem->{location}, $location, "The location should have been set to correct location" );
97
    is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
97
    is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
98
98
99
    ModItem({ location => 'CART' }, $bibnum, $itemnumber);
99
    ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber);
100
    $getitem = GetItem($itemnumber);
100
    $getitem = GetItem($itemnumber);
101
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
101
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
102
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
102
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
Lines 168-174 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
168
168
169
    # Create a new biblio
169
    # Create a new biblio
170
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
170
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
171
    my ($biblionumber, $biblioitemnumber) = get_biblio();
171
    my $biblio = $builder->gimme_a_biblio();
172
172
173
    # Add two items
173
    # Add two items
174
    my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
174
    my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
Lines 178-184 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
178
            withdrawn     => 1,
178
            withdrawn     => 1,
179
            itype         => $itemtype->{itemtype},
179
            itype         => $itemtype->{itemtype},
180
        },
180
        },
181
        $biblionumber
181
        $biblio->biblionumber
182
    );
182
    );
183
    my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
183
    my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
184
        {
184
        {
Lines 187-193 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
187
            withdrawn     => 0,
187
            withdrawn     => 0,
188
            itype         => $itemtype->{itemtype},
188
            itype         => $itemtype->{itemtype},
189
        },
189
        },
190
        $biblionumber
190
        $biblio->biblionumber
191
    );
191
    );
192
192
193
    my $opachiddenitems;
193
    my $opachiddenitems;
Lines 266-272 subtest 'GetItemsInfo tests' => sub { Link Here
266
    });
266
    });
267
267
268
    # Add a biblio
268
    # Add a biblio
269
    my ($biblionumber, $biblioitemnumber) = get_biblio();
269
    my $biblio = $builder->gimme_a_biblio();
270
    # Add an item
270
    # Add an item
271
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
271
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
272
        {
272
        {
Lines 274-280 subtest 'GetItemsInfo tests' => sub { Link Here
274
            holdingbranch => $library2->{branchcode},
274
            holdingbranch => $library2->{branchcode},
275
            itype         => $itemtype->{itemtype},
275
            itype         => $itemtype->{itemtype},
276
        },
276
        },
277
        $biblionumber
277
        $biblio->biblionumber
278
    );
278
    );
279
279
280
    my $library = Koha::Libraries->find( $library1->{branchcode} );
280
    my $library = Koha::Libraries->find( $library1->{branchcode} );
Lines 285-291 subtest 'GetItemsInfo tests' => sub { Link Here
285
    $library->opac_info("holdingbranch OPAC info");
285
    $library->opac_info("holdingbranch OPAC info");
286
    $library->store;
286
    $library->store;
287
287
288
    my @results = GetItemsInfo( $biblionumber );
288
    my @results = GetItemsInfo( $biblio->biblionumber );
289
    ok( @results, 'GetItemsInfo returns results');
289
    ok( @results, 'GetItemsInfo returns results');
290
    is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info",
290
    is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info",
291
        'GetItemsInfo returns the correct home branch OPAC info notice' );
291
        'GetItemsInfo returns the correct home branch OPAC info notice' );
Lines 357-363 subtest 'SearchItems test' => sub { Link Here
357
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
357
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
358
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
358
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
359
359
360
    my ($biblionumber) = get_biblio();
360
    my $biblio = $builder->gimme_a_biblio();
361
361
362
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
362
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
363
363
Lines 366-377 subtest 'SearchItems test' => sub { Link Here
366
        homebranch => $library1->{branchcode},
366
        homebranch => $library1->{branchcode},
367
        holdingbranch => $library1->{branchcode},
367
        holdingbranch => $library1->{branchcode},
368
        itype => $itemtype->{itemtype},
368
        itype => $itemtype->{itemtype},
369
    }, $biblionumber);
369
    }, $biblio->biblionumber);
370
    my (undef, undef, $item2_itemnumber) = AddItem({
370
    my (undef, undef, $item2_itemnumber) = AddItem({
371
        homebranch => $library2->{branchcode},
371
        homebranch => $library2->{branchcode},
372
        holdingbranch => $library2->{branchcode},
372
        holdingbranch => $library2->{branchcode},
373
        itype => $itemtype->{itemtype},
373
        itype => $itemtype->{itemtype},
374
    }, $biblionumber);
374
    }, $biblio->biblionumber);
375
375
376
    my ($items, $total_results);
376
    my ($items, $total_results);
377
377
Lines 476-482 subtest 'SearchItems test' => sub { Link Here
476
        )
476
        )
477
    );
477
    );
478
    my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record,
478
    my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record,
479
        $biblionumber);
479
        $biblio->biblionumber);
480
480
481
    # Search item where item subfield z is "foobar"
481
    # Search item where item subfield z is "foobar"
482
    $filter = {
482
    $filter = {
Lines 498-504 subtest 'SearchItems test' => sub { Link Here
498
    $cache->clear_from_cache("default_value_for_mod_marc-");
498
    $cache->clear_from_cache("default_value_for_mod_marc-");
499
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
499
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
500
500
501
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
501
    ModItemFromMarc($item3_record, $biblio->biblionumber, $item3_itemnumber);
502
502
503
    # Make sure the link is used
503
    # Make sure the link is used
504
    my $item3 = GetItem($item3_itemnumber);
504
    my $item3 = GetItem($item3_itemnumber);
Lines 534-547 subtest 'Koha::Item(s) tests' => sub { Link Here
534
534
535
    # Create a biblio and item for testing
535
    # Create a biblio and item for testing
536
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
536
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
537
    my ($bibnum, $bibitemnum) = get_biblio();
537
    my $biblio = $builder->gimme_a_biblio();
538
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
538
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
539
        {
539
        {
540
            homebranch    => $library1->{branchcode},
540
            homebranch    => $library1->{branchcode},
541
            holdingbranch => $library2->{branchcode},
541
            holdingbranch => $library2->{branchcode},
542
            itype         => $itemtype->{itemtype},
542
            itype         => $itemtype->{itemtype},
543
        },
543
        },
544
        $bibnum
544
        $biblio->biblionumber
545
    );
545
    );
546
546
547
    # Get item.
547
    # Get item.
Lines 575-581 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
575
        source => 'Itemtype',
575
        source => 'Itemtype',
576
    });
576
    });
577
577
578
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
578
    my $biblio = $builder->gimme_a_biblio();
579
    my $item_infos = [
579
    my $item_infos = [
580
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
580
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
581
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
581
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
Lines 598-604 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
598
                holdingbranch => $item_info->{holdingbanch},
598
                holdingbranch => $item_info->{holdingbanch},
599
                itype         => $itemtype->{itemtype},
599
                itype         => $itemtype->{itemtype},
600
            },
600
            },
601
            $biblionumber
601
            $biblio->biblionumber
602
        );
602
        );
603
        push @itemnumbers, $itemnumber;
603
        push @itemnumbers, $itemnumber;
604
    }
604
    }
Lines 608-639 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
608
608
609
    my ($itemfield) =
609
    my ($itemfield) =
610
      C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' );
610
      C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' );
611
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
611
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
612
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
612
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
613
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
613
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
614
      'Should carp is no record passed.';
614
      'Should carp is no record passed.';
615
615
616
    C4::Biblio::EmbedItemsInMarcBiblio({
616
    C4::Biblio::EmbedItemsInMarcBiblio({
617
        marc_record  => $record,
617
        marc_record  => $record,
618
        biblionumber => $biblionumber });
618
        biblionumber => $biblio->biblionumber });
619
    my @items = $record->field($itemfield);
619
    my @items = $record->field($itemfield);
620
    is( scalar @items, $number_of_items, 'Should return all items' );
620
    is( scalar @items, $number_of_items, 'Should return all items' );
621
621
622
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
622
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
623
        biblionumber => $biblionumber,
623
        biblionumber => $biblio->biblionumber,
624
        embed_items  => 1 });
624
        embed_items  => 1 });
625
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
625
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
626
626
627
    C4::Biblio::EmbedItemsInMarcBiblio({
627
    C4::Biblio::EmbedItemsInMarcBiblio({
628
        marc_record  => $record,
628
        marc_record  => $record,
629
        biblionumber => $biblionumber,
629
        biblionumber => $biblio->biblionumber,
630
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
630
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
631
    @items = $record->field($itemfield);
631
    @items = $record->field($itemfield);
632
    is( scalar @items, 2, 'Should return all items present in the list' );
632
    is( scalar @items, 2, 'Should return all items present in the list' );
633
633
634
    C4::Biblio::EmbedItemsInMarcBiblio({
634
    C4::Biblio::EmbedItemsInMarcBiblio({
635
        marc_record  => $record,
635
        marc_record  => $record,
636
        biblionumber => $biblionumber,
636
        biblionumber => $biblio->biblionumber,
637
        opac         => 1 });
637
        opac         => 1 });
638
    @items = $record->field($itemfield);
638
    @items = $record->field($itemfield);
639
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
639
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
Lines 644-650 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
644
644
645
    C4::Biblio::EmbedItemsInMarcBiblio({
645
    C4::Biblio::EmbedItemsInMarcBiblio({
646
        marc_record  => $record,
646
        marc_record  => $record,
647
        biblionumber => $biblionumber });
647
        biblionumber => $biblio->biblionumber });
648
    @items = $record->field($itemfield);
648
    @items = $record->field($itemfield);
649
    is( scalar @items,
649
    is( scalar @items,
650
        $number_of_items,
650
        $number_of_items,
Lines 652-658 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
652
652
653
    C4::Biblio::EmbedItemsInMarcBiblio({
653
    C4::Biblio::EmbedItemsInMarcBiblio({
654
        marc_record  => $record,
654
        marc_record  => $record,
655
        biblionumber => $biblionumber,
655
        biblionumber => $biblio->biblionumber,
656
        opac         => 1 });
656
        opac         => 1 });
657
    @items = $record->field($itemfield);
657
    @items = $record->field($itemfield);
658
    is(
658
    is(
Lines 666-672 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
666
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
666
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
667
    C4::Biblio::EmbedItemsInMarcBiblio({
667
    C4::Biblio::EmbedItemsInMarcBiblio({
668
        marc_record  => $record,
668
        marc_record  => $record,
669
        biblionumber => $biblionumber,
669
        biblionumber => $biblio->biblionumber,
670
        opac         => 1 });
670
        opac         => 1 });
671
    @items = $record->field($itemfield);
671
    @items = $record->field($itemfield);
672
    is(
672
    is(
Lines 702-708 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
702
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
702
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
703
703
704
    # Create a record with a barcode
704
    # Create a record with a barcode
705
    my ($biblionumber) = get_biblio( $framework->{frameworkcode} );
705
    my $biblio = $builder->gimme_a_biblio({ frameworkcode => $framework->{frameworkcode} });
706
    my $item_record = new MARC::Record;
706
    my $item_record = new MARC::Record;
707
    my $a_barcode = 'a barcode';
707
    my $a_barcode = 'a barcode';
708
    my $barcode_field = MARC::Field->new(
708
    my $barcode_field = MARC::Field->new(
Lines 715-721 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
715
        y => $itemtype
715
        y => $itemtype
716
    );
716
    );
717
    $item_record->append_fields( $barcode_field );
717
    $item_record->append_fields( $barcode_field );
718
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
718
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblio->biblionumber);
719
719
720
    # Make sure everything has been set up
720
    # Make sure everything has been set up
721
    my $item = GetItem($item_itemnumber);
721
    my $item = GetItem($item_itemnumber);
Lines 724-736 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
724
    # Delete the barcode field and save the record
724
    # Delete the barcode field and save the record
725
    $item_record->delete_fields( $barcode_field );
725
    $item_record->delete_fields( $barcode_field );
726
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
726
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
727
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
727
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
728
    $item = GetItem($item_itemnumber);
728
    $item = GetItem($item_itemnumber);
729
    is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
729
    is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
730
730
731
    # Re-add the barcode field and save the record
731
    # Re-add the barcode field and save the record
732
    $item_record->append_fields( $barcode_field );
732
    $item_record->append_fields( $barcode_field );
733
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
733
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
734
    $item = GetItem($item_itemnumber);
734
    $item = GetItem($item_itemnumber);
735
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
735
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
736
736
Lines 751-757 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
751
    );
751
    );
752
    $item_record->append_fields( $another_barcode_field );
752
    $item_record->append_fields( $another_barcode_field );
753
    # The DB value should not have been updated
753
    # The DB value should not have been updated
754
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
754
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
755
    $item = GetItem($item_itemnumber);
755
    $item = GetItem($item_itemnumber);
756
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
756
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
757
757
Lines 848-871 subtest 'Test logging for ModItem' => sub { Link Here
848
848
849
    # Create a biblio instance for testing
849
    # Create a biblio instance for testing
850
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
850
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
851
    my ($bibnum, $bibitemnum) = get_biblio();
851
    my $biblio = $builder->gimme_a_biblio();
852
852
853
    # Add an item.
853
    # Add an item.
854
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
854
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
855
855
856
    # False means no logging
856
    # False means no logging
857
    $schema->resultset('ActionLog')->search()->delete();
857
    $schema->resultset('ActionLog')->search()->delete();
858
    ModItem({ location => $location }, $bibnum, $itemnumber, { log_action => 0 });
858
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 0 });
859
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
859
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
860
860
861
    # True means logging
861
    # True means logging
862
    $schema->resultset('ActionLog')->search()->delete();
862
    $schema->resultset('ActionLog')->search()->delete();
863
    ModItem({ location => $location }, $bibnum, $itemnumber, { log_action => 1 });
863
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 1 });
864
    is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' );
864
    is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' );
865
865
866
    # Undefined defaults to true
866
    # Undefined defaults to true
867
    $schema->resultset('ActionLog')->search()->delete();
867
    $schema->resultset('ActionLog')->search()->delete();
868
    ModItem({ location => $location }, $bibnum, $itemnumber);
868
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
869
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
869
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
870
870
871
    $schema->storage->txn_rollback;
871
    $schema->storage->txn_rollback;
Lines 933-948 subtest 'Check add_to_rota method' => sub { Link Here
933
933
934
    $schema->storage->txn_rollback;
934
    $schema->storage->txn_rollback;
935
};
935
};
936
937
# Helper method to set up a Biblio.
938
sub get_biblio {
939
    my ( $frameworkcode ) = @_;
940
    $frameworkcode //= '';
941
    my $bib = MARC::Record->new();
942
    $bib->append_fields(
943
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
944
        MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
945
    );
946
    my ($bibnum, $bibitemnum) = AddBiblio($bib, $frameworkcode);
947
    return ($bibnum, $bibitemnum);
948
}
(-)a/t/db_dependent/Items/DelItem.t (-17 / +6 lines)
Lines 16-35 my $library = $builder->build({ Link Here
16
    source => 'Branch',
16
    source => 'Branch',
17
});
17
});
18
18
19
my ( $biblionumber, $bibitemnum ) = get_biblio();
19
my $biblio = $builder->gimme_a_biblio();
20
20
21
my ( $item_bibnum, $item_bibitemnum, $itemnumber );
21
my ( $item_bibnum, $item_bibitemnum, $itemnumber );
22
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
22
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
23
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber );
23
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber );
24
24
25
my $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
25
my $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
26
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
26
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
27
my $deleted_item = GetItem($itemnumber);
27
my $deleted_item = GetItem($itemnumber);
28
is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." );
28
is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." );
29
29
30
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
30
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
31
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber );
31
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber );
32
$deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
32
$deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
33
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
33
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
34
$deleted_item = GetItem($itemnumber);
34
$deleted_item = GetItem($itemnumber);
35
is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." );
35
is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." );
Lines 37-52 is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter Link Here
37
$deleted = DelItem( { itemnumber => $itemnumber + 1} );
37
$deleted = DelItem( { itemnumber => $itemnumber + 1} );
38
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
38
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
39
39
40
$deleted = DelItem( { itemnumber => $itemnumber + 1, biblionumber => $biblionumber } );
40
$deleted = DelItem( { itemnumber => $itemnumber + 1, biblionumber => $biblio->biblionumber } );
41
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
41
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
42
43
# Helper method to set up a Biblio.
44
sub get_biblio {
45
    my $bib = MARC::Record->new();
46
    $bib->append_fields(
47
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
48
        MARC::Field->new( '245', ' ', ' ', a => 'Silence in the library' ),
49
    );
50
    my ( $bibnum, $bibitemnum ) = AddBiblio( $bib, '' );
51
    return ( $bibnum, $bibitemnum );
52
}
(-)a/t/db_dependent/Items/GetItemsForInventory.t (-18 / +2 lines)
Lines 74-81 subtest 'Skip items with waiting holds' => sub { Link Here
74
    my $title_1 = 'Title 1, ';
74
    my $title_1 = 'Title 1, ';
75
    my $title_2 = 'Title 2, bizzarre one so doesn\'t already exist';
75
    my $title_2 = 'Title 2, bizzarre one so doesn\'t already exist';
76
76
77
    my $biblio_1 = create_helper_biblio( $itemtype->itemtype, $title_1 );
77
    my $biblio_1 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype, title => $title_1 });
78
    my $biblio_2 = create_helper_biblio( $itemtype->itemtype, $title_2 );
78
    my $biblio_2 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype, title => $title_2 });
79
79
80
    my ( $items_1, $first_items_count ) = GetItemsForInventory();
80
    my ( $items_1, $first_items_count ) = GetItemsForInventory();
81
    is( scalar @{$items_1}, $first_items_count, 'Results and count match' );
81
    is( scalar @{$items_1}, $first_items_count, 'Results and count match' );
Lines 244-262 sub OldWay { Link Here
244
244
245
    return (\@results, $iTotalRecords);
245
    return (\@results, $iTotalRecords);
246
}
246
}
247
248
# Helper method to set up a Biblio.
249
sub create_helper_biblio {
250
    my $itemtype = shift;
251
    my $title    = shift;
252
    my $record   = MARC::Record->new();
253
254
    $record->append_fields(
255
        MARC::Field->new( '245', ' ', ' ', a => $title ),
256
        MARC::Field->new( '942', ' ', ' ', c => $itemtype ),
257
    );
258
259
    my ($biblio_id) = AddBiblio( $record, '' );
260
261
    return Koha::Biblios->find($biblio_id);
262
}
(-)a/t/db_dependent/Koha/BiblioUtils/Iterator.t (-16 / +3 lines)
Lines 47-76 my $itemtype = $builder->build({ Link Here
47
47
48
# Create a biblio instance for testing
48
# Create a biblio instance for testing
49
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
49
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
50
my ($bibnum, $bibitemnum) = get_biblio();
50
my $biblio = $builder->gimme_a_biblio();
51
51
52
# Add an item.
52
# Add an item.
53
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
53
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
54
54
55
my $rs = $schema->resultset('Biblioitem')->search({});
55
my $rs = $schema->resultset('Biblioitem')->search({});
56
my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 );
56
my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 );
57
my $record = $iterator->next();
57
my $record = $iterator->next();
58
my $expected_tags = [ 100, 245, 952, 999 ];
58
my $expected_tags = [ 100, 245, 942, 952, 999 ];
59
my @result_tags = map { $_->tag() } $record->field('...');
59
my @result_tags = map { $_->tag() } $record->field('...');
60
my @sorted_tags = sort @result_tags;
60
my @sorted_tags = sort @result_tags;
61
is_deeply(\@sorted_tags,$expected_tags, "Got the same tags as expected");
61
is_deeply(\@sorted_tags,$expected_tags, "Got the same tags as expected");
62
62
63
$schema->storage->txn_rollback();
63
$schema->storage->txn_rollback();
64
65
# Helper method to set up a Biblio.
66
sub get_biblio {
67
    my ( $frameworkcode ) = @_;
68
    $frameworkcode //= '';
69
    my $bib = MARC::Record->new();
70
    $bib->append_fields(
71
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
72
        MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
73
    );
74
    my ($bibnum, $bibitemnum) = AddBiblio($bib, $frameworkcode);
75
    return ($bibnum, $bibitemnum);
76
}
(-)a/t/db_dependent/Koha/Biblios.t (-17 / +2 lines)
Lines 143-153 subtest 'can_be_transferred' => sub { Link Here
143
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
143
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
144
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
144
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
145
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
145
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
146
    my ($bibnum, $title, $bibitemnum) = create_helper_biblio('ONLY1');
146
    my $biblio = $builder->gimme_a_biblio({ itemtype => 'ONLY1' });
147
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
147
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
148
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $bibnum);
148
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $biblio->biblionumber);
149
    my $item  = Koha::Items->find($itemnumber);
149
    my $item  = Koha::Items->find($itemnumber);
150
    my $biblio = Koha::Biblios->find($bibnum);
151
150
152
    is(Koha::Item::Transfer::Limits->search({
151
    is(Koha::Item::Transfer::Limits->search({
153
        fromBranch => $library1->branchcode,
152
        fromBranch => $library1->branchcode,
Lines 188-204 subtest 'can_be_transferred' => sub { Link Here
188
};
187
};
189
188
190
$schema->storage->txn_rollback;
189
$schema->storage->txn_rollback;
191
192
# Helper method to set up a Biblio.
193
sub create_helper_biblio {
194
    my $itemtype = shift;
195
    my ($bibnum, $title, $bibitemnum);
196
    my $bib = MARC::Record->new();
197
    $title = 'Silence in the library';
198
    $bib->append_fields(
199
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
200
        MARC::Field->new('245', ' ', ' ', a => $title),
201
        MARC::Field->new('942', ' ', ' ', c => $itemtype),
202
    );
203
    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
204
}
(-)a/t/db_dependent/OAI/Sets.t (-36 / +11 lines)
Lines 27-32 use Koha::Database; Link Here
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::OAI::Sets;
28
use C4::OAI::Sets;
29
29
30
use t::lib::TestBuilder;
31
30
my $schema  = Koha::Database->new->schema;
32
my $schema  = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
33
$schema->storage->txn_begin;
32
my $dbh = C4::Context->dbh;
34
my $dbh = C4::Context->dbh;
Lines 36-42 $dbh->do('DELETE FROM oai_sets_descriptions'); Link Here
36
$dbh->do('DELETE FROM oai_sets_mappings');
38
$dbh->do('DELETE FROM oai_sets_mappings');
37
$dbh->do('DELETE FROM oai_sets_biblios');
39
$dbh->do('DELETE FROM oai_sets_biblios');
38
40
39
41
my $builder = t::lib::TestBuilder->new;
40
# ---------- Testing AddOAISet ------------------
42
# ---------- Testing AddOAISet ------------------
41
ok (!defined(AddOAISet), 'AddOAISet without argument is undef');
43
ok (!defined(AddOAISet), 'AddOAISet without argument is undef');
42
44
Lines 353-361 ok (!defined(AddOAISetsBiblios(my $arg=[])), 'AddOAISetsBiblios with a no HASH a Link Here
353
ok (defined(AddOAISetsBiblios($arg={})), 'AddOAISetsBiblios with a HASH argument is def');
355
ok (defined(AddOAISetsBiblios($arg={})), 'AddOAISetsBiblios with a HASH argument is def');
354
356
355
# Create a biblio instance for testing
357
# Create a biblio instance for testing
356
my $biblionumber1 = create_helper_biblio('Moffat, Steven');
358
my $biblio_1 = $builder->gimme_a_biblio({ author => 'Moffat, Steven' });
359
my $biblionumber1 = $biblio_1->biblionumber;
357
isa_ok(\$biblionumber1, 'SCALAR', '$biblionumber1 is a SCALAR');
360
isa_ok(\$biblionumber1, 'SCALAR', '$biblionumber1 is a SCALAR');
358
my $biblionumber2 = create_helper_biblio('Moffat, Steven');
361
my $biblio_2 = $builder->gimme_a_biblio({ author => 'Moffat, Steven' });
362
my $biblionumber2 = $biblio_2->biblionumber;
359
isa_ok(\$biblionumber2, 'SCALAR', '$biblionumber2 is a SCALAR');
363
isa_ok(\$biblionumber2, 'SCALAR', '$biblionumber2 is a SCALAR');
360
364
361
my $oai_sets_biblios = {
365
my $oai_sets_biblios = {
Lines 517-523 ModOAISetMappings($setVH_id, $mappingsVH); Link Here
517
521
518
522
519
#Create a biblio notice corresponding at one of mappings
523
#Create a biblio notice corresponding at one of mappings
520
my $biblionumberVH = create_helper_biblio('Victor Hugo');
524
my $biblio_VH = $builder->gimme_a_biblio({ author => 'Victor Hugo' });
525
my $biblionumberVH = $biblio_VH->biblionumber;
521
526
522
#Update
527
#Update
523
my $record = GetMarcBiblio({ biblionumber => $biblionumberVH });
528
my $record = GetMarcBiblio({ biblionumber => $biblionumberVH });
Lines 572-578 ModOAISetMappings($setNotVH_id, $mappingsNotVH); Link Here
572
577
573
578
574
#Create a biblio notice corresponding at one of mappings
579
#Create a biblio notice corresponding at one of mappings
575
my $biblionumberNotVH = create_helper_biblio('Sponge, Bob');
580
my $biblio_NotVH = $builder->gimme_a_biblio({ author => 'Sponge, Bob' });
581
my $biblionumberNotVH = $biblio_NotVH->biblionumber;
576
582
577
#Update
583
#Update
578
$record = GetMarcBiblio({ biblionumber => $biblionumberNotVH });
584
$record = GetMarcBiblio({ biblionumber => $biblionumberNotVH });
Lines 581-615 UpdateOAISetsBiblio($biblionumberNotVH, $record); Link Here
581
my @setsNotEq = CalcOAISetsBiblio($record);
587
my @setsNotEq = CalcOAISetsBiblio($record);
582
is_deeply(@setsNotEq, $setNotVH_id, 'The $record only belongs to $setNotVH');
588
is_deeply(@setsNotEq, $setNotVH_id, 'The $record only belongs to $setNotVH');
583
589
584
585
586
# ---------- Subs --------------------------------
587
588
589
# Helper method to set up a Biblio.
590
sub create_helper_biblio {
591
    my $author = shift;
592
593
    return unless (defined($author));
594
595
    my $marcflavour = C4::Context->preference('marcflavour');
596
    my $bib = MARC::Record->new();
597
    my $title = 'Silence in the library';
598
599
    if ($marcflavour eq 'UNIMARC' ){
600
        $bib->append_fields(
601
            MARC::Field->new('200', ' ', ' ', f => $author),
602
            MARC::Field->new('200', ' ', ' ', a => $title),
603
        );
604
    }
605
    else{
606
        $bib->append_fields(
607
            MARC::Field->new('100', ' ', ' ', a => $author),
608
            MARC::Field->new('245', ' ', ' ', a => $title),
609
        );
610
    }
611
    my ($biblionumber)= AddBiblio($bib, '');
612
    return $biblionumber;
613
}
614
615
$schema->storage->txn_rollback;
590
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Serials.t (-11 / +2 lines)
Lines 145-151 subtest 'Values should not be erased on editing' => sub { Link Here
145
145
146
    plan tests => 1;
146
    plan tests => 1;
147
147
148
    ( $biblionumber, $biblioitemnumber ) = get_biblio();
148
    my $biblio = $builder->gimme_a_biblio();
149
    my $biblionumber = $biblio->biblionumber;
149
    my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField( 'items.itemcallnumber', '' );
150
    my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField( 'items.itemcallnumber', '' );
150
    my ( $it_tag, $it_sf )   = GetMarcFromKohaField( 'items.itype', '' );
151
    my ( $it_tag, $it_sf )   = GetMarcFromKohaField( 'items.itype', '' );
151
152
Lines 349-361 subtest "Do not generate an expected if one already exists" => sub { Link Here
349
};
350
};
350
351
351
$dbh->rollback;
352
$dbh->rollback;
352
353
sub get_biblio {
354
    my $bib = MARC::Record->new();
355
    $bib->append_fields(
356
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
357
        MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
358
    );
359
    my ($bibnum, $bibitemnum) = AddBiblio($bib, '');
360
    return ($bibnum, $bibitemnum);
361
}
(-)a/t/lib/TestBuilder.pm (-6 / +22 lines)
Lines 3-8 package t::lib::TestBuilder; Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Koha::Database;
5
use Koha::Database;
6
use C4::Biblio;
7
use Koha::Biblios;
6
8
7
use Bytes::Random::Secure;
9
use Bytes::Random::Secure;
8
use Carp;
10
use Carp;
Lines 128-143 sub build { Link Here
128
sub gimme_a_biblio {
130
sub gimme_a_biblio {
129
    my ( $self, $args ) = @_;
131
    my ( $self, $args ) = @_;
130
132
131
    my $itemtype = $args->{itemtype} || $self->build_object({ class => 'Koha::ItemTypes' })->itemtype;
133
    my $title  = $args->{title}  || 'Some boring read';
132
    my $title    = $args->{title}    || 'Some boring read';
134
    my $author = $args->{author} || 'Some boring author';
135
    my $frameworkcode = $args->{frameworkcode} || '';
136
    my $itemtype = $args->{itemtype}
137
      || $self->build_object( { class => 'Koha::ItemTypes' } )->itemtype;
138
139
    my $marcflavour = C4::Context->preference('marcflavour');
133
140
134
    my $record = MARC::Record->new();
141
    my $record = MARC::Record->new();
142
    my ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 200, 'a' ) : ( 245, 'a' );
143
    $record->append_fields(
144
        MARC::Field->new( $tag, ' ', ' ', $subfield => $title ),
145
    );
146
147
    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 200, 'f' ) : ( 100, 'a' );
148
    $record->append_fields(
149
        MARC::Field->new( $tag, ' ', ' ', $subfield => $author ),
150
    );
151
152
    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 995, 'r' ) : ( 942, 'c' );
135
    $record->append_fields(
153
    $record->append_fields(
136
        MARC::Field->new( '245', ' ', ' ', a => $title ),
154
        MARC::Field->new( $tag, ' ', ' ', $subfield => $itemtype )
137
        MARC::Field->new( '942', ' ', ' ', c => $itemtype )
138
    );
155
    );
139
156
140
    my ($biblio_id) = AddBiblio( $record, '' );
157
    my ($biblio_id) = C4::Biblio::AddBiblio( $record, $frameworkcode );
141
    return Koha::Biblios->find($biblio_id);
158
    return Koha::Biblios->find($biblio_id);
142
}
159
}
143
160
144
- 

Return to bug 21798