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

(-)a/t/db_dependent/Circulation.t (-84 / +54 lines)
Lines 213-220 $dbh->do( Link Here
213
# CanBookBeRenewed tests
213
# CanBookBeRenewed tests
214
    C4::Context->set_preference('ItemsDeniedRenewal','');
214
    C4::Context->set_preference('ItemsDeniedRenewal','');
215
    # Generate test biblio
215
    # Generate test biblio
216
    my $title = 'Silence in the library';
216
    my $biblio = $builder->gimme_a_biblio();
217
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
218
217
219
    my $barcode = 'R00000342';
218
    my $barcode = 'R00000342';
220
    my $branch = $library2->{branchcode};
219
    my $branch = $library2->{branchcode};
Lines 227-233 $dbh->do( Link Here
227
            replacementprice => 12.00,
226
            replacementprice => 12.00,
228
            itype            => $itemtype
227
            itype            => $itemtype
229
        },
228
        },
230
        $biblionumber
229
        $biblio->biblionumber
231
    );
230
    );
232
231
233
    my $barcode2 = 'R00000343';
232
    my $barcode2 = 'R00000343';
Lines 239-245 $dbh->do( Link Here
239
            replacementprice => 23.00,
238
            replacementprice => 23.00,
240
            itype            => $itemtype
239
            itype            => $itemtype
241
        },
240
        },
242
        $biblionumber
241
        $biblio->biblionumber
243
    );
242
    );
244
243
245
    my $barcode3 = 'R00000346';
244
    my $barcode3 = 'R00000346';
Lines 251-257 $dbh->do( Link Here
251
            replacementprice => 23.00,
250
            replacementprice => 23.00,
252
            itype            => $itemtype
251
            itype            => $itemtype
253
        },
252
        },
254
        $biblionumber
253
        $biblio->biblionumber
255
    );
254
    );
256
255
257
    # Create borrowers
256
    # Create borrowers
Lines 328-336 $dbh->do( Link Here
328
327
329
    # Biblio-level hold, renewal test
328
    # Biblio-level hold, renewal test
330
    AddReserve(
329
    AddReserve(
331
        $branch, $reserving_borrowernumber, $biblionumber,
330
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
332
        $bibitems,  $priority, $resdate, $expdate, $notes,
331
        $bibitems,  $priority, $resdate, $expdate, $notes,
333
        $title, $checkitem, $found
332
        'a title', $checkitem, $found
334
    );
333
    );
335
334
336
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
335
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
Lines 345-351 $dbh->do( Link Here
345
    my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
344
    my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
346
        {
345
        {
347
            borrowernumber => $hold_waiting_borrowernumber,
346
            borrowernumber => $hold_waiting_borrowernumber,
348
            biblionumber   => $biblionumber,
347
            biblionumber   => $biblio->biblionumber,
349
            itemnumber     => $itemnumber,
348
            itemnumber     => $itemnumber,
350
            branchcode     => $branch,
349
            branchcode     => $branch,
351
            priority       => 3,
350
            priority       => 3,
Lines 360-366 $dbh->do( Link Here
360
    $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
359
    $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     => $itemnumber3,
363
            itemnumber     => $itemnumber3,
365
            branchcode     => $branch,
364
            branchcode     => $branch,
366
            priority       => 0,
365
            priority       => 0,
Lines 381-387 $dbh->do( Link Here
381
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
380
    is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
382
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
381
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
383
382
384
    my $reserveid = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
383
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
385
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
384
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
386
    AddIssue($reserving_borrower, $barcode3);
385
    AddIssue($reserving_borrower, $barcode3);
387
    my $reserve = $dbh->selectrow_hashref(
386
    my $reserve = $dbh->selectrow_hashref(
Lines 393-401 $dbh->do( Link Here
393
392
394
    # Item-level hold, renewal test
393
    # Item-level hold, renewal test
395
    AddReserve(
394
    AddReserve(
396
        $branch, $reserving_borrowernumber, $biblionumber,
395
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
397
        $bibitems,  $priority, $resdate, $expdate, $notes,
396
        $bibitems,  $priority, $resdate, $expdate, $notes,
398
        $title, $itemnumber, $found
397
        'a title', $itemnumber, $found
399
    );
398
    );
400
399
401
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
400
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
Lines 406-415 $dbh->do( Link Here
406
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
405
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
407
406
408
    # Items can't fill hold for reasons
407
    # Items can't fill hold for reasons
409
    ModItem({ notforloan => 1 }, $biblionumber, $itemnumber);
408
    ModItem({ notforloan => 1 }, $biblio->biblionumber, $itemnumber);
410
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
409
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
411
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
410
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
412
    ModItem({ notforloan => 0, itype => $itemtype }, $biblionumber, $itemnumber);
411
    ModItem({ notforloan => 0, itype => $itemtype }, $biblio->biblionumber, $itemnumber);
413
412
414
    # FIXME: Add more for itemtype not for loan etc.
413
    # FIXME: Add more for itemtype not for loan etc.
415
414
Lines 423-429 $dbh->do( Link Here
423
            replacementprice => 23.00,
422
            replacementprice => 23.00,
424
            itype            => $itemtype
423
            itype            => $itemtype
425
        },
424
        },
426
        $biblionumber
425
        $biblio->biblionumber
427
    );
426
    );
428
    my $datedue5 = AddIssue($restricted_borrower, $barcode5);
427
    my $datedue5 = AddIssue($restricted_borrower, $barcode5);
429
    is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
428
    is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
Lines 444-450 $dbh->do( Link Here
444
            replacementprice => 23.00,
443
            replacementprice => 23.00,
445
            itype            => $itemtype
444
            itype            => $itemtype
446
        },
445
        },
447
        $biblionumber
446
        $biblio->biblionumber
448
    );
447
    );
449
448
450
    my $barcode7 = 'R00000349';
449
    my $barcode7 = 'R00000349';
Lines 456-462 $dbh->do( Link Here
456
            replacementprice => 23.00,
455
            replacementprice => 23.00,
457
            itype            => $itemtype
456
            itype            => $itemtype
458
        },
457
        },
459
        $biblionumber
458
        $biblio->biblionumber
460
    );
459
    );
461
    my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
460
    my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
462
    is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
461
    is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
Lines 519-525 $dbh->do( Link Here
519
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
518
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
520
519
521
520
522
    $hold = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next;
521
    $hold = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next;
523
    $hold->cancel;
522
    $hold->cancel;
524
523
525
    # Bug 14101
524
    # Bug 14101
Lines 534-540 $dbh->do( Link Here
534
            replacementprice => 16.00,
533
            replacementprice => 16.00,
535
            itype            => $itemtype
534
            itype            => $itemtype
536
        },
535
        },
537
        $biblionumber
536
        $biblio->biblionumber
538
    );
537
    );
539
538
540
    $issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
539
    $issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
Lines 604-610 $dbh->do( Link Here
604
        my $item_to_auto_renew = $builder->build(
603
        my $item_to_auto_renew = $builder->build(
605
            {   source => 'Item',
604
            {   source => 'Item',
606
                value  => {
605
                value  => {
607
                    biblionumber  => $biblionumber,
606
                    biblionumber  => $biblio->biblionumber,
608
                    homebranch    => $branch,
607
                    homebranch    => $branch,
609
                    holdingbranch => $branch,
608
                    holdingbranch => $branch,
610
                }
609
                }
Lines 663-669 $dbh->do( Link Here
663
        my $item_to_auto_renew = $builder->build({
662
        my $item_to_auto_renew = $builder->build({
664
            source => 'Item',
663
            source => 'Item',
665
            value => {
664
            value => {
666
                biblionumber => $biblionumber,
665
                biblionumber => $biblio->biblionumber,
667
                homebranch       => $branch,
666
                homebranch       => $branch,
668
                holdingbranch    => $branch,
667
                holdingbranch    => $branch,
669
            }
668
            }
Lines 703-709 $dbh->do( Link Here
703
        my $item_to_auto_renew = $builder->build({
702
        my $item_to_auto_renew = $builder->build({
704
            source => 'Item',
703
            source => 'Item',
705
            value => {
704
            value => {
706
                biblionumber => $biblionumber,
705
                biblionumber => $biblio->biblionumber,
707
                homebranch       => $branch,
706
                homebranch       => $branch,
708
                holdingbranch    => $branch,
707
                holdingbranch    => $branch,
709
            }
708
            }
Lines 755-761 $dbh->do( Link Here
755
        my $item_to_auto_renew = $builder->build(
754
        my $item_to_auto_renew = $builder->build(
756
            {   source => 'Item',
755
            {   source => 'Item',
757
                value  => {
756
                value  => {
758
                    biblionumber  => $biblionumber,
757
                    biblionumber  => $biblio->biblionumber,
759
                    homebranch    => $branch,
758
                    homebranch    => $branch,
760
                    holdingbranch => $branch,
759
                    holdingbranch => $branch,
761
                }
760
                }
Lines 907-914 $dbh->do( Link Here
907
    my $branch   = $library2->{branchcode};
906
    my $branch   = $library2->{branchcode};
908
907
909
    #Create another record
908
    #Create another record
910
    my $title2 = 'Something is worng here';
909
    my $biblio2 = $builder->gimme_a_biblio();
911
    my ($biblionumber2, $biblioitemnumber2) = add_biblio($title2, 'Anonymous');
912
910
913
    #Create third item
911
    #Create third item
914
    AddItem(
912
    AddItem(
Lines 918-924 $dbh->do( Link Here
918
            barcode          => $barcode3,
916
            barcode          => $barcode3,
919
            itype            => $itemtype
917
            itype            => $itemtype
920
        },
918
        },
921
        $biblionumber2
919
        $biblio2->biblionumber
922
    );
920
    );
923
921
924
    # Create a borrower
922
    # Create a borrower
Lines 987-993 $dbh->do( Link Here
987
    my $barcode  = '1234567890';
985
    my $barcode  = '1234567890';
988
    my $branch   = $library2->{branchcode};
986
    my $branch   = $library2->{branchcode};
989
987
990
    my ($biblionumber, $biblioitemnumber) = add_biblio();
988
    my $biblio = $builder->gimme_a_biblio();
991
989
992
    #Create third item
990
    #Create third item
993
    my ( undef, undef, $itemnumber ) = AddItem(
991
    my ( undef, undef, $itemnumber ) = AddItem(
Lines 997-1003 $dbh->do( Link Here
997
            barcode          => $barcode,
995
            barcode          => $barcode,
998
            itype            => $itemtype
996
            itype            => $itemtype
999
        },
997
        },
1000
        $biblionumber
998
        $biblio->biblionumber
1001
    );
999
    );
1002
1000
1003
    # Create a borrower
1001
    # Create a borrower
Lines 1044-1050 $dbh->do( Link Here
1044
        undef,  0,
1042
        undef,  0,
1045
        .10, 1
1043
        .10, 1
1046
    );
1044
    );
1047
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
1045
    my $biblio = $builder->gimme_a_biblio();
1048
1046
1049
    my $barcode1 = '1234';
1047
    my $barcode1 = '1234';
1050
    my ( undef, undef, $itemnumber1 ) = AddItem(
1048
    my ( undef, undef, $itemnumber1 ) = AddItem(
Lines 1054-1060 $dbh->do( Link Here
1054
            barcode       => $barcode1,
1052
            barcode       => $barcode1,
1055
            itype         => $itemtype
1053
            itype         => $itemtype
1056
        },
1054
        },
1057
        $biblionumber
1055
        $biblio->biblionumber
1058
    );
1056
    );
1059
    my $barcode2 = '4321';
1057
    my $barcode2 = '4321';
1060
    my ( undef, undef, $itemnumber2 ) = AddItem(
1058
    my ( undef, undef, $itemnumber2 ) = AddItem(
Lines 1064-1070 $dbh->do( Link Here
1064
            barcode       => $barcode2,
1062
            barcode       => $barcode2,
1065
            itype         => $itemtype
1063
            itype         => $itemtype
1066
        },
1064
        },
1067
        $biblionumber
1065
        $biblio->biblionumber
1068
    );
1066
    );
1069
1067
1070
    my $borrowernumber1 = Koha::Patron->new({
1068
    my $borrowernumber1 = Koha::Patron->new({
Lines 1089-1095 $dbh->do( Link Here
1089
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1087
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1090
1088
1091
    AddReserve(
1089
    AddReserve(
1092
        $library2->{branchcode}, $borrowernumber2, $biblionumber,
1090
        $library2->{branchcode}, $borrowernumber2, $biblio->biblionumber,
1093
        '',  1, undef, undef, '',
1091
        '',  1, undef, undef, '',
1094
        undef, undef, undef
1092
        undef, undef, undef
1095
    );
1093
    );
Lines 1115-1121 $dbh->do( Link Here
1115
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1113
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1116
1114
1117
    # Setting item not checked out to be not for loan but holdable
1115
    # Setting item not checked out to be not for loan but holdable
1118
    ModItem({ notforloan => -1 }, $biblionumber, $itemnumber2);
1116
    ModItem({ notforloan => -1 }, $biblio->biblionumber, $itemnumber2);
1119
1117
1120
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1118
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1121
    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' );
1119
    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 1127-1133 $dbh->do( Link Here
1127
    my $branch   = $library->{branchcode};
1125
    my $branch   = $library->{branchcode};
1128
1126
1129
    #Create another record
1127
    #Create another record
1130
    my ($biblionumber, $biblioitemnumber) = add_biblio('A title', 'Anonymous');
1128
    my $biblio = $builder->gimme_a_biblio();
1131
1129
1132
    my (undef, undef, $itemnumber) = AddItem(
1130
    my (undef, undef, $itemnumber) = AddItem(
1133
        {
1131
        {
Lines 1136-1142 $dbh->do( Link Here
1136
            barcode          => $barcode,
1134
            barcode          => $barcode,
1137
            itype            => $itemtype
1135
            itype            => $itemtype
1138
        },
1136
        },
1139
        $biblionumber
1137
        $biblio->biblionumber
1140
    );
1138
    );
1141
1139
1142
    my $borrowernumber = Koha::Patron->new({
1140
    my $borrowernumber = Koha::Patron->new({
Lines 1157-1163 $dbh->do( Link Here
1157
{
1155
{
1158
    my $library = $builder->build({ source => 'Branch' });
1156
    my $library = $builder->build({ source => 'Branch' });
1159
1157
1160
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1158
    my $biblio = $builder->gimme_a_biblio();
1161
1159
1162
    my $barcode = 'just a barcode';
1160
    my $barcode = 'just a barcode';
1163
    my ( undef, undef, $itemnumber ) = AddItem(
1161
    my ( undef, undef, $itemnumber ) = AddItem(
Lines 1167-1173 $dbh->do( Link Here
1167
            barcode          => $barcode,
1165
            barcode          => $barcode,
1168
            itype            => $itemtype
1166
            itype            => $itemtype
1169
        },
1167
        },
1170
        $biblionumber,
1168
        $biblio->biblionumber,
1171
    );
1169
    );
1172
1170
1173
    my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1171
    my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
Lines 1457-1464 subtest 'CanBookBeIssued + Statistic patrons "X"' => sub { Link Here
1457
subtest 'MultipleReserves' => sub {
1455
subtest 'MultipleReserves' => sub {
1458
    plan tests => 3;
1456
    plan tests => 3;
1459
1457
1460
    my $title = 'Silence in the library';
1458
    my $biblio = $builder->gimme_a_biblio();
1461
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
1462
1459
1463
    my $branch = $library2->{branchcode};
1460
    my $branch = $library2->{branchcode};
1464
1461
Lines 1471-1477 subtest 'MultipleReserves' => sub { Link Here
1471
            replacementprice => 12.00,
1468
            replacementprice => 12.00,
1472
            itype            => $itemtype
1469
            itype            => $itemtype
1473
        },
1470
        },
1474
        $biblionumber
1471
        $biblio->biblionumber
1475
    );
1472
    );
1476
1473
1477
    my $barcode2 = 'R00110002';
1474
    my $barcode2 = 'R00110002';
Lines 1483-1489 subtest 'MultipleReserves' => sub { Link Here
1483
            replacementprice => 12.00,
1480
            replacementprice => 12.00,
1484
            itype            => $itemtype
1481
            itype            => $itemtype
1485
        },
1482
        },
1486
        $biblionumber
1483
        $biblio->biblionumber
1487
    );
1484
    );
1488
1485
1489
    my $bibitems       = '';
1486
    my $bibitems       = '';
Lines 1515-1523 subtest 'MultipleReserves' => sub { Link Here
1515
    );
1512
    );
1516
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1513
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1517
    AddReserve(
1514
    AddReserve(
1518
        $branch, $reserving_borrowernumber1, $biblionumber,
1515
        $branch, $reserving_borrowernumber1, $biblio->biblionumber,
1519
        $bibitems,  $priority, $resdate, $expdate, $notes,
1516
        $bibitems,  $priority, $resdate, $expdate, $notes,
1520
        $title, $checkitem, $found
1517
        'a title', $checkitem, $found
1521
    );
1518
    );
1522
1519
1523
    my %reserving_borrower_data2 = (
1520
    my %reserving_borrower_data2 = (
Lines 1528-1536 subtest 'MultipleReserves' => sub { Link Here
1528
    );
1525
    );
1529
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1526
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1530
    AddReserve(
1527
    AddReserve(
1531
        $branch, $reserving_borrowernumber2, $biblionumber,
1528
        $branch, $reserving_borrowernumber2, $biblio->biblionumber,
1532
        $bibitems,  $priority, $resdate, $expdate, $notes,
1529
        $bibitems,  $priority, $resdate, $expdate, $notes,
1533
        $title, $checkitem, $found
1530
        'a title', $checkitem, $found
1534
    );
1531
    );
1535
1532
1536
    {
1533
    {
Lines 1547-1553 subtest 'MultipleReserves' => sub { Link Here
1547
            replacementprice => 12.00,
1544
            replacementprice => 12.00,
1548
            itype            => $itemtype
1545
            itype            => $itemtype
1549
        },
1546
        },
1550
        $biblionumber
1547
        $biblio->biblionumber
1551
    );
1548
    );
1552
1549
1553
    {
1550
    {
Lines 1995-2003 subtest '_FixAccountForLostAndReturned' => sub { Link Here
1995
    );
1992
    );
1996
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1993
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1997
1994
1998
    # Generate test biblio
1995
    my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Daria' });
1999
    my $title = 'Koha for Dummies';
2000
    my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, 'Hall, Daria' );
2001
1996
2002
    subtest 'Full write-off tests' => sub {
1997
    subtest 'Full write-off tests' => sub {
2003
1998
Lines 2013-2025 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2013
                replacementprice => $replacement_amount,
2008
                replacementprice => $replacement_amount,
2014
                itype            => $item_type->itemtype
2009
                itype            => $item_type->itemtype
2015
            },
2010
            },
2016
            $biblionumber
2011
            $biblio->biblionumber
2017
        );
2012
        );
2018
2013
2019
        AddIssue( $patron->unblessed, $barcode );
2014
        AddIssue( $patron->unblessed, $barcode );
2020
2015
2021
        # Simulate item marked as lost
2016
        # Simulate item marked as lost
2022
        ModItem( { itemlost => 3 }, $biblionumber, $item_id );
2017
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
2023
        LostItem( $item_id, 1 );
2018
        LostItem( $item_id, 1 );
2024
2019
2025
        my $processing_fee_lines = Koha::Account::Lines->search(
2020
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2075-2087 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2075
                replacementprice => $replacement_amount,
2070
                replacementprice => $replacement_amount,
2076
                itype            => $item_type->itemtype
2071
                itype            => $item_type->itemtype
2077
            },
2072
            },
2078
            $biblionumber
2073
            $biblio->biblionumber
2079
        );
2074
        );
2080
2075
2081
        AddIssue( $patron->unblessed, $barcode );
2076
        AddIssue( $patron->unblessed, $barcode );
2082
2077
2083
        # Simulate item marked as lost
2078
        # Simulate item marked as lost
2084
        ModItem( { itemlost => 1 }, $biblionumber, $item_id );
2079
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
2085
        LostItem( $item_id, 1 );
2080
        LostItem( $item_id, 1 );
2086
2081
2087
        my $processing_fee_lines = Koha::Account::Lines->search(
2082
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2144-2156 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2144
                replacementprice => $replacement_amount,
2139
                replacementprice => $replacement_amount,
2145
                itype            => $item_type->itemtype
2140
                itype            => $item_type->itemtype
2146
            },
2141
            },
2147
            $biblionumber
2142
            $biblio->biblionumber
2148
        );
2143
        );
2149
2144
2150
        AddIssue( $patron->unblessed, $barcode );
2145
        AddIssue( $patron->unblessed, $barcode );
2151
2146
2152
        # Simulate item marked as lost
2147
        # Simulate item marked as lost
2153
        ModItem( { itemlost => 3 }, $biblionumber, $item_id );
2148
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item_id );
2154
        LostItem( $item_id, 1 );
2149
        LostItem( $item_id, 1 );
2155
2150
2156
        my $processing_fee_lines = Koha::Account::Lines->search(
2151
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2198-2210 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2198
                replacementprice => $replacement_amount,
2193
                replacementprice => $replacement_amount,
2199
                itype            => $item_type->itemtype
2194
                itype            => $item_type->itemtype
2200
            },
2195
            },
2201
            $biblionumber
2196
            $biblio->biblionumber
2202
        );
2197
        );
2203
2198
2204
        AddIssue( $patron->unblessed, $barcode );
2199
        AddIssue( $patron->unblessed, $barcode );
2205
2200
2206
        # Simulate item marked as lost
2201
        # Simulate item marked as lost
2207
        ModItem( { itemlost => 1 }, $biblionumber, $item_id );
2202
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
2208
        LostItem( $item_id, 1 );
2203
        LostItem( $item_id, 1 );
2209
2204
2210
        my $processing_fee_lines = Koha::Account::Lines->search(
2205
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2362-2370 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2362
subtest '_FixOverduesOnReturn' => sub {
2357
subtest '_FixOverduesOnReturn' => sub {
2363
    plan tests => 10;
2358
    plan tests => 10;
2364
2359
2365
    # Generate test biblio
2360
    my $biblio = $builder->gimme_a_biblio({ author => 'Hall, Kylie' });
2366
    my $title  = 'Koha for Dummies';
2367
    my ( $biblionumber, $biblioitemnumber ) = add_biblio($title, 'Hall, Kylie');
2368
2361
2369
    my $barcode = 'KD987654321';
2362
    my $barcode = 'KD987654321';
2370
    my $branchcode  = $library2->{branchcode};
2363
    my $branchcode  = $library2->{branchcode};
Lines 2377-2383 subtest '_FixOverduesOnReturn' => sub { Link Here
2377
            replacementprice => 99.00,
2370
            replacementprice => 99.00,
2378
            itype            => $itemtype
2371
            itype            => $itemtype
2379
        },
2372
        },
2380
        $biblionumber
2373
        $biblio->biblionumber
2381
    );
2374
    );
2382
2375
2383
    my $patron = $builder->build( { source => 'Borrower' } );
2376
    my $patron = $builder->build( { source => 'Borrower' } );
Lines 3009-3037 sub str { Link Here
3009
    return $s;
3002
    return $s;
3010
}
3003
}
3011
3004
3012
sub add_biblio {
3013
    my ($title, $author) = @_;
3014
3015
    my $marcflavour = C4::Context->preference('marcflavour');
3016
3017
    my $biblio = MARC::Record->new();
3018
    if ($title) {
3019
        my $tag = $marcflavour eq 'UNIMARC' ? '200' : '245';
3020
        $biblio->append_fields(
3021
            MARC::Field->new($tag, ' ', ' ', a => $title),
3022
        );
3023
    }
3024
3025
    if ($author) {
3026
        my ($tag, $code) = $marcflavour eq 'UNIMARC' ? (200, 'f') : (100, 'a');
3027
        $biblio->append_fields(
3028
            MARC::Field->new($tag, ' ', ' ', $code => $author),
3029
        );
3030
    }
3031
3032
    return AddBiblio($biblio, '');
3033
}
3034
3035
sub test_debarment_on_checkout {
3005
sub test_debarment_on_checkout {
3036
    my ($params) = @_;
3006
    my ($params) = @_;
3037
    my $item     = $params->{item};
3007
    my $item     = $params->{item};
(-)a/t/db_dependent/Holds.t (-65 / +48 lines)
Lines 54-65 $insert_sth->execute('DUMMY'); Link Here
54
$insert_sth->execute('ONLY1');
54
$insert_sth->execute('ONLY1');
55
55
56
# Setup Test------------------------
56
# Setup Test------------------------
57
# Create a biblio instance for testing
57
my $biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
58
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
59
58
60
# Create item instance for testing.
59
# Create item instance for testing.
61
my ($item_bibnum, $item_bibitemnum, $itemnumber)
60
my ($item_bibnum, $item_bibitemnum, $itemnumber)
62
    = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
61
    = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
63
62
64
# Create some borrowers
63
# Create some borrowers
65
my @borrowernumbers;
64
my @borrowernumbers;
Lines 73-98 foreach (1..$borrowers_count) { Link Here
73
    push @borrowernumbers, $borrowernumber;
72
    push @borrowernumbers, $borrowernumber;
74
}
73
}
75
74
76
my $biblionumber = $bibnum;
77
78
# Create five item level holds
75
# Create five item level holds
79
foreach my $borrowernumber ( @borrowernumbers ) {
76
foreach my $borrowernumber ( @borrowernumbers ) {
80
    AddReserve(
77
    AddReserve(
81
        $branch_1,
78
        $branch_1,
82
        $borrowernumber,
79
        $borrowernumber,
83
        $biblionumber,
80
        $biblio->biblionumber,
84
        my $bibitems = q{},
81
        my $bibitems = q{},
85
        my $priority = C4::Reserves::CalculatePriority( $biblionumber ),
82
        my $priority = C4::Reserves::CalculatePriority( $biblio->biblionumber ),
86
        my $resdate,
83
        my $resdate,
87
        my $expdate,
84
        my $expdate,
88
        my $notes = q{},
85
        my $notes = q{},
89
        $title,
86
        'a title',
90
        my $checkitem = $itemnumber,
87
        my $checkitem = $itemnumber,
91
        my $found,
88
        my $found,
92
    );
89
    );
93
}
90
}
94
91
95
my $biblio = Koha::Biblios->find( $biblionumber );
96
my $holds = $biblio->holds;
92
my $holds = $biblio->holds;
97
is( $holds->count, $borrowers_count, 'Test GetReserves()' );
93
is( $holds->count, $borrowers_count, 'Test GetReserves()' );
98
is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
94
is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
Lines 176-182 ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" ); Link Here
176
172
177
SuspendAll(
173
SuspendAll(
178
    borrowernumber => $borrowernumber,
174
    borrowernumber => $borrowernumber,
179
    biblionumber   => $biblionumber,
175
    biblionumber   => $biblio->biblionumber,
180
    suspend => 1,
176
    suspend => 1,
181
    suspend_until => '2012-01-01',
177
    suspend_until => '2012-01-01',
182
);
178
);
Lines 186-192 is( $hold->suspend_until, '2012-01-01 00:00:00', "Test SuspendAll(), with date" Link Here
186
182
187
SuspendAll(
183
SuspendAll(
188
    borrowernumber => $borrowernumber,
184
    borrowernumber => $borrowernumber,
189
    biblionumber   => $biblionumber,
185
    biblionumber   => $biblio->biblionumber,
190
    suspend => 0,
186
    suspend => 0,
191
);
187
);
192
$hold = Koha::Holds->find( $reserve_id );
188
$hold = Koha::Holds->find( $reserve_id );
Lines 197-215 is( $hold->suspend_until, undef, "Test resuming with SuspendAll(), should have n Link Here
197
AddReserve(
193
AddReserve(
198
    $branch_1,
194
    $branch_1,
199
    $borrowernumbers[0],
195
    $borrowernumbers[0],
200
    $biblionumber,
196
    $biblio->biblionumber,
201
    my $bibitems = q{},
197
    my $bibitems = q{},
202
    my $priority,
198
    my $priority,
203
    my $resdate,
199
    my $resdate,
204
    my $expdate,
200
    my $expdate,
205
    my $notes = q{},
201
    my $notes = q{},
206
    $title,
202
    'a title',
207
    my $checkitem,
203
    my $checkitem,
208
    my $found,
204
    my $found,
209
);
205
);
210
$patron = Koha::Patrons->find( $borrowernumber );
206
$patron = Koha::Patrons->find( $borrowernumber );
211
$holds = $patron->holds;
207
$holds = $patron->holds;
212
my $reserveid = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
208
my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
213
ModReserveMinusPriority( $itemnumber, $reserveid );
209
ModReserveMinusPriority( $itemnumber, $reserveid );
214
$holds = $patron->holds;
210
$holds = $patron->holds;
215
is( $holds->next->itemnumber, $itemnumber, "Test ModReserveMinusPriority()" );
211
is( $holds->next->itemnumber, $itemnumber, "Test ModReserveMinusPriority()" );
Lines 243-251 is( $hold->priority, '6', "Test AlterPriority(), move to bottom" ); Link Here
243
# Note that canreservefromotherbranches has no effect if
239
# Note that canreservefromotherbranches has no effect if
244
# IndependentBranches is OFF.
240
# IndependentBranches is OFF.
245
241
246
my ($foreign_bibnum, $foreign_title, $foreign_bibitemnum) = create_helper_biblio('DUMMY');
242
my $foreign_biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
247
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
243
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
248
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_bibnum);
244
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
249
$dbh->do('DELETE FROM issuingrules');
245
$dbh->do('DELETE FROM issuingrules');
250
$dbh->do(
246
$dbh->do(
251
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
247
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 288-301 ok( Link Here
288
284
289
{
285
{
290
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
286
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
291
    ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
287
    $biblio = $builder->gimme_a_biblio({ itemtype => 'DUMMY' });
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 $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $bibnum, '', 1);
289
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
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 $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $bibnum, '', 2);
291
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
296
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
292
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
297
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $bibnum, '', 3);
293
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
298
    my $hhh = Koha::Holds->search({ biblionumber => $bibnum });
294
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
299
    my $hold3 = Koha::Holds->find( $reserveid3 );
295
    my $hold3 = Koha::Holds->find( $reserveid3 );
300
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
296
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
301
    ModReserve({ reserve_id => $reserveid1, rank => 'del' });
297
    ModReserve({ reserve_id => $reserveid1, rank => 'del' });
Lines 325-336 ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', Link Here
325
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
321
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
326
322
327
# Regression test for bug 9532
323
# Regression test for bug 9532
328
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
324
$biblio = $builder->gimme_a_biblio({ itemtype => 'CANNOT' });
329
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
325
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
330
AddReserve(
326
AddReserve(
331
    $branch_1,
327
    $branch_1,
332
    $borrowernumbers[0],
328
    $borrowernumbers[0],
333
    $bibnum,
329
    $biblio->biblionumber,
334
    '',
330
    '',
335
    1,
331
    1,
336
);
332
);
Lines 373-392 $dbh->do(q{ Link Here
373
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
369
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
374
    VALUES (?, ?, ?, ?)
370
    VALUES (?, ?, ?, ?)
375
}, {}, $branch_1, 'CAN', 1, 'homebranch');
371
}, {}, $branch_1, 'CAN', 1, 'homebranch');
376
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
372
$biblio = $builder->gimme_a_biblio({ itemtype => 'CANNOT' });
377
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
373
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
378
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
374
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
379
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
375
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
380
    "CanItemBeReserved should return 'notReservable'");
376
    "CanItemBeReserved should return 'notReservable'");
381
377
382
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
378
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
383
    { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
379
    { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
384
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
380
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
385
    'cannotReserveFromOtherBranches',
381
    'cannotReserveFromOtherBranches',
386
    "CanItemBeReserved should return 'cannotReserveFromOtherBranches'");
382
    "CanItemBeReserved should return 'cannotReserveFromOtherBranches'");
387
383
388
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
384
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
389
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
385
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
390
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
386
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
391
    "CanItemBeReserved should return 'OK'");
387
    "CanItemBeReserved should return 'OK'");
392
388
Lines 399-407 $dbh->do('DELETE FROM issues'); Link Here
399
$dbh->do('DELETE FROM items');
395
$dbh->do('DELETE FROM items');
400
$dbh->do('DELETE FROM biblio');
396
$dbh->do('DELETE FROM biblio');
401
397
402
( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
398
$biblio = $builder->gimme_a_biblio({ itemtype => 'ONLY1' });
403
( $item_bibnum, $item_bibitemnum, $itemnumber )
399
( $item_bibnum, $item_bibitemnum, $itemnumber )
404
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
400
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
405
401
406
$dbh->do(
402
$dbh->do(
407
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
403
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 412-418 $dbh->do( Link Here
412
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
408
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
413
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
409
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
414
410
415
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
411
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
416
412
417
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
413
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
418
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
414
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
Lines 424-433 subtest 'Test max_holds per library/patron category' => sub { Link Here
424
    $dbh->do('DELETE FROM issuingrules');
420
    $dbh->do('DELETE FROM issuingrules');
425
    $dbh->do('DELETE FROM circulation_rules');
421
    $dbh->do('DELETE FROM circulation_rules');
426
422
427
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
423
    $biblio = $builder->gimme_a_biblio({ itemtype => 'TEST' });
428
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
424
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
429
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
425
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
430
        $bibnum );
426
        $biblio->biblionumber );
431
    $dbh->do(
427
    $dbh->do(
432
        q{
428
        q{
433
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
429
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 436-444 subtest 'Test max_holds per library/patron category' => sub { Link Here
436
        {},
432
        {},
437
        '*', '*', 'TEST', 99, 99
433
        '*', '*', 'TEST', 99, 99
438
    );
434
    );
439
    AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
435
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
440
    AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
436
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
441
    AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
437
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
442
438
443
    my $count =
439
    my $count =
444
      Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
440
      Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
Lines 494-502 subtest 'Test max_holds per library/patron category' => sub { Link Here
494
subtest 'Pickup location availability tests' => sub {
490
subtest 'Pickup location availability tests' => sub {
495
    plan tests => 4;
491
    plan tests => 4;
496
492
497
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
493
    $biblio = $builder->gimme_a_biblio({ itemtype => 'ONLY1' });
498
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
494
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
499
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
495
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
500
    #Add a default rule to allow some holds
496
    #Add a default rule to allow some holds
501
    $dbh->do(
497
    $dbh->do(
502
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
498
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 551-576 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
551
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
547
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
552
548
553
    # Create 3 biblios with items
549
    # Create 3 biblios with items
554
    my ($bibnum_1) = create_helper_biblio( $itemtype->itemtype );
550
    my $biblio_1 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
555
    my ( undef, undef, $itemnumber_1 ) = AddItem(
551
    my ( undef, undef, $itemnumber_1 ) = AddItem(
556
        {   homebranch    => $library->branchcode,
552
        {   homebranch    => $library->branchcode,
557
            holdingbranch => $library->branchcode
553
            holdingbranch => $library->branchcode
558
        },
554
        },
559
        $bibnum
555
        $biblio_1->biblionumber
560
    );
556
    );
561
    my ($bibnum_2) = create_helper_biblio( $itemtype->itemtype );
557
    my $biblio_2 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
562
    my ( undef, undef, $itemnumber_2 ) = AddItem(
558
    my ( undef, undef, $itemnumber_2 ) = AddItem(
563
        {   homebranch    => $library->branchcode,
559
        {   homebranch    => $library->branchcode,
564
            holdingbranch => $library->branchcode
560
            holdingbranch => $library->branchcode
565
        },
561
        },
566
        $bibnum_2
562
        $biblio_2->biblionumber
567
    );
563
    );
568
    my ($bibnum_3) = create_helper_biblio( $itemtype->itemtype );
564
    my $biblio_3 = $builder->gimme_a_biblio({ itemtype => $itemtype->itemtype });
569
    my ( undef, undef, $itemnumber_3 ) = AddItem(
565
    my ( undef, undef, $itemnumber_3 ) = AddItem(
570
        {   homebranch    => $library->branchcode,
566
        {   homebranch    => $library->branchcode,
571
            holdingbranch => $library->branchcode
567
            holdingbranch => $library->branchcode
572
        },
568
        },
573
        $bibnum_3
569
        $biblio_3->biblionumber
574
    );
570
    );
575
571
576
    Koha::IssuingRules->search->delete;
572
    Koha::IssuingRules->search->delete;
Lines 590-596 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
590
        'Patron can reserve item with hold limit of 1, no holds placed'
586
        'Patron can reserve item with hold limit of 1, no holds placed'
591
    );
587
    );
592
588
593
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, );
589
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
594
590
595
    is_deeply(
591
    is_deeply(
596
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ),
592
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ),
Lines 608-614 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
608
    );
604
    );
609
605
610
    # Add a second reserve
606
    # Add a second reserve
611
    my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, );
607
    my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
612
    is_deeply(
608
    is_deeply(
613
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
609
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
614
        { status => 'tooManyReservesToday', limit => 2 },
610
        { status => 'tooManyReservesToday', limit => 2 },
Lines 644-657 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
644
        { status => 'OK' },
640
        { status => 'OK' },
645
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
641
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
646
    );
642
    );
647
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, );
643
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
648
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, );
644
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
649
    is_deeply(
645
    is_deeply(
650
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
646
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
651
        { status => 'OK' },
647
        { status => 'OK' },
652
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
648
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
653
    );
649
    );
654
    AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_3, '', 1, );
650
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_3->biblionumber, '', 1, );
655
    is_deeply(
651
    is_deeply(
656
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
652
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
657
        { status => 'tooManyReserves', limit => 3 },
653
        { status => 'tooManyReserves', limit => 3 },
Lines 660-675 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
660
656
661
    $schema->storage->txn_rollback;
657
    $schema->storage->txn_rollback;
662
};
658
};
663
664
# Helper method to set up a Biblio.
665
sub create_helper_biblio {
666
    my $itemtype = shift;
667
    my $bib = MARC::Record->new();
668
    my $title = 'Silence in the library';
669
    $bib->append_fields(
670
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
671
        MARC::Field->new('245', ' ', ' ', a => $title),
672
        MARC::Field->new('942', ' ', ' ', c => $itemtype),
673
    );
674
    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
675
}
(-)a/t/db_dependent/Holds/LocalHoldsPriority.t (-19 / +4 lines)
Lines 40-54 my $itemtype = $builder->build( Link Here
40
40
41
my $borrowers_count = 5;
41
my $borrowers_count = 5;
42
42
43
# Create a helper biblio
43
my $biblio = $builder->gimme_a_biblio();
44
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
45
# Create a helper item for the biblio.
46
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
44
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
47
    {   homebranch    => $library4->{branchcode},
45
    {   homebranch    => $library4->{branchcode},
48
        holdingbranch => $library3->{branchcode},
46
        holdingbranch => $library3->{branchcode},
49
        itype         => $itemtype
47
        itype         => $itemtype
50
    },
48
    },
51
    $bibnum
49
    $biblio->biblionumber,
52
);
50
);
53
51
54
52
Lines 67-87 foreach ( 1 .. $borrowers_count ) { Link Here
67
    push @borrowernumbers, $borrowernumber;
65
    push @borrowernumbers, $borrowernumber;
68
}
66
}
69
67
70
my $biblionumber = $bibnum;
71
72
# Create five item level holds
68
# Create five item level holds
73
my $i = 1;
69
my $i = 1;
74
foreach my $borrowernumber (@borrowernumbers) {
70
foreach my $borrowernumber (@borrowernumbers) {
75
    AddReserve(
71
    AddReserve(
76
        $branchcodes[$i],
72
        $branchcodes[$i],
77
        $borrowernumber,
73
        $borrowernumber,
78
        $biblionumber,
74
        $biblio->biblionumber,
79
        my $bibitems   = q{},
75
        my $bibitems   = q{},
80
        my $priority = $i,
76
        my $priority = $i,
81
        my $resdate,
77
        my $resdate,
82
        my $expdate,
78
        my $expdate,
83
        my $notes = q{},
79
        my $notes = q{},
84
        $title,
80
        'a title',
85
        my $checkitem,
81
        my $checkitem,
86
        my $found,
82
        my $found,
87
    );
83
    );
Lines 116-129 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' Link Here
116
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
112
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
117
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
113
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
118
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
114
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
119
120
# Helper method to set up a Biblio.
121
sub create_helper_biblio {
122
    my $bib   = MARC::Record->new();
123
    my $title = 'Silence in the library';
124
    $bib->append_fields(
125
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
126
        MARC::Field->new( '245', ' ', ' ', a => $title ),
127
    );
128
    return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
129
}
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-20 / +4 lines)
Lines 46-55 t::lib::Mocks::mock_userenv({ flags => 1, userid => '1', branchcode => $branchco Link Here
46
46
47
my $borrowers_count = 3;
47
my $borrowers_count = 3;
48
48
49
# Create a biblio instance
49
my $biblio = $builder->gimme_a_biblio();
50
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
51
52
# Create an item
53
my $item_barcode = 'my_barcode';
50
my $item_barcode = 'my_barcode';
54
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
51
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
55
    {   homebranch    => $branchcode,
52
    {   homebranch    => $branchcode,
Lines 57-63 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( Link Here
57
        barcode       => $item_barcode,
54
        barcode       => $item_barcode,
58
        itype         => $itemtype
55
        itype         => $itemtype
59
    },
56
    },
60
    $bibnum
57
    $biblio->biblionumber,
61
);
58
);
62
59
63
# Create some borrowers
60
# Create some borrowers
Lines 73-92 foreach my $i ( 1 .. $borrowers_count ) { Link Here
73
    push @borrowernumbers, $borrowernumber;
70
    push @borrowernumbers, $borrowernumber;
74
}
71
}
75
72
76
my $biblionumber = $bibnum;
77
78
# Create five item level holds
73
# Create five item level holds
79
foreach my $borrowernumber (@borrowernumbers) {
74
foreach my $borrowernumber (@borrowernumbers) {
80
    AddReserve(
75
    AddReserve(
81
        $branchcode,
76
        $branchcode,
82
        $borrowernumber,
77
        $borrowernumber,
83
        $biblionumber,
78
        $biblio->biblionumber,
84
        my $bibitems   = q{},
79
        my $bibitems   = q{},
85
        my $priority,
80
        my $priority,
86
        my $resdate,
81
        my $resdate,
87
        my $expdate,
82
        my $expdate,
88
        my $notes = q{},
83
        my $notes = q{},
89
        $title,
84
        'a title',
90
        my $checkitem,
85
        my $checkitem,
91
        my $found,
86
        my $found,
92
    );
87
    );
Lines 104-117 ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' ); Link Here
104
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
99
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
105
100
106
$schema->storage->txn_rollback;
101
$schema->storage->txn_rollback;
107
108
# Helper method to set up a Biblio.
109
sub create_helper_biblio {
110
    my $bib   = MARC::Record->new();
111
    my $title = 'Silence in the library';
112
    $bib->append_fields(
113
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
114
        MARC::Field->new( '245', ' ', ' ', a => $title ),
115
    );
116
    return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
117
}
(-)a/t/db_dependent/Items.t (-56 / +43 lines)
Lines 56-67 subtest 'General Add, Get and Del tests' => sub { Link Here
56
56
57
    # Create a biblio instance for testing
57
    # Create a biblio instance for testing
58
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
58
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
59
    my ($bibnum, $bibitemnum) = get_biblio();
59
    my $biblio = $builder->gimme_a_biblio();
60
60
61
    # Add an item.
61
    # Add an item.
62
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
62
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
63
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
63
    cmp_ok($item_bibnum, '==', $biblio->biblionumber, "New item is linked to correct biblionumber.");
64
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
64
    cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
65
65
66
    # Get item.
66
    # Get item.
67
    my $getitem = GetItem($itemnumber);
67
    my $getitem = GetItem($itemnumber);
Lines 74-102 subtest 'General Add, Get and Del tests' => sub { Link Here
74
    # Do not modify anything, and do not explode!
74
    # Do not modify anything, and do not explode!
75
    my $dbh = C4::Context->dbh;
75
    my $dbh = C4::Context->dbh;
76
    local $dbh->{RaiseError} = 1;
76
    local $dbh->{RaiseError} = 1;
77
    ModItem({}, $bibnum, $itemnumber);
77
    ModItem({}, $biblio->biblionumber, $itemnumber);
78
78
79
    # Modify item; setting barcode.
79
    # Modify item; setting barcode.
80
    ModItem({ barcode => '987654321' }, $bibnum, $itemnumber);
80
    ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber);
81
    my $moditem = GetItem($itemnumber);
81
    my $moditem = GetItem($itemnumber);
82
    cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
82
    cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
83
83
84
    # Delete item.
84
    # Delete item.
85
    DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber });
85
    DelItem({ biblionumber => $biblio->biblionumber, itemnumber => $itemnumber });
86
    my $getdeleted = GetItem($itemnumber);
86
    my $getdeleted = GetItem($itemnumber);
87
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
87
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
88
88
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum);
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
90
    $getitem = GetItem($itemnumber);
90
    $getitem = GetItem($itemnumber);
91
    is( $getitem->{location}, $location, "The location should not have been modified" );
91
    is( $getitem->{location}, $location, "The location should not have been modified" );
92
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
92
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
93
93
94
    ModItem({ location => $location }, $bibnum, $itemnumber);
94
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
95
    $getitem = GetItem($itemnumber);
95
    $getitem = GetItem($itemnumber);
96
    is( $getitem->{location}, $location, "The location should have been set to correct location" );
96
    is( $getitem->{location}, $location, "The location should have been set to correct location" );
97
    is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
97
    is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
98
98
99
    ModItem({ location => 'CART' }, $bibnum, $itemnumber);
99
    ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber);
100
    $getitem = GetItem($itemnumber);
100
    $getitem = GetItem($itemnumber);
101
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
101
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
102
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
102
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
Lines 168-174 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
168
168
169
    # Create a new biblio
169
    # Create a new biblio
170
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
170
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
171
    my ($biblionumber, $biblioitemnumber) = get_biblio();
171
    my $biblio = $builder->gimme_a_biblio();
172
172
173
    # Add two items
173
    # Add two items
174
    my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
174
    my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
Lines 178-184 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
178
            withdrawn     => 1,
178
            withdrawn     => 1,
179
            itype         => $itemtype->{itemtype},
179
            itype         => $itemtype->{itemtype},
180
        },
180
        },
181
        $biblionumber
181
        $biblio->biblionumber
182
    );
182
    );
183
    my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
183
    my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
184
        {
184
        {
Lines 187-193 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
187
            withdrawn     => 0,
187
            withdrawn     => 0,
188
            itype         => $itemtype->{itemtype},
188
            itype         => $itemtype->{itemtype},
189
        },
189
        },
190
        $biblionumber
190
        $biblio->biblionumber
191
    );
191
    );
192
192
193
    my $opachiddenitems;
193
    my $opachiddenitems;
Lines 266-272 subtest 'GetItemsInfo tests' => sub { Link Here
266
    });
266
    });
267
267
268
    # Add a biblio
268
    # Add a biblio
269
    my ($biblionumber, $biblioitemnumber) = get_biblio();
269
    my $biblio = $builder->gimme_a_biblio();
270
    # Add an item
270
    # Add an item
271
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
271
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
272
        {
272
        {
Lines 274-280 subtest 'GetItemsInfo tests' => sub { Link Here
274
            holdingbranch => $library2->{branchcode},
274
            holdingbranch => $library2->{branchcode},
275
            itype         => $itemtype->{itemtype},
275
            itype         => $itemtype->{itemtype},
276
        },
276
        },
277
        $biblionumber
277
        $biblio->biblionumber
278
    );
278
    );
279
279
280
    my $library = Koha::Libraries->find( $library1->{branchcode} );
280
    my $library = Koha::Libraries->find( $library1->{branchcode} );
Lines 285-291 subtest 'GetItemsInfo tests' => sub { Link Here
285
    $library->opac_info("holdingbranch OPAC info");
285
    $library->opac_info("holdingbranch OPAC info");
286
    $library->store;
286
    $library->store;
287
287
288
    my @results = GetItemsInfo( $biblionumber );
288
    my @results = GetItemsInfo( $biblio->biblionumber );
289
    ok( @results, 'GetItemsInfo returns results');
289
    ok( @results, 'GetItemsInfo returns results');
290
    is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info",
290
    is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info",
291
        'GetItemsInfo returns the correct home branch OPAC info notice' );
291
        'GetItemsInfo returns the correct home branch OPAC info notice' );
Lines 357-363 subtest 'SearchItems test' => sub { Link Here
357
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
357
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
358
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
358
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
359
359
360
    my ($biblionumber) = get_biblio();
360
    my $biblio = $builder->gimme_a_biblio();
361
361
362
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
362
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
363
363
Lines 366-377 subtest 'SearchItems test' => sub { Link Here
366
        homebranch => $library1->{branchcode},
366
        homebranch => $library1->{branchcode},
367
        holdingbranch => $library1->{branchcode},
367
        holdingbranch => $library1->{branchcode},
368
        itype => $itemtype->{itemtype},
368
        itype => $itemtype->{itemtype},
369
    }, $biblionumber);
369
    }, $biblio->biblionumber);
370
    my (undef, undef, $item2_itemnumber) = AddItem({
370
    my (undef, undef, $item2_itemnumber) = AddItem({
371
        homebranch => $library2->{branchcode},
371
        homebranch => $library2->{branchcode},
372
        holdingbranch => $library2->{branchcode},
372
        holdingbranch => $library2->{branchcode},
373
        itype => $itemtype->{itemtype},
373
        itype => $itemtype->{itemtype},
374
    }, $biblionumber);
374
    }, $biblio->biblionumber);
375
375
376
    my ($items, $total_results);
376
    my ($items, $total_results);
377
377
Lines 476-482 subtest 'SearchItems test' => sub { Link Here
476
        )
476
        )
477
    );
477
    );
478
    my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record,
478
    my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record,
479
        $biblionumber);
479
        $biblio->biblionumber);
480
480
481
    # Search item where item subfield z is "foobar"
481
    # Search item where item subfield z is "foobar"
482
    $filter = {
482
    $filter = {
Lines 498-504 subtest 'SearchItems test' => sub { Link Here
498
    $cache->clear_from_cache("default_value_for_mod_marc-");
498
    $cache->clear_from_cache("default_value_for_mod_marc-");
499
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
499
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
500
500
501
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
501
    ModItemFromMarc($item3_record, $biblio->biblionumber, $item3_itemnumber);
502
502
503
    # Make sure the link is used
503
    # Make sure the link is used
504
    my $item3 = GetItem($item3_itemnumber);
504
    my $item3 = GetItem($item3_itemnumber);
Lines 534-547 subtest 'Koha::Item(s) tests' => sub { Link Here
534
534
535
    # Create a biblio and item for testing
535
    # Create a biblio and item for testing
536
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
536
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
537
    my ($bibnum, $bibitemnum) = get_biblio();
537
    my $biblio = $builder->gimme_a_biblio();
538
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
538
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
539
        {
539
        {
540
            homebranch    => $library1->{branchcode},
540
            homebranch    => $library1->{branchcode},
541
            holdingbranch => $library2->{branchcode},
541
            holdingbranch => $library2->{branchcode},
542
            itype         => $itemtype->{itemtype},
542
            itype         => $itemtype->{itemtype},
543
        },
543
        },
544
        $bibnum
544
        $biblio->biblionumber
545
    );
545
    );
546
546
547
    # Get item.
547
    # Get item.
Lines 575-581 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
575
        source => 'Itemtype',
575
        source => 'Itemtype',
576
    });
576
    });
577
577
578
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
578
    my $biblio = $builder->gimme_a_biblio();
579
    my $item_infos = [
579
    my $item_infos = [
580
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
580
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
581
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
581
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
Lines 598-604 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
598
                holdingbranch => $item_info->{holdingbanch},
598
                holdingbranch => $item_info->{holdingbanch},
599
                itype         => $itemtype->{itemtype},
599
                itype         => $itemtype->{itemtype},
600
            },
600
            },
601
            $biblionumber
601
            $biblio->biblionumber
602
        );
602
        );
603
        push @itemnumbers, $itemnumber;
603
        push @itemnumbers, $itemnumber;
604
    }
604
    }
Lines 608-639 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
608
608
609
    my ($itemfield) =
609
    my ($itemfield) =
610
      C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' );
610
      C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' );
611
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
611
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
612
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
612
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
613
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
613
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
614
      'Should carp is no record passed.';
614
      'Should carp is no record passed.';
615
615
616
    C4::Biblio::EmbedItemsInMarcBiblio({
616
    C4::Biblio::EmbedItemsInMarcBiblio({
617
        marc_record  => $record,
617
        marc_record  => $record,
618
        biblionumber => $biblionumber });
618
        biblionumber => $biblio->biblionumber });
619
    my @items = $record->field($itemfield);
619
    my @items = $record->field($itemfield);
620
    is( scalar @items, $number_of_items, 'Should return all items' );
620
    is( scalar @items, $number_of_items, 'Should return all items' );
621
621
622
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
622
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
623
        biblionumber => $biblionumber,
623
        biblionumber => $biblio->biblionumber,
624
        embed_items  => 1 });
624
        embed_items  => 1 });
625
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
625
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
626
626
627
    C4::Biblio::EmbedItemsInMarcBiblio({
627
    C4::Biblio::EmbedItemsInMarcBiblio({
628
        marc_record  => $record,
628
        marc_record  => $record,
629
        biblionumber => $biblionumber,
629
        biblionumber => $biblio->biblionumber,
630
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
630
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
631
    @items = $record->field($itemfield);
631
    @items = $record->field($itemfield);
632
    is( scalar @items, 2, 'Should return all items present in the list' );
632
    is( scalar @items, 2, 'Should return all items present in the list' );
633
633
634
    C4::Biblio::EmbedItemsInMarcBiblio({
634
    C4::Biblio::EmbedItemsInMarcBiblio({
635
        marc_record  => $record,
635
        marc_record  => $record,
636
        biblionumber => $biblionumber,
636
        biblionumber => $biblio->biblionumber,
637
        opac         => 1 });
637
        opac         => 1 });
638
    @items = $record->field($itemfield);
638
    @items = $record->field($itemfield);
639
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
639
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
Lines 644-650 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
644
644
645
    C4::Biblio::EmbedItemsInMarcBiblio({
645
    C4::Biblio::EmbedItemsInMarcBiblio({
646
        marc_record  => $record,
646
        marc_record  => $record,
647
        biblionumber => $biblionumber });
647
        biblionumber => $biblio->biblionumber });
648
    @items = $record->field($itemfield);
648
    @items = $record->field($itemfield);
649
    is( scalar @items,
649
    is( scalar @items,
650
        $number_of_items,
650
        $number_of_items,
Lines 652-658 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
652
652
653
    C4::Biblio::EmbedItemsInMarcBiblio({
653
    C4::Biblio::EmbedItemsInMarcBiblio({
654
        marc_record  => $record,
654
        marc_record  => $record,
655
        biblionumber => $biblionumber,
655
        biblionumber => $biblio->biblionumber,
656
        opac         => 1 });
656
        opac         => 1 });
657
    @items = $record->field($itemfield);
657
    @items = $record->field($itemfield);
658
    is(
658
    is(
Lines 666-672 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
666
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
666
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
667
    C4::Biblio::EmbedItemsInMarcBiblio({
667
    C4::Biblio::EmbedItemsInMarcBiblio({
668
        marc_record  => $record,
668
        marc_record  => $record,
669
        biblionumber => $biblionumber,
669
        biblionumber => $biblio->biblionumber,
670
        opac         => 1 });
670
        opac         => 1 });
671
    @items = $record->field($itemfield);
671
    @items = $record->field($itemfield);
672
    is(
672
    is(
Lines 702-708 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
702
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
702
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
703
703
704
    # Create a record with a barcode
704
    # Create a record with a barcode
705
    my ($biblionumber) = get_biblio( $framework->{frameworkcode} );
705
    my $biblio = $builder->gimme_a_biblio({ frameworkcode => $framework->{frameworkcode} });
706
    my $item_record = new MARC::Record;
706
    my $item_record = new MARC::Record;
707
    my $a_barcode = 'a barcode';
707
    my $a_barcode = 'a barcode';
708
    my $barcode_field = MARC::Field->new(
708
    my $barcode_field = MARC::Field->new(
Lines 715-721 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
715
        y => $itemtype
715
        y => $itemtype
716
    );
716
    );
717
    $item_record->append_fields( $barcode_field );
717
    $item_record->append_fields( $barcode_field );
718
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
718
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblio->biblionumber);
719
719
720
    # Make sure everything has been set up
720
    # Make sure everything has been set up
721
    my $item = GetItem($item_itemnumber);
721
    my $item = GetItem($item_itemnumber);
Lines 724-736 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
724
    # Delete the barcode field and save the record
724
    # Delete the barcode field and save the record
725
    $item_record->delete_fields( $barcode_field );
725
    $item_record->delete_fields( $barcode_field );
726
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
726
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
727
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
727
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
728
    $item = GetItem($item_itemnumber);
728
    $item = GetItem($item_itemnumber);
729
    is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
729
    is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
730
730
731
    # Re-add the barcode field and save the record
731
    # Re-add the barcode field and save the record
732
    $item_record->append_fields( $barcode_field );
732
    $item_record->append_fields( $barcode_field );
733
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
733
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
734
    $item = GetItem($item_itemnumber);
734
    $item = GetItem($item_itemnumber);
735
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
735
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
736
736
Lines 751-757 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
751
    );
751
    );
752
    $item_record->append_fields( $another_barcode_field );
752
    $item_record->append_fields( $another_barcode_field );
753
    # The DB value should not have been updated
753
    # The DB value should not have been updated
754
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
754
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
755
    $item = GetItem($item_itemnumber);
755
    $item = GetItem($item_itemnumber);
756
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
756
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
757
757
Lines 848-871 subtest 'Test logging for ModItem' => sub { Link Here
848
848
849
    # Create a biblio instance for testing
849
    # Create a biblio instance for testing
850
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
850
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
851
    my ($bibnum, $bibitemnum) = get_biblio();
851
    my $biblio = $builder->gimme_a_biblio();
852
852
853
    # Add an item.
853
    # Add an item.
854
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
854
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
855
855
856
    # False means no logging
856
    # False means no logging
857
    $schema->resultset('ActionLog')->search()->delete();
857
    $schema->resultset('ActionLog')->search()->delete();
858
    ModItem({ location => $location }, $bibnum, $itemnumber, { log_action => 0 });
858
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 0 });
859
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
859
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
860
860
861
    # True means logging
861
    # True means logging
862
    $schema->resultset('ActionLog')->search()->delete();
862
    $schema->resultset('ActionLog')->search()->delete();
863
    ModItem({ location => $location }, $bibnum, $itemnumber, { log_action => 1 });
863
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 1 });
864
    is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' );
864
    is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' );
865
865
866
    # Undefined defaults to true
866
    # Undefined defaults to true
867
    $schema->resultset('ActionLog')->search()->delete();
867
    $schema->resultset('ActionLog')->search()->delete();
868
    ModItem({ location => $location }, $bibnum, $itemnumber);
868
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
869
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
869
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
870
870
871
    $schema->storage->txn_rollback;
871
    $schema->storage->txn_rollback;
Lines 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 143-149 subtest 'Values should not be erased on editing' => sub { Link Here
143
143
144
    plan tests => 1;
144
    plan tests => 1;
145
145
146
    ( $biblionumber, $biblioitemnumber ) = get_biblio();
146
    my $biblio = $builder->gimme_a_biblio();
147
    my $biblionumber = $biblio->biblionumber;
147
    my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField( 'items.itemcallnumber', '' );
148
    my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField( 'items.itemcallnumber', '' );
148
    my ( $it_tag, $it_sf )   = GetMarcFromKohaField( 'items.itype', '' );
149
    my ( $it_tag, $it_sf )   = GetMarcFromKohaField( 'items.itype', '' );
149
150
Lines 346-358 subtest "Do not generate an expected if one already exists" => sub { Link Here
346
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
347
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
347
    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" );
348
    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" );
348
};
349
};
349
350
sub get_biblio {
351
    my $bib = MARC::Record->new();
352
    $bib->append_fields(
353
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
354
        MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
355
    );
356
    my ($bibnum, $bibitemnum) = AddBiblio($bib, '');
357
    return ($bibnum, $bibitemnum);
358
}
(-)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