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

(-)a/t/db_dependent/Circulation.t (-84 / +54 lines)
Lines 228-235 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
228
# CanBookBeRenewed tests
228
# CanBookBeRenewed tests
229
    C4::Context->set_preference('ItemsDeniedRenewal','');
229
    C4::Context->set_preference('ItemsDeniedRenewal','');
230
    # Generate test biblio
230
    # Generate test biblio
231
    my $title = 'Silence in the library';
231
    my $biblio = $builder->gimme_a_biblio();
232
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
233
232
234
    my $barcode = 'R00000342';
233
    my $barcode = 'R00000342';
235
    my $branch = $library2->{branchcode};
234
    my $branch = $library2->{branchcode};
Lines 242-248 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
242
            replacementprice => 12.00,
241
            replacementprice => 12.00,
243
            itype            => $itemtype
242
            itype            => $itemtype
244
        },
243
        },
245
        $biblionumber
244
        $biblio->biblionumber
246
    );
245
    );
247
246
248
    my $barcode2 = 'R00000343';
247
    my $barcode2 = 'R00000343';
Lines 254-260 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
254
            replacementprice => 23.00,
253
            replacementprice => 23.00,
255
            itype            => $itemtype
254
            itype            => $itemtype
256
        },
255
        },
257
        $biblionumber
256
        $biblio->biblionumber
258
    );
257
    );
259
258
260
    my $barcode3 = 'R00000346';
259
    my $barcode3 = 'R00000346';
Lines 266-272 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
266
            replacementprice => 23.00,
265
            replacementprice => 23.00,
267
            itype            => $itemtype
266
            itype            => $itemtype
268
        },
267
        },
269
        $biblionumber
268
        $biblio->biblionumber
270
    );
269
    );
271
270
272
    # Create borrowers
271
    # Create borrowers
Lines 343-351 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
343
342
344
    # Biblio-level hold, renewal test
343
    # Biblio-level hold, renewal test
345
    AddReserve(
344
    AddReserve(
346
        $branch, $reserving_borrowernumber, $biblionumber,
345
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
347
        $bibitems,  $priority, $resdate, $expdate, $notes,
346
        $bibitems,  $priority, $resdate, $expdate, $notes,
348
        $title, $checkitem, $found
347
        'a title', $checkitem, $found
349
    );
348
    );
350
349
351
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
350
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
Lines 360-366 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
360
    my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
359
    my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
361
        {
360
        {
362
            borrowernumber => $hold_waiting_borrowernumber,
361
            borrowernumber => $hold_waiting_borrowernumber,
363
            biblionumber   => $biblionumber,
362
            biblionumber   => $biblio->biblionumber,
364
            itemnumber     => $itemnumber,
363
            itemnumber     => $itemnumber,
365
            branchcode     => $branch,
364
            branchcode     => $branch,
366
            priority       => 3,
365
            priority       => 3,
Lines 375-381 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
375
    $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
374
    $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
376
        {
375
        {
377
            borrowernumber => $hold_waiting_borrowernumber,
376
            borrowernumber => $hold_waiting_borrowernumber,
378
            biblionumber   => $biblionumber,
377
            biblionumber   => $biblio->biblionumber,
379
            itemnumber     => $itemnumber3,
378
            itemnumber     => $itemnumber3,
380
            branchcode     => $branch,
379
            branchcode     => $branch,
381
            priority       => 0,
380
            priority       => 0,
Lines 396-402 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
396
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
395
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
397
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
396
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
398
397
399
    my $reserveid = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
398
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
400
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
399
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
401
    AddIssue($reserving_borrower, $barcode3);
400
    AddIssue($reserving_borrower, $barcode3);
402
    my $reserve = $dbh->selectrow_hashref(
401
    my $reserve = $dbh->selectrow_hashref(
Lines 408-416 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
408
407
409
    # Item-level hold, renewal test
408
    # Item-level hold, renewal test
410
    AddReserve(
409
    AddReserve(
411
        $branch, $reserving_borrowernumber, $biblionumber,
410
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
412
        $bibitems,  $priority, $resdate, $expdate, $notes,
411
        $bibitems,  $priority, $resdate, $expdate, $notes,
413
        $title, $itemnumber, $found
412
        'a title', $itemnumber, $found
414
    );
413
    );
415
414
416
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
415
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
Lines 421-430 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
421
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
420
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
422
421
423
    # Items can't fill hold for reasons
422
    # Items can't fill hold for reasons
424
    ModItem({ notforloan => 1 }, $biblionumber, $itemnumber);
423
    ModItem({ notforloan => 1 }, $biblio->biblionumber, $itemnumber);
425
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
424
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
426
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
425
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
427
    ModItem({ notforloan => 0, itype => $itemtype }, $biblionumber, $itemnumber);
426
    ModItem({ notforloan => 0, itype => $itemtype }, $biblio->biblionumber, $itemnumber);
428
427
429
    # FIXME: Add more for itemtype not for loan etc.
428
    # FIXME: Add more for itemtype not for loan etc.
430
429
Lines 438-444 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
438
            replacementprice => 23.00,
437
            replacementprice => 23.00,
439
            itype            => $itemtype
438
            itype            => $itemtype
440
        },
439
        },
441
        $biblionumber
440
        $biblio->biblionumber
442
    );
441
    );
443
    my $datedue5 = AddIssue($restricted_borrower, $barcode5);
442
    my $datedue5 = AddIssue($restricted_borrower, $barcode5);
444
    is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
443
    is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
Lines 459-465 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
459
            replacementprice => 23.00,
458
            replacementprice => 23.00,
460
            itype            => $itemtype
459
            itype            => $itemtype
461
        },
460
        },
462
        $biblionumber
461
        $biblio->biblionumber
463
    );
462
    );
464
463
465
    my $barcode7 = 'R00000349';
464
    my $barcode7 = 'R00000349';
Lines 471-477 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
471
            replacementprice => 23.00,
470
            replacementprice => 23.00,
472
            itype            => $itemtype
471
            itype            => $itemtype
473
        },
472
        },
474
        $biblionumber
473
        $biblio->biblionumber
475
    );
474
    );
476
    my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
475
    my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
477
    is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
476
    is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
Lines 535-541 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
535
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
534
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
536
535
537
536
538
    $hold = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next;
537
    $hold = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next;
539
    $hold->cancel;
538
    $hold->cancel;
540
539
541
    # Bug 14101
540
    # Bug 14101
Lines 550-556 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
550
            replacementprice => 16.00,
549
            replacementprice => 16.00,
551
            itype            => $itemtype
550
            itype            => $itemtype
552
        },
551
        },
553
        $biblionumber
552
        $biblio->biblionumber
554
    );
553
    );
555
554
556
    $issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
555
    $issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
Lines 620-626 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
620
        my $item_to_auto_renew = $builder->build(
619
        my $item_to_auto_renew = $builder->build(
621
            {   source => 'Item',
620
            {   source => 'Item',
622
                value  => {
621
                value  => {
623
                    biblionumber  => $biblionumber,
622
                    biblionumber  => $biblio->biblionumber,
624
                    homebranch    => $branch,
623
                    homebranch    => $branch,
625
                    holdingbranch => $branch,
624
                    holdingbranch => $branch,
626
                }
625
                }
Lines 679-685 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
679
        my $item_to_auto_renew = $builder->build({
678
        my $item_to_auto_renew = $builder->build({
680
            source => 'Item',
679
            source => 'Item',
681
            value => {
680
            value => {
682
                biblionumber => $biblionumber,
681
                biblionumber => $biblio->biblionumber,
683
                homebranch       => $branch,
682
                homebranch       => $branch,
684
                holdingbranch    => $branch,
683
                holdingbranch    => $branch,
685
            }
684
            }
Lines 719-725 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
719
        my $item_to_auto_renew = $builder->build({
718
        my $item_to_auto_renew = $builder->build({
720
            source => 'Item',
719
            source => 'Item',
721
            value => {
720
            value => {
722
                biblionumber => $biblionumber,
721
                biblionumber => $biblio->biblionumber,
723
                homebranch       => $branch,
722
                homebranch       => $branch,
724
                holdingbranch    => $branch,
723
                holdingbranch    => $branch,
725
            }
724
            }
Lines 771-777 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
771
        my $item_to_auto_renew = $builder->build(
770
        my $item_to_auto_renew = $builder->build(
772
            {   source => 'Item',
771
            {   source => 'Item',
773
                value  => {
772
                value  => {
774
                    biblionumber  => $biblionumber,
773
                    biblionumber  => $biblio->biblionumber,
775
                    homebranch    => $branch,
774
                    homebranch    => $branch,
776
                    holdingbranch => $branch,
775
                    holdingbranch => $branch,
777
                }
776
                }
Lines 923-930 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
923
    my $branch   = $library2->{branchcode};
922
    my $branch   = $library2->{branchcode};
924
923
925
    #Create another record
924
    #Create another record
926
    my $title2 = 'Something is worng here';
925
    my $biblio2 = $builder->gimme_a_biblio();
927
    my ($biblionumber2, $biblioitemnumber2) = add_biblio($title2, 'Anonymous');
928
926
929
    #Create third item
927
    #Create third item
930
    AddItem(
928
    AddItem(
Lines 934-940 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
934
            barcode          => $barcode3,
932
            barcode          => $barcode3,
935
            itype            => $itemtype
933
            itype            => $itemtype
936
        },
934
        },
937
        $biblionumber2
935
        $biblio2->biblionumber
938
    );
936
    );
939
937
940
    # Create a borrower
938
    # Create a borrower
Lines 1003-1009 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1003
    my $barcode  = '1234567890';
1001
    my $barcode  = '1234567890';
1004
    my $branch   = $library2->{branchcode};
1002
    my $branch   = $library2->{branchcode};
1005
1003
1006
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1004
    my $biblio = $builder->gimme_a_biblio();
1007
1005
1008
    #Create third item
1006
    #Create third item
1009
    my ( undef, undef, $itemnumber ) = AddItem(
1007
    my ( undef, undef, $itemnumber ) = AddItem(
Lines 1013-1019 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1013
            barcode          => $barcode,
1011
            barcode          => $barcode,
1014
            itype            => $itemtype
1012
            itype            => $itemtype
1015
        },
1013
        },
1016
        $biblionumber
1014
        $biblio->biblionumber
1017
    );
1015
    );
1018
1016
1019
    # Create a borrower
1017
    # Create a borrower
Lines 1060-1066 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1060
        undef,  0,
1058
        undef,  0,
1061
        .10, 1
1059
        .10, 1
1062
    );
1060
    );
1063
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1061
    my $biblio = $builder->gimme_a_biblio();
1064
1062
1065
    my $barcode1 = '1234';
1063
    my $barcode1 = '1234';
1066
    my ( undef, undef, $itemnumber1 ) = AddItem(
1064
    my ( undef, undef, $itemnumber1 ) = AddItem(
Lines 1070-1076 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1070
            barcode       => $barcode1,
1068
            barcode       => $barcode1,
1071
            itype         => $itemtype
1069
            itype         => $itemtype
1072
        },
1070
        },
1073
        $biblionumber
1071
        $biblio->biblionumber
1074
    );
1072
    );
1075
    my $barcode2 = '4321';
1073
    my $barcode2 = '4321';
1076
    my ( undef, undef, $itemnumber2 ) = AddItem(
1074
    my ( undef, undef, $itemnumber2 ) = AddItem(
Lines 1080-1086 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1080
            barcode       => $barcode2,
1078
            barcode       => $barcode2,
1081
            itype         => $itemtype
1079
            itype         => $itemtype
1082
        },
1080
        },
1083
        $biblionumber
1081
        $biblio->biblionumber
1084
    );
1082
    );
1085
1083
1086
    my $borrowernumber1 = Koha::Patron->new({
1084
    my $borrowernumber1 = Koha::Patron->new({
Lines 1105-1111 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1105
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1103
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1106
1104
1107
    AddReserve(
1105
    AddReserve(
1108
        $library2->{branchcode}, $borrowernumber2, $biblionumber,
1106
        $library2->{branchcode}, $borrowernumber2, $biblio->biblionumber,
1109
        '',  1, undef, undef, '',
1107
        '',  1, undef, undef, '',
1110
        undef, undef, undef
1108
        undef, undef, undef
1111
    );
1109
    );
Lines 1131-1137 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1131
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1129
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1132
1130
1133
    # Setting item not checked out to be not for loan but holdable
1131
    # Setting item not checked out to be not for loan but holdable
1134
    ModItem({ notforloan => -1 }, $biblionumber, $itemnumber2);
1132
    ModItem({ notforloan => -1 }, $biblio->biblionumber, $itemnumber2);
1135
1133
1136
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1134
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1137
    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' );
1135
    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 1143-1149 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1143
    my $branch   = $library->{branchcode};
1141
    my $branch   = $library->{branchcode};
1144
1142
1145
    #Create another record
1143
    #Create another record
1146
    my ($biblionumber, $biblioitemnumber) = add_biblio('A title', 'Anonymous');
1144
    my $biblio = $builder->gimme_a_biblio();
1147
1145
1148
    my (undef, undef, $itemnumber) = AddItem(
1146
    my (undef, undef, $itemnumber) = AddItem(
1149
        {
1147
        {
Lines 1152-1158 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1152
            barcode          => $barcode,
1150
            barcode          => $barcode,
1153
            itype            => $itemtype
1151
            itype            => $itemtype
1154
        },
1152
        },
1155
        $biblionumber
1153
        $biblio->biblionumber
1156
    );
1154
    );
1157
1155
1158
    my $borrowernumber = Koha::Patron->new({
1156
    my $borrowernumber = Koha::Patron->new({
Lines 1173-1179 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1173
{
1171
{
1174
    my $library = $builder->build({ source => 'Branch' });
1172
    my $library = $builder->build({ source => 'Branch' });
1175
1173
1176
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1174
    my $biblio = $builder->gimme_a_biblio();
1177
1175
1178
    my $barcode = 'just a barcode';
1176
    my $barcode = 'just a barcode';
1179
    my ( undef, undef, $itemnumber ) = AddItem(
1177
    my ( undef, undef, $itemnumber ) = AddItem(
Lines 1183-1189 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1183
            barcode          => $barcode,
1181
            barcode          => $barcode,
1184
            itype            => $itemtype
1182
            itype            => $itemtype
1185
        },
1183
        },
1186
        $biblionumber,
1184
        $biblio->biblionumber,
1187
    );
1185
    );
1188
1186
1189
    my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1187
    my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
Lines 1473-1480 subtest 'CanBookBeIssued + Statistic patrons "X"' => sub { Link Here
1473
subtest 'MultipleReserves' => sub {
1471
subtest 'MultipleReserves' => sub {
1474
    plan tests => 3;
1472
    plan tests => 3;
1475
1473
1476
    my $title = 'Silence in the library';
1474
    my $biblio = $builder->gimme_a_biblio();
1477
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
1478
1475
1479
    my $branch = $library2->{branchcode};
1476
    my $branch = $library2->{branchcode};
1480
1477
Lines 1487-1493 subtest 'MultipleReserves' => sub { Link Here
1487
            replacementprice => 12.00,
1484
            replacementprice => 12.00,
1488
            itype            => $itemtype
1485
            itype            => $itemtype
1489
        },
1486
        },
1490
        $biblionumber
1487
        $biblio->biblionumber
1491
    );
1488
    );
1492
1489
1493
    my $barcode2 = 'R00110002';
1490
    my $barcode2 = 'R00110002';
Lines 1499-1505 subtest 'MultipleReserves' => sub { Link Here
1499
            replacementprice => 12.00,
1496
            replacementprice => 12.00,
1500
            itype            => $itemtype
1497
            itype            => $itemtype
1501
        },
1498
        },
1502
        $biblionumber
1499
        $biblio->biblionumber
1503
    );
1500
    );
1504
1501
1505
    my $bibitems       = '';
1502
    my $bibitems       = '';
Lines 1531-1539 subtest 'MultipleReserves' => sub { Link Here
1531
    );
1528
    );
1532
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1529
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1533
    AddReserve(
1530
    AddReserve(
1534
        $branch, $reserving_borrowernumber1, $biblionumber,
1531
        $branch, $reserving_borrowernumber1, $biblio->biblionumber,
1535
        $bibitems,  $priority, $resdate, $expdate, $notes,
1532
        $bibitems,  $priority, $resdate, $expdate, $notes,
1536
        $title, $checkitem, $found
1533
        'a title', $checkitem, $found
1537
    );
1534
    );
1538
1535
1539
    my %reserving_borrower_data2 = (
1536
    my %reserving_borrower_data2 = (
Lines 1544-1552 subtest 'MultipleReserves' => sub { Link Here
1544
    );
1541
    );
1545
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1542
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1546
    AddReserve(
1543
    AddReserve(
1547
        $branch, $reserving_borrowernumber2, $biblionumber,
1544
        $branch, $reserving_borrowernumber2, $biblio->biblionumber,
1548
        $bibitems,  $priority, $resdate, $expdate, $notes,
1545
        $bibitems,  $priority, $resdate, $expdate, $notes,
1549
        $title, $checkitem, $found
1546
        'a title', $checkitem, $found
1550
    );
1547
    );
1551
1548
1552
    {
1549
    {
Lines 1563-1569 subtest 'MultipleReserves' => sub { Link Here
1563
            replacementprice => 12.00,
1560
            replacementprice => 12.00,
1564
            itype            => $itemtype
1561
            itype            => $itemtype
1565
        },
1562
        },
1566
        $biblionumber
1563
        $biblio->biblionumber
1567
    );
1564
    );
1568
1565
1569
    {
1566
    {
Lines 2011-2019 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2011
    );
2008
    );
2012
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
2009
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
2013
2010
2014
    # Generate test biblio
2011
    my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Daria' });
2015
    my $title = 'Koha for Dummies';
2016
    my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, 'Hall, Daria' );
2017
2012
2018
    subtest 'Full write-off tests' => sub {
2013
    subtest 'Full write-off tests' => sub {
2019
2014
Lines 2029-2041 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2029
                replacementprice => $replacement_amount,
2024
                replacementprice => $replacement_amount,
2030
                itype            => $item_type->itemtype
2025
                itype            => $item_type->itemtype
2031
            },
2026
            },
2032
            $biblionumber
2027
            $biblio->biblionumber
2033
        );
2028
        );
2034
2029
2035
        AddIssue( $patron->unblessed, $barcode );
2030
        AddIssue( $patron->unblessed, $barcode );
2036
2031
2037
        # Simulate item marked as lost
2032
        # Simulate item marked as lost
2038
        ModItem( { itemlost => 3 }, $biblionumber, $item_id );
2033
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
2039
        LostItem( $item_id, 1 );
2034
        LostItem( $item_id, 1 );
2040
2035
2041
        my $processing_fee_lines = Koha::Account::Lines->search(
2036
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2091-2103 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2091
                replacementprice => $replacement_amount,
2086
                replacementprice => $replacement_amount,
2092
                itype            => $item_type->itemtype
2087
                itype            => $item_type->itemtype
2093
            },
2088
            },
2094
            $biblionumber
2089
            $biblio->biblionumber
2095
        );
2090
        );
2096
2091
2097
        AddIssue( $patron->unblessed, $barcode );
2092
        AddIssue( $patron->unblessed, $barcode );
2098
2093
2099
        # Simulate item marked as lost
2094
        # Simulate item marked as lost
2100
        ModItem( { itemlost => 1 }, $biblionumber, $item_id );
2095
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
2101
        LostItem( $item_id, 1 );
2096
        LostItem( $item_id, 1 );
2102
2097
2103
        my $processing_fee_lines = Koha::Account::Lines->search(
2098
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2160-2172 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2160
                replacementprice => $replacement_amount,
2155
                replacementprice => $replacement_amount,
2161
                itype            => $item_type->itemtype
2156
                itype            => $item_type->itemtype
2162
            },
2157
            },
2163
            $biblionumber
2158
            $biblio->biblionumber
2164
        );
2159
        );
2165
2160
2166
        AddIssue( $patron->unblessed, $barcode );
2161
        AddIssue( $patron->unblessed, $barcode );
2167
2162
2168
        # Simulate item marked as lost
2163
        # Simulate item marked as lost
2169
        ModItem( { itemlost => 3 }, $biblionumber, $item_id );
2164
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
2170
        LostItem( $item_id, 1 );
2165
        LostItem( $item_id, 1 );
2171
2166
2172
        my $processing_fee_lines = Koha::Account::Lines->search(
2167
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2214-2226 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2214
                replacementprice => $replacement_amount,
2209
                replacementprice => $replacement_amount,
2215
                itype            => $item_type->itemtype
2210
                itype            => $item_type->itemtype
2216
            },
2211
            },
2217
            $biblionumber
2212
            $biblio->biblionumber
2218
        );
2213
        );
2219
2214
2220
        AddIssue( $patron->unblessed, $barcode );
2215
        AddIssue( $patron->unblessed, $barcode );
2221
2216
2222
        # Simulate item marked as lost
2217
        # Simulate item marked as lost
2223
        ModItem( { itemlost => 1 }, $biblionumber, $item_id );
2218
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
2224
        LostItem( $item_id, 1 );
2219
        LostItem( $item_id, 1 );
2225
2220
2226
        my $processing_fee_lines = Koha::Account::Lines->search(
2221
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2301-2309 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2301
subtest '_FixOverduesOnReturn' => sub {
2296
subtest '_FixOverduesOnReturn' => sub {
2302
    plan tests => 10;
2297
    plan tests => 10;
2303
2298
2304
    # Generate test biblio
2299
    my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Kylie' });
2305
    my $title  = 'Koha for Dummies';
2306
    my ( $biblionumber, $biblioitemnumber ) = add_biblio($title, 'Hall, Kylie');
2307
2300
2308
    my $barcode = 'KD987654321';
2301
    my $barcode = 'KD987654321';
2309
    my $branchcode  = $library2->{branchcode};
2302
    my $branchcode  = $library2->{branchcode};
Lines 2316-2322 subtest '_FixOverduesOnReturn' => sub { Link Here
2316
            replacementprice => 99.00,
2309
            replacementprice => 99.00,
2317
            itype            => $itemtype
2310
            itype            => $itemtype
2318
        },
2311
        },
2319
        $biblionumber
2312
        $biblio->biblionumber
2320
    );
2313
    );
2321
2314
2322
    my $patron = $builder->build( { source => 'Borrower' } );
2315
    my $patron = $builder->build( { source => 'Borrower' } );
Lines 2785-2813 sub str { Link Here
2785
    return $s;
2778
    return $s;
2786
}
2779
}
2787
2780
2788
sub add_biblio {
2789
    my ($title, $author) = @_;
2790
2791
    my $marcflavour = C4::Context->preference('marcflavour');
2792
2793
    my $biblio = MARC::Record->new();
2794
    if ($title) {
2795
        my $tag = $marcflavour eq 'UNIMARC' ? '200' : '245';
2796
        $biblio->append_fields(
2797
            MARC::Field->new($tag, ' ', ' ', a => $title),
2798
        );
2799
    }
2800
2801
    if ($author) {
2802
        my ($tag, $code) = $marcflavour eq 'UNIMARC' ? (200, 'f') : (100, 'a');
2803
        $biblio->append_fields(
2804
            MARC::Field->new($tag, ' ', ' ', $code => $author),
2805
        );
2806
    }
2807
2808
    return AddBiblio($biblio, '');
2809
}
2810
2811
sub test_debarment_on_checkout {
2781
sub test_debarment_on_checkout {
2812
    my ($params) = @_;
2782
    my ($params) = @_;
2813
    my $item     = $params->{item};
2783
    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 52-61 sub Mock_userenv { Link Here
52
52
53
my $borrowers_count = 3;
53
my $borrowers_count = 3;
54
54
55
# Create a biblio instance
55
my $biblio = $builder->gimme_a_biblio();
56
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
57
58
# Create an item
59
my $item_barcode = 'my_barcode';
56
my $item_barcode = 'my_barcode';
60
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
57
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
61
    {   homebranch    => $branchcode,
58
    {   homebranch    => $branchcode,
Lines 63-69 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( Link Here
63
        barcode       => $item_barcode,
60
        barcode       => $item_barcode,
64
        itype         => $itemtype
61
        itype         => $itemtype
65
    },
62
    },
66
    $bibnum
63
    $biblio->biblionumber,
67
);
64
);
68
65
69
# Create some borrowers
66
# Create some borrowers
Lines 79-98 foreach my $i ( 1 .. $borrowers_count ) { Link Here
79
    push @borrowernumbers, $borrowernumber;
76
    push @borrowernumbers, $borrowernumber;
80
}
77
}
81
78
82
my $biblionumber = $bibnum;
83
84
# Create five item level holds
79
# Create five item level holds
85
foreach my $borrowernumber (@borrowernumbers) {
80
foreach my $borrowernumber (@borrowernumbers) {
86
    AddReserve(
81
    AddReserve(
87
        $branchcode,
82
        $branchcode,
88
        $borrowernumber,
83
        $borrowernumber,
89
        $biblionumber,
84
        $biblio->biblionumber,
90
        my $bibitems   = q{},
85
        my $bibitems   = q{},
91
        my $priority,
86
        my $priority,
92
        my $resdate,
87
        my $resdate,
93
        my $expdate,
88
        my $expdate,
94
        my $notes = q{},
89
        my $notes = q{},
95
        $title,
90
        'a title',
96
        my $checkitem,
91
        my $checkitem,
97
        my $found,
92
        my $found,
98
    );
93
    );
Lines 110-123 ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' ); Link Here
110
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
105
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
111
106
112
$schema->storage->txn_rollback;
107
$schema->storage->txn_rollback;
113
114
# Helper method to set up a Biblio.
115
sub create_helper_biblio {
116
    my $bib   = MARC::Record->new();
117
    my $title = 'Silence in the library';
118
    $bib->append_fields(
119
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
120
        MARC::Field->new( '245', ' ', ' ', a => $title ),
121
    );
122
    return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
123
}
(-)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 955-970 subtest 'Split subfields in Item2Marc (Bug 21774)' => sub { Link Here
955
955
956
    $schema->storage->txn_rollback;
956
    $schema->storage->txn_rollback;
957
};
957
};
958
959
# Helper method to set up a Biblio.
960
sub get_biblio {
961
    my ( $frameworkcode ) = @_;
962
    $frameworkcode //= '';
963
    my $bib = MARC::Record->new();
964
    $bib->append_fields(
965
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
966
        MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
967
    );
968
    my ($bibnum, $bibitemnum) = AddBiblio($bib, $frameworkcode);
969
    return ($bibnum, $bibitemnum);
970
}
(-)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