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

(-)a/t/db_dependent/Accounts.t (-6 / +6 lines)
Lines 75-81 my $userenv_branchcode = $branchcode; Link Here
75
75
76
# Test manualinvoice
76
# Test manualinvoice
77
my $itemtype = $builder->build( { source => 'Itemtype' } );
77
my $itemtype = $builder->build( { source => 'Itemtype' } );
78
my $item   = $builder->build( { source => 'Item', value => { itype => $itemtype->{itemtype} } } );
78
my $item   = $builder->build_sample_item( { itype => $itemtype->{itemtype} } );
79
my $patron = $builder->build( { source => 'Borrower' } );
79
my $patron = $builder->build( { source => 'Borrower' } );
80
my $amount = 5;
80
my $amount = 5;
81
my $description = "Test fee!";
81
my $description = "Test fee!";
Lines 83-89 my $type = 'LOST'; Link Here
83
my $note = 'Test note!';
83
my $note = 'Test note!';
84
warning_like {
84
warning_like {
85
    C4::Accounts::manualinvoice( $patron->{borrowernumber},
85
    C4::Accounts::manualinvoice( $patron->{borrowernumber},
86
        $item->{itemnumber}, $description, $type, $amount, $note )
86
        $item->itemnumber, $description, $type, $amount, $note )
87
}
87
}
88
qr/C4::Accounts::manualinvoice is deprecated in favor of Koha::Account->add_debit/,
88
qr/C4::Accounts::manualinvoice is deprecated in favor of Koha::Account->add_debit/,
89
  "deprecation warning received for manualinvoice";
89
  "deprecation warning received for manualinvoice";
Lines 586-595 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
586
            processfee => 2.04,
586
            processfee => 2.04,
587
    }});
587
    }});
588
    my $cli_borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'};
588
    my $cli_borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'};
589
    my $cli_itemnumber1 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_no_fee->{itemtype} } })->{'itemnumber'};
589
    my $cli_itemnumber1 = $builder->build_sample_item({ itype => $itype_no_replace_no_fee->{itemtype} })->itemnumber;
590
    my $cli_itemnumber2 = $builder->build({ source => 'Item', value => { itype => $itype_replace_no_fee->{itemtype} } })->{'itemnumber'};
590
    my $cli_itemnumber2 = $builder->build_sample_item({ itype => $itype_replace_no_fee->{itemtype} })->itemnumber;
591
    my $cli_itemnumber3 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_fee->{itemtype} } })->{'itemnumber'};
591
    my $cli_itemnumber3 = $builder->build_sample_item({ itype => $itype_no_replace_fee->{itemtype} })->itemnumber;
592
    my $cli_itemnumber4 = $builder->build({ source => 'Item', value => { itype => $itype_replace_fee->{itemtype} } })->{'itemnumber'};
592
    my $cli_itemnumber4 = $builder->build_sample_item({ itype => $itype_replace_fee->{itemtype} })->itemnumber;
593
593
594
    my $cli_issue_id_1 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1 } })->{issue_id};
594
    my $cli_issue_id_1 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1 } })->{issue_id};
595
    my $cli_issue_id_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2 } })->{issue_id};
595
    my $cli_issue_id_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2 } })->{issue_id};
(-)a/t/db_dependent/Acquisition.t (-3 / +3 lines)
Lines 698-704 subtest 'ModReceiveOrder replacementprice tests' => sub { Link Here
698
    plan tests => 2;
698
    plan tests => 2;
699
    #Let's build an order, we need a couple things though
699
    #Let's build an order, we need a couple things though
700
    my $builder = t::lib::TestBuilder->new;
700
    my $builder = t::lib::TestBuilder->new;
701
    my $order_biblio = $builder->build({ source => 'Biblio' });
701
    my $order_biblio = $builder->build_sample_biblio;
702
    my $order_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
702
    my $order_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
703
    my $order_invoice = $builder->build({ source => 'Aqinvoice'});
703
    my $order_invoice = $builder->build({ source => 'Aqinvoice'});
704
    my $order_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
704
    my $order_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
Lines 715-721 subtest 'ModReceiveOrder replacementprice tests' => sub { Link Here
715
    };
715
    };
716
    my $receive_order = $builder->build({ source => 'Aqorder', value => $orderinfo });
716
    my $receive_order = $builder->build({ source => 'Aqorder', value => $orderinfo });
717
    (undef, my $received_ordernumber) = ModReceiveOrder({
717
    (undef, my $received_ordernumber) = ModReceiveOrder({
718
            biblionumber => $order_biblio->{biblionumber},
718
            biblionumber => $order_biblio->biblionumber,
719
            order        => $receive_order,
719
            order        => $receive_order,
720
            invoice      => $order_invoice,
720
            invoice      => $order_invoice,
721
            quantityreceived => $receive_order->{quantity},
721
            quantityreceived => $receive_order->{quantity},
Lines 726-732 subtest 'ModReceiveOrder replacementprice tests' => sub { Link Here
726
    $orderinfo->{replacementprice} = 16.12;
726
    $orderinfo->{replacementprice} = 16.12;
727
    $receive_order = $builder->build({ source => 'Aqorder', value => $orderinfo });
727
    $receive_order = $builder->build({ source => 'Aqorder', value => $orderinfo });
728
    (undef, $received_ordernumber) = ModReceiveOrder({
728
    (undef, $received_ordernumber) = ModReceiveOrder({
729
            biblionumber => $order_biblio->{biblionumber},
729
            biblionumber => $order_biblio->biblionumber,
730
            order        => $receive_order,
730
            order        => $receive_order,
731
            invoice      => $order_invoice,
731
            invoice      => $order_invoice,
732
            quantityreceived => $receive_order->{quantity},
732
            quantityreceived => $receive_order->{quantity},
(-)a/t/db_dependent/ArticleRequests.t (-22 / +5 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 57;
22
use Test::More tests => 54;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 47-71 my $dbh = C4::Context->dbh; Link Here
47
47
48
$dbh->do("DELETE FROM circulation_rules");
48
$dbh->do("DELETE FROM circulation_rules");
49
49
50
my $biblio = Koha::Biblio->new()->store();
50
my $item = $builder->build_sample_item;
51
ok( $biblio->id, 'Koha::Biblio created' );
51
my $biblio = $item->biblio;
52
53
my $biblioitem = $schema->resultset('Biblioitem')->new(
54
    {
55
        biblionumber => $biblio->id
56
    }
57
)->insert();
58
ok( $biblioitem->id, 'biblioitem created' );
59
60
my $itype = $builder->build({ source => 'Itemtype' });
61
my $item = Koha::Item->new(
62
    {
63
        biblionumber     => $biblio->id,
64
        biblioitemnumber => $biblioitem->id,
65
        itype => $itype->{itemtype},
66
    }
67
)->store();
68
ok( $item->id, 'Koha::Item created' );
69
52
70
my $branch   = $builder->build({ source => 'Branch' });
53
my $branch   = $builder->build({ source => 'Branch' });
71
my $category = $builder->build({ source => 'Category' });
54
my $category = $builder->build({ source => 'Category' });
Lines 86-93 my $article_request_title = 'an article request title'; Link Here
86
my $article_request = Koha::ArticleRequest->new(
69
my $article_request = Koha::ArticleRequest->new(
87
    {
70
    {
88
        borrowernumber => $patron->id,
71
        borrowernumber => $patron->id,
89
        biblionumber   => $biblio->id,
72
        biblionumber   => $item->biblionumber,
90
        itemnumber     => $item->id,
73
        itemnumber     => $item->itemnumber,
91
        title          => $article_request_title,
74
        title          => $article_request_title,
92
    }
75
    }
93
)->store();
76
)->store();
(-)a/t/db_dependent/Barcodes.t (-16 / +12 lines)
Lines 50-61 subtest 'Test generation of annual barcodes from DB values' => sub { Link Here
50
50
51
    my $barcodevalue = $barcodeobj->value();
51
    my $barcodevalue = $barcodeobj->value();
52
52
53
    my $item_1 = $builder->build({
53
    my $item_1 = $builder->build_sample_item(
54
        source => 'Item',
54
        {
55
        value => {
56
            barcode => $barcodevalue
55
            barcode => $barcodevalue
57
        }
56
        }
58
    });
57
    );
59
58
60
    is($barcodevalue,$barcodeobj->db_max(), "(annual) First barcode saved to db is equal to db_max" );
59
    is($barcodevalue,$barcodeobj->db_max(), "(annual) First barcode saved to db is equal to db_max" );
61
60
Lines 66-77 subtest 'Test generation of annual barcodes from DB values' => sub { Link Here
66
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
65
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
67
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
66
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
68
67
69
    my $item_2 = $builder->build({
68
    my $item_2 = $builder->build_sample_item(
70
        source => 'Item',
69
        {
71
        value => {
72
            barcode => $barcodevalue
70
            barcode => $barcodevalue
73
        }
71
        }
74
    });
72
    );
75
73
76
    $barcodeobj = C4::Barcodes->new('annual');
74
    $barcodeobj = C4::Barcodes->new('annual');
77
75
Lines 105-116 subtest 'Test generation of hbyymmincr barcodes from DB values' => sub { Link Here
105
103
106
    my $barcodevalue = $barcodeobj->value();
104
    my $barcodevalue = $barcodeobj->value();
107
105
108
    my $item_1 = $builder->build({
106
    my $item_1 = $builder->build_sample_item(
109
        source => 'Item',
107
        {
110
        value => {
111
            barcode => $barcodevalue
108
            barcode => $barcodevalue
112
        }
109
        }
113
    });
110
    );
114
111
115
    is($barcodevalue,$barcodeobj->db_max(), "(hbyymmincr) First barcode saved to db is equal to db_max" );
112
    is($barcodevalue,$barcodeobj->db_max(), "(hbyymmincr) First barcode saved to db is equal to db_max" );
116
113
Lines 121-132 subtest 'Test generation of hbyymmincr barcodes from DB values' => sub { Link Here
121
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
118
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
122
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
119
    $barcodevalue = $barcodeobj->next_value($barcodevalue);
123
120
124
    my $item_2 = $builder->build({
121
    my $item_2 = $builder->build_sample_item(
125
        source => 'Item',
122
        {
126
        value => {
127
            barcode => $barcodevalue
123
            barcode => $barcodevalue
128
        }
124
        }
129
    });
125
    );
130
126
131
    $barcodeobj = C4::Barcodes->new('hbyymmincr',$branchcode_1);
127
    $barcodeobj = C4::Barcodes->new('hbyymmincr',$branchcode_1);
132
128
(-)a/t/db_dependent/Barcodes_ValueBuilder.t (-16 / +12 lines)
Lines 34-63 my $builder = t::lib::TestBuilder->new; Link Here
34
my $dbh = C4::Context->dbh;
34
my $dbh = C4::Context->dbh;
35
$dbh->do(q|DELETE FROM issues|);
35
$dbh->do(q|DELETE FROM issues|);
36
$dbh->do(q|DELETE FROM items|);
36
$dbh->do(q|DELETE FROM items|);
37
my $item_1 = $builder->build({
37
my $item_1 = $builder->build_sample_item(
38
    source => 'Item',
38
    {
39
    value => {
40
        barcode => '33333074344563'
39
        barcode => '33333074344563'
41
    }
40
    }
42
});
41
);
43
my $item_2 = $builder->build({
42
my $item_2 = $builder->build_sample_item(
44
    source => 'Item',
43
    {
45
    value => {
46
        barcode => 'hb12070890'
44
        barcode => 'hb12070890'
47
    }
45
    }
48
});
46
);
49
my $item_3 = $builder->build({
47
my $item_3 = $builder->build_sample_item(
50
    source => 'Item',
48
    {
51
    value => {
52
        barcode => '201200345'
49
        barcode => '201200345'
53
    }
50
    }
54
});
51
);
55
my $item_4 = $builder->build({
52
my $item_4 = $builder->build_sample_item(
56
    source => 'Item',
53
    {
57
    value => {
58
        barcode => '2012-0034'
54
        barcode => '2012-0034'
59
    }
55
    }
60
});
56
);
61
57
62
my %args = (
58
my %args = (
63
    year        => '2012',
59
    year        => '2012',
(-)a/t/db_dependent/Biblio/ModBiblioMarc.t (-3 / +3 lines)
Lines 33-47 subtest "Check MARC field length calculation" => sub { Link Here
33
33
34
    t::lib::Mocks->mock_preference( 'marcflavour', 'MARC21' );
34
    t::lib::Mocks->mock_preference( 'marcflavour', 'MARC21' );
35
35
36
    my $biblio = t::lib::TestBuilder->new->build({ source => 'Biblio' });
36
    my $biblio = t::lib::TestBuilder->new->build_sample_biblio;
37
    my $record = MARC::Record->new;
37
    my $record = MARC::Record->new;
38
    $record->append_fields(
38
    $record->append_fields(
39
        MARC::Field->new( '100', '', '', a => 'My title' ),
39
        MARC::Field->new( '100', '', '', a => 'My title' ),
40
    );
40
    );
41
41
42
    is( $record->leader, ' 'x24, 'No leader lengths' );
42
    is( $record->leader, ' 'x24, 'No leader lengths' );
43
    C4::Biblio::ModBiblioMarc( $record, $biblio->{biblionumber}, '' );
43
    C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber, '' );
44
    my $savedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->{biblionumber} });
44
    my $savedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
45
    like( substr($savedrec->leader,0,5), qr/^\d{5}$/, 'Record length found' );
45
    like( substr($savedrec->leader,0,5), qr/^\d{5}$/, 'Record length found' );
46
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
46
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
47
};
47
};
(-)a/t/db_dependent/Budgets.t (-7 / +5 lines)
Lines 968-976 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
968
#Let's build an order, we need a couple things though
968
#Let's build an order, we need a couple things though
969
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
969
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
970
970
971
    my $spent_biblio   = $builder->build({ source => 'Biblio' });
971
    my $item_1         = $builder->build_sample_item;
972
    my $item_1         = $builder->build({ source => 'Item', value => { biblionumber => $spent_biblio->{biblionumber} } });
973
    my $biblioitem_1   = $builder->build({ source => 'Biblioitem', value => { biblionumber => $spent_biblio->{biblionumber}, itemnumber => $item_1->{itemnumber} } });
974
    my $spent_basket   = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
972
    my $spent_basket   = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
975
    my $spent_invoice  = $builder->build({ source => 'Aqinvoice'});
973
    my $spent_invoice  = $builder->build({ source => 'Aqinvoice'});
976
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
974
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
Lines 996-1002 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
996
        rrp                     => 16.99,
994
        rrp                     => 16.99,
997
        discount                => .42,
995
        discount                => .42,
998
        ecost                   => 16.91,
996
        ecost                   => 16.91,
999
        biblionumber            => $spent_biblio->{biblionumber},
997
        biblionumber            => $item_1->biblionumber,
1000
        currency                => $spent_currency->{currency},
998
        currency                => $spent_currency->{currency},
1001
        tax_rate_on_ordering    => 0,
999
        tax_rate_on_ordering    => 0,
1002
        tax_value_on_ordering   => 0,
1000
        tax_value_on_ordering   => 0,
Lines 1045-1051 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
1045
#Let's test some budget planning
1043
#Let's test some budget planning
1046
#Regression tests for bug 18736
1044
#Regression tests for bug 18736
1047
    #We need an item to test by BRANCHES
1045
    #We need an item to test by BRANCHES
1048
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber}  } });
1046
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->itemnumber  } });
1049
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
1047
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
1050
    my $cell = {
1048
    my $cell = {
1051
        authcat => 'MONTHS',
1049
        authcat => 'MONTHS',
Lines 1062-1073 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
1062
            expected_exact   => 9.8542,
1060
            expected_exact   => 9.8542,
1063
        },
1061
        },
1064
        'BRANCHES' => {
1062
        'BRANCHES' => {
1065
            authvalue => $item_1->{homebranch},
1063
            authvalue => $item_1->homebranch,
1066
            expected_rounded => 9.85,
1064
            expected_rounded => 9.85,
1067
            expected_exact   => 9.8542,
1065
            expected_exact   => 9.8542,
1068
        },
1066
        },
1069
        'ITEMTYPES' => {
1067
        'ITEMTYPES' => {
1070
            authvalue => $biblioitem_1->{itemtype},
1068
            authvalue => $item_1->biblioitem->itemtype,
1071
            expected_rounded => 78.80,
1069
            expected_rounded => 78.80,
1072
            expected_exact   => 78.8336,
1070
            expected_exact   => 78.8336,
1073
        },
1071
        },
(-)a/t/db_dependent/Circulation.t (-171 / +154 lines)
Lines 83-91 sub test_debarment_on_checkout { Link Here
83
    );
83
    );
84
    my @caller      = caller;
84
    my @caller      = caller;
85
    my $line_number = $caller[2];
85
    my $line_number = $caller[2];
86
    AddIssue( $patron, $item->{barcode}, $due_date );
86
    AddIssue( $patron, $item->barcode, $due_date );
87
87
88
    my ( undef, $message ) = AddReturn( $item->{barcode}, $library->{branchcode}, undef, $return_date );
88
    my ( undef, $message ) = AddReturn( $item->barcode, $library->{branchcode}, undef, $return_date );
89
    is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' )
89
    is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' )
90
        or diag('AddReturn returned message ' . Dumper $message );
90
        or diag('AddReturn returned message ' . Dumper $message );
91
    my $debarments = Koha::Patron::Debarments::GetDebarments(
91
    my $debarments = Koha::Patron::Debarments::GetDebarments(
Lines 749-767 subtest "CanBookBeRenewed tests" => sub { Link Here
749
749
750
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
750
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
751
        plan tests => 14;
751
        plan tests => 14;
752
        my $item_to_auto_renew = $builder->build(
752
        my $item_to_auto_renew = $builder->build_sample_item(
753
            {   source => 'Item',
753
            {
754
                value  => {
754
                biblionumber => $biblio->biblionumber,
755
                    biblionumber  => $biblio->biblionumber,
755
                library      => $branch,
756
                    homebranch    => $branch,
757
                    holdingbranch => $branch,
758
                }
759
            }
756
            }
760
        );
757
        );
761
758
762
        my $ten_days_before = dt_from_string->add( days => -10 );
759
        my $ten_days_before = dt_from_string->add( days => -10 );
763
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
760
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
764
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
761
        AddIssue( $renewing_borrower, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
765
762
766
        Koha::CirculationRules->set_rules(
763
        Koha::CirculationRules->set_rules(
767
            {
764
            {
Lines 775-781 subtest "CanBookBeRenewed tests" => sub { Link Here
775
            }
772
            }
776
        );
773
        );
777
        ( $renewokay, $error ) =
774
        ( $renewokay, $error ) =
778
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
775
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
779
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
776
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
780
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
777
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
781
778
Lines 791-797 subtest "CanBookBeRenewed tests" => sub { Link Here
791
            }
788
            }
792
        );
789
        );
793
        ( $renewokay, $error ) =
790
        ( $renewokay, $error ) =
794
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
791
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
795
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
792
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
796
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
793
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
797
794
Lines 807-813 subtest "CanBookBeRenewed tests" => sub { Link Here
807
            }
804
            }
808
        );
805
        );
809
        ( $renewokay, $error ) =
806
        ( $renewokay, $error ) =
810
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
807
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
811
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
808
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
812
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
809
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
813
810
Lines 823-829 subtest "CanBookBeRenewed tests" => sub { Link Here
823
            }
820
            }
824
        );
821
        );
825
        ( $renewokay, $error ) =
822
        ( $renewokay, $error ) =
826
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
823
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
827
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
824
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
828
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
825
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
829
826
Lines 840-846 subtest "CanBookBeRenewed tests" => sub { Link Here
840
            }
837
            }
841
        );
838
        );
842
        ( $renewokay, $error ) =
839
        ( $renewokay, $error ) =
843
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
840
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
844
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
841
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
845
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
842
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
846
843
Lines 857-863 subtest "CanBookBeRenewed tests" => sub { Link Here
857
            }
854
            }
858
        );
855
        );
859
        ( $renewokay, $error ) =
856
        ( $renewokay, $error ) =
860
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
857
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
861
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
858
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
862
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
859
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
863
860
Lines 874-898 subtest "CanBookBeRenewed tests" => sub { Link Here
874
            }
871
            }
875
        );
872
        );
876
        ( $renewokay, $error ) =
873
        ( $renewokay, $error ) =
877
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
874
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
878
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
875
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
879
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
876
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
880
    };
877
    };
881
878
882
    subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew & OPACFineNoRenewalsIncludeCredit" => sub {
879
    subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew & OPACFineNoRenewalsIncludeCredit" => sub {
883
        plan tests => 10;
880
        plan tests => 10;
884
        my $item_to_auto_renew = $builder->build({
881
        my $item_to_auto_renew = $builder->build_sample_item(
885
            source => 'Item',
882
            {
886
            value => {
887
                biblionumber => $biblio->biblionumber,
883
                biblionumber => $biblio->biblionumber,
888
                homebranch       => $branch,
884
                library      => $branch,
889
                holdingbranch    => $branch,
890
            }
885
            }
891
        });
886
        );
892
887
893
        my $ten_days_before = dt_from_string->add( days => -10 );
888
        my $ten_days_before = dt_from_string->add( days => -10 );
894
        my $ten_days_ahead = dt_from_string->add( days => 10 );
889
        my $ten_days_ahead = dt_from_string->add( days => 10 );
895
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
890
        AddIssue( $renewing_borrower, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
896
891
897
        Koha::CirculationRules->set_rules(
892
        Koha::CirculationRules->set_rules(
898
            {
893
            {
Lines 915-926 subtest "CanBookBeRenewed tests" => sub { Link Here
915
                amount      => $fines_amount,
910
                amount      => $fines_amount,
916
                interface   => 'test',
911
                interface   => 'test',
917
                type        => 'OVERDUE',
912
                type        => 'OVERDUE',
918
                item_id     => $item_to_auto_renew->{itemnumber},
913
                item_id     => $item_to_auto_renew->itemnumber,
919
                description => "Some fines"
914
                description => "Some fines"
920
            }
915
            }
921
        )->status('RETURNED')->store;
916
        )->status('RETURNED')->store;
922
        ( $renewokay, $error ) =
917
        ( $renewokay, $error ) =
923
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
918
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
924
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
919
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
925
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
920
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
926
921
Lines 929-940 subtest "CanBookBeRenewed tests" => sub { Link Here
929
                amount      => $fines_amount,
924
                amount      => $fines_amount,
930
                interface   => 'test',
925
                interface   => 'test',
931
                type        => 'OVERDUE',
926
                type        => 'OVERDUE',
932
                item_id     => $item_to_auto_renew->{itemnumber},
927
                item_id     => $item_to_auto_renew->itemnumber,
933
                description => "Some fines"
928
                description => "Some fines"
934
            }
929
            }
935
        )->status('RETURNED')->store;
930
        )->status('RETURNED')->store;
936
        ( $renewokay, $error ) =
931
        ( $renewokay, $error ) =
937
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
932
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
938
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
933
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
939
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
934
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
940
935
Lines 943-954 subtest "CanBookBeRenewed tests" => sub { Link Here
943
                amount      => $fines_amount,
938
                amount      => $fines_amount,
944
                interface   => 'test',
939
                interface   => 'test',
945
                type        => 'OVERDUE',
940
                type        => 'OVERDUE',
946
                item_id     => $item_to_auto_renew->{itemnumber},
941
                item_id     => $item_to_auto_renew->itemnumber,
947
                description => "Some fines"
942
                description => "Some fines"
948
            }
943
            }
949
        )->status('RETURNED')->store;
944
        )->status('RETURNED')->store;
950
        ( $renewokay, $error ) =
945
        ( $renewokay, $error ) =
951
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
946
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
952
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
947
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
953
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' );
948
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' );
954
949
Lines 961-973 subtest "CanBookBeRenewed tests" => sub { Link Here
961
            }
956
            }
962
        )->store;
957
        )->store;
963
        ( $renewokay, $error ) =
958
        ( $renewokay, $error ) =
964
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
959
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
965
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
960
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
966
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
961
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
967
962
968
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
963
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
969
        ( $renewokay, $error ) =
964
        ( $renewokay, $error ) =
970
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
965
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
971
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
966
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
972
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
967
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
973
968
Lines 977-990 subtest "CanBookBeRenewed tests" => sub { Link Here
977
972
978
    subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub {
973
    subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub {
979
        plan tests => 6;
974
        plan tests => 6;
980
        my $item_to_auto_renew = $builder->build({
975
        my $item_to_auto_renew = $builder->build_sample_item(
981
            source => 'Item',
976
            {
982
            value => {
983
                biblionumber => $biblio->biblionumber,
977
                biblionumber => $biblio->biblionumber,
984
                homebranch       => $branch,
978
                library      => $branch,
985
                holdingbranch    => $branch,
986
            }
979
            }
987
        });
980
        );
988
981
989
        Koha::CirculationRules->set_rules(
982
        Koha::CirculationRules->set_rules(
990
            {
983
            {
Lines 1005-1013 subtest "CanBookBeRenewed tests" => sub { Link Here
1005
        # => auto renew is allowed
998
        # => auto renew is allowed
1006
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
999
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
1007
        my $patron = $expired_borrower;
1000
        my $patron = $expired_borrower;
1008
        my $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1001
        my $checkout = AddIssue( $patron, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1009
        ( $renewokay, $error ) =
1002
        ( $renewokay, $error ) =
1010
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1003
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->itemnumber );
1011
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1004
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1012
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1005
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1013
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1006
        Koha::Checkouts->find( $checkout->issue_id )->delete;
Lines 1017-1025 subtest "CanBookBeRenewed tests" => sub { Link Here
1017
        # => auto renew is not allowed
1010
        # => auto renew is not allowed
1018
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1011
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1019
        $patron = $expired_borrower;
1012
        $patron = $expired_borrower;
1020
        $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1013
        $checkout = AddIssue( $patron, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1021
        ( $renewokay, $error ) =
1014
        ( $renewokay, $error ) =
1022
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1015
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->itemnumber );
1023
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1016
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1024
        is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
1017
        is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
1025
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1018
        Koha::Checkouts->find( $checkout->issue_id )->delete;
Lines 1029-1037 subtest "CanBookBeRenewed tests" => sub { Link Here
1029
        # => auto renew is allowed
1022
        # => auto renew is allowed
1030
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1023
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1031
        $patron = $renewing_borrower;
1024
        $patron = $renewing_borrower;
1032
        $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1025
        $checkout = AddIssue( $patron, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1033
        ( $renewokay, $error ) =
1026
        ( $renewokay, $error ) =
1034
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
1027
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->itemnumber );
1035
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1028
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1036
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1029
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1037
        Koha::Checkouts->find( $checkout->issue_id )->delete;
1030
        Koha::Checkouts->find( $checkout->issue_id )->delete;
Lines 1039-1057 subtest "CanBookBeRenewed tests" => sub { Link Here
1039
1032
1040
    subtest "GetLatestAutoRenewDate" => sub {
1033
    subtest "GetLatestAutoRenewDate" => sub {
1041
        plan tests => 5;
1034
        plan tests => 5;
1042
        my $item_to_auto_renew = $builder->build(
1035
        my $item_to_auto_renew = $builder->build_sample_item(
1043
            {   source => 'Item',
1036
            {
1044
                value  => {
1037
                biblionumber => $biblio->biblionumber,
1045
                    biblionumber  => $biblio->biblionumber,
1038
                library      => $branch,
1046
                    homebranch    => $branch,
1047
                    holdingbranch => $branch,
1048
                }
1049
            }
1039
            }
1050
        );
1040
        );
1051
1041
1052
        my $ten_days_before = dt_from_string->add( days => -10 );
1042
        my $ten_days_before = dt_from_string->add( days => -10 );
1053
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1043
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1054
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1044
        AddIssue( $renewing_borrower, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1055
        Koha::CirculationRules->set_rules(
1045
        Koha::CirculationRules->set_rules(
1056
            {
1046
            {
1057
                categorycode => undef,
1047
                categorycode => undef,
Lines 1064-1070 subtest "CanBookBeRenewed tests" => sub { Link Here
1064
                }
1054
                }
1065
            }
1055
            }
1066
        );
1056
        );
1067
        my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
1057
        my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
1068
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' );
1058
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' );
1069
        my $five_days_before = dt_from_string->add( days => -5 );
1059
        my $five_days_before = dt_from_string->add( days => -5 );
1070
        Koha::CirculationRules->set_rules(
1060
        Koha::CirculationRules->set_rules(
Lines 1079-1085 subtest "CanBookBeRenewed tests" => sub { Link Here
1079
                }
1069
                }
1080
            }
1070
            }
1081
        );
1071
        );
1082
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
1072
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
1083
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
1073
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
1084
            $five_days_before->truncate( to => 'minute' ),
1074
            $five_days_before->truncate( to => 'minute' ),
1085
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
1075
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
Lines 1100-1106 subtest "CanBookBeRenewed tests" => sub { Link Here
1100
                }
1090
                }
1101
            }
1091
            }
1102
        );
1092
        );
1103
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
1093
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
1104
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
1094
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
1105
            $five_days_ahead->truncate( to => 'minute' ),
1095
            $five_days_ahead->truncate( to => 'minute' ),
1106
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
1096
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
Lines 1118-1124 subtest "CanBookBeRenewed tests" => sub { Link Here
1118
                }
1108
                }
1119
            }
1109
            }
1120
        );
1110
        );
1121
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
1111
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
1122
        is( $latest_auto_renew_date->truncate( to => 'day' ),
1112
        is( $latest_auto_renew_date->truncate( to => 'day' ),
1123
            $two_days_ahead->truncate( to => 'day' ),
1113
            $two_days_ahead->truncate( to => 'day' ),
1124
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after'
1114
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after'
Lines 1135-1141 subtest "CanBookBeRenewed tests" => sub { Link Here
1135
                }
1125
                }
1136
            }
1126
            }
1137
        );
1127
        );
1138
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
1128
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber );
1139
        is( $latest_auto_renew_date->truncate( to => 'day' ),
1129
        is( $latest_auto_renew_date->truncate( to => 'day' ),
1140
            $two_days_ahead->truncate( to => 'day' ),
1130
            $two_days_ahead->truncate( to => 'day' ),
1141
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after'
1131
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after'
Lines 1602-1612 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1602
            homebranch    => $homebranch->{branchcode},
1592
            homebranch    => $homebranch->{branchcode},
1603
            holdingbranch => $holdingbranch->{branchcode},
1593
            holdingbranch => $holdingbranch->{branchcode},
1604
        }
1594
        }
1605
    )->unblessed;
1595
    );
1606
1596
1607
    set_userenv($holdingbranch);
1597
    set_userenv($holdingbranch);
1608
1598
1609
    my $issue = AddIssue( $patron_1->unblessed, $item->{barcode} );
1599
    my $issue = AddIssue( $patron_1->unblessed, $item->barcode );
1610
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1600
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1611
1601
1612
    my ( $error, $question, $alerts );
1602
    my ( $error, $question, $alerts );
Lines 1619-1634 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1619
    ok( $error->{UNKNOWN_BARCODE}, '"KohaIsAwesome" is not a valid barcode as expected.' );
1609
    ok( $error->{UNKNOWN_BARCODE}, '"KohaIsAwesome" is not a valid barcode as expected.' );
1620
    ## Can be issued from homebranch
1610
    ## Can be issued from homebranch
1621
    set_userenv($homebranch);
1611
    set_userenv($homebranch);
1622
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1612
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1623
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1613
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1624
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1614
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1625
    ## Can be issued from holdingbranch
1615
    ## Can be issued from holdingbranch
1626
    set_userenv($holdingbranch);
1616
    set_userenv($holdingbranch);
1627
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1617
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1628
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1618
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1629
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1619
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1630
    ## Can be issued from another branch
1620
    ## Can be issued from another branch
1631
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1621
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1632
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1622
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1633
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1623
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1634
1624
Lines 1636-1653 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1636
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
1626
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
1637
    ## Cannot be issued from homebranch
1627
    ## Cannot be issued from homebranch
1638
    set_userenv($homebranch);
1628
    set_userenv($homebranch);
1639
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1629
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1640
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1630
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1641
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1631
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1642
    is( $error->{branch_to_return},         $holdingbranch->{branchcode}, 'branch_to_return matched holdingbranch' );
1632
    is( $error->{branch_to_return},         $holdingbranch->{branchcode}, 'branch_to_return matched holdingbranch' );
1643
    ## Can be issued from holdinbranch
1633
    ## Can be issued from holdinbranch
1644
    set_userenv($holdingbranch);
1634
    set_userenv($holdingbranch);
1645
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1635
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1646
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1636
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1647
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1637
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1648
    ## Cannot be issued from another branch
1638
    ## Cannot be issued from another branch
1649
    set_userenv($otherbranch);
1639
    set_userenv($otherbranch);
1650
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1640
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1651
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1641
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1652
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1642
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1653
    is( $error->{branch_to_return},         $holdingbranch->{branchcode}, 'branch_to_return matches holdingbranch' );
1643
    is( $error->{branch_to_return},         $holdingbranch->{branchcode}, 'branch_to_return matches holdingbranch' );
Lines 1656-1673 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1656
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
1646
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
1657
    ## Can be issued from holdinbranch
1647
    ## Can be issued from holdinbranch
1658
    set_userenv($homebranch);
1648
    set_userenv($homebranch);
1659
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1649
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1660
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1650
    is( keys(%$error) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1661
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1651
    is( exists $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER must be set' );
1662
    ## Cannot be issued from holdinbranch
1652
    ## Cannot be issued from holdinbranch
1663
    set_userenv($holdingbranch);
1653
    set_userenv($holdingbranch);
1664
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1654
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1665
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1655
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1666
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1656
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1667
    is( $error->{branch_to_return},         $homebranch->{branchcode}, 'branch_to_return matches homebranch' );
1657
    is( $error->{branch_to_return},         $homebranch->{branchcode}, 'branch_to_return matches homebranch' );
1668
    ## Cannot be issued from holdinbranch
1658
    ## Cannot be issued from holdinbranch
1669
    set_userenv($otherbranch);
1659
    set_userenv($otherbranch);
1670
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1660
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->barcode );
1671
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1661
    is( keys(%$question) + keys(%$alerts), 0, 'There should not be any errors or alerts (impossible)' . str($error, $question, $alerts) );
1672
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1662
    is( exists $error->{RETURN_IMPOSSIBLE}, 1, 'RETURN_IMPOSSIBLE must be set' );
1673
    is( $error->{branch_to_return},         $homebranch->{branchcode}, 'branch_to_return matches homebranch' );
1663
    is( $error->{branch_to_return},         $homebranch->{branchcode}, 'branch_to_return matches homebranch' );
Lines 1689-1700 subtest 'AddIssue & AllowReturnToBranch' => sub { Link Here
1689
            homebranch    => $homebranch->{branchcode},
1679
            homebranch    => $homebranch->{branchcode},
1690
            holdingbranch => $holdingbranch->{branchcode},
1680
            holdingbranch => $holdingbranch->{branchcode},
1691
        }
1681
        }
1692
    )->unblessed;
1682
    );
1693
1683
1694
    set_userenv($holdingbranch);
1684
    set_userenv($holdingbranch);
1695
1685
1696
    my $ref_issue = 'Koha::Checkout';
1686
    my $ref_issue = 'Koha::Checkout';
1697
    my $issue = AddIssue( $patron_1, $item->{barcode} );
1687
    my $issue = AddIssue( $patron_1, $item->barcode );
1698
1688
1699
    my ( $error, $question, $alerts );
1689
    my ( $error, $question, $alerts );
1700
1690
Lines 1702-1743 subtest 'AddIssue & AllowReturnToBranch' => sub { Link Here
1702
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
1692
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
1703
    ## Can be issued from homebranch
1693
    ## Can be issued from homebranch
1704
    set_userenv($homebranch);
1694
    set_userenv($homebranch);
1705
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue, 'AllowReturnToBranch - anywhere | Can be issued from homebranch');
1695
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), $ref_issue, 'AllowReturnToBranch - anywhere | Can be issued from homebranch');
1706
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1696
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->barcode ); # Reinsert the original issue
1707
    ## Can be issued from holdinbranch
1697
    ## Can be issued from holdinbranch
1708
    set_userenv($holdingbranch);
1698
    set_userenv($holdingbranch);
1709
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue, 'AllowReturnToBranch - anywhere | Can be issued from holdingbranch');
1699
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), $ref_issue, 'AllowReturnToBranch - anywhere | Can be issued from holdingbranch');
1710
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1700
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->barcode ); # Reinsert the original issue
1711
    ## Can be issued from another branch
1701
    ## Can be issued from another branch
1712
    set_userenv($otherbranch);
1702
    set_userenv($otherbranch);
1713
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue, 'AllowReturnToBranch - anywhere | Can be issued from otherbranch');
1703
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), $ref_issue, 'AllowReturnToBranch - anywhere | Can be issued from otherbranch');
1714
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1704
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->barcode ); # Reinsert the original issue
1715
1705
1716
    # AllowReturnToBranch == holdinbranch
1706
    # AllowReturnToBranch == holdinbranch
1717
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
1707
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
1718
    ## Cannot be issued from homebranch
1708
    ## Cannot be issued from homebranch
1719
    set_userenv($homebranch);
1709
    set_userenv($homebranch);
1720
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '', 'AllowReturnToBranch - holdingbranch | Cannot be issued from homebranch');
1710
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), '', 'AllowReturnToBranch - holdingbranch | Cannot be issued from homebranch');
1721
    ## Can be issued from holdingbranch
1711
    ## Can be issued from holdingbranch
1722
    set_userenv($holdingbranch);
1712
    set_userenv($holdingbranch);
1723
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue, 'AllowReturnToBranch - holdingbranch | Can be issued from holdingbranch');
1713
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), $ref_issue, 'AllowReturnToBranch - holdingbranch | Can be issued from holdingbranch');
1724
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1714
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->barcode ); # Reinsert the original issue
1725
    ## Cannot be issued from another branch
1715
    ## Cannot be issued from another branch
1726
    set_userenv($otherbranch);
1716
    set_userenv($otherbranch);
1727
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '', 'AllowReturnToBranch - holdingbranch | Cannot be issued from otherbranch');
1717
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), '', 'AllowReturnToBranch - holdingbranch | Cannot be issued from otherbranch');
1728
1718
1729
    # AllowReturnToBranch == homebranch
1719
    # AllowReturnToBranch == homebranch
1730
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
1720
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
1731
    ## Can be issued from homebranch
1721
    ## Can be issued from homebranch
1732
    set_userenv($homebranch);
1722
    set_userenv($homebranch);
1733
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue, 'AllowReturnToBranch - homebranch | Can be issued from homebranch' );
1723
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), $ref_issue, 'AllowReturnToBranch - homebranch | Can be issued from homebranch' );
1734
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1724
    set_userenv($holdingbranch); AddIssue( $patron_1, $item->barcode ); # Reinsert the original issue
1735
    ## Cannot be issued from holdinbranch
1725
    ## Cannot be issued from holdinbranch
1736
    set_userenv($holdingbranch);
1726
    set_userenv($holdingbranch);
1737
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '', 'AllowReturnToBranch - homebranch | Cannot be issued from holdingbranch' );
1727
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), '', 'AllowReturnToBranch - homebranch | Cannot be issued from holdingbranch' );
1738
    ## Cannot be issued from another branch
1728
    ## Cannot be issued from another branch
1739
    set_userenv($otherbranch);
1729
    set_userenv($otherbranch);
1740
    is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '', 'AllowReturnToBranch - homebranch | Cannot be issued from otherbranch' );
1730
    is ( ref( AddIssue( $patron_2, $item->barcode ) ), '', 'AllowReturnToBranch - homebranch | Cannot be issued from otherbranch' );
1741
    # TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch');
1731
    # TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch');
1742
};
1732
};
1743
1733
Lines 1750-1787 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
1750
        {
1740
        {
1751
            library => $library->{branchcode},
1741
            library => $library->{branchcode},
1752
        }
1742
        }
1753
    )->unblessed;
1743
    );
1754
    my $item_2 = $builder->build_sample_item(
1744
    my $item_2 = $builder->build_sample_item(
1755
        {
1745
        {
1756
            library => $library->{branchcode},
1746
            library => $library->{branchcode},
1757
        }
1747
        }
1758
    )->unblessed;
1748
    );
1759
1749
1760
    my ( $error, $question, $alerts );
1750
    my ( $error, $question, $alerts );
1761
1751
1762
    # Patron cannot issue item_1, they have overdues
1752
    # Patron cannot issue item_1, they have overdues
1763
    my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
1753
    my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
1764
    my $issue = AddIssue( $patron->unblessed, $item_1->{barcode}, $yesterday );    # Add an overdue
1754
    my $issue = AddIssue( $patron->unblessed, $item_1->barcode, $yesterday );    # Add an overdue
1765
1755
1766
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
1756
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
1767
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1757
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1768
    is( keys(%$error) + keys(%$alerts),  0, 'No key for error and alert' . str($error, $question, $alerts) );
1758
    is( keys(%$error) + keys(%$alerts),  0, 'No key for error and alert' . str($error, $question, $alerts) );
1769
    is( $question->{USERBLOCKEDOVERDUE}, 1, 'OverduesBlockCirc=confirmation, USERBLOCKEDOVERDUE should be set for question' );
1759
    is( $question->{USERBLOCKEDOVERDUE}, 1, 'OverduesBlockCirc=confirmation, USERBLOCKEDOVERDUE should be set for question' );
1770
1760
1771
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' );
1761
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' );
1772
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1762
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1773
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . str($error, $question, $alerts) );
1763
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . str($error, $question, $alerts) );
1774
    is( $error->{USERBLOCKEDOVERDUE},      1, 'OverduesBlockCirc=block, USERBLOCKEDOVERDUE should be set for error' );
1764
    is( $error->{USERBLOCKEDOVERDUE},      1, 'OverduesBlockCirc=block, USERBLOCKEDOVERDUE should be set for error' );
1775
1765
1776
    # Patron cannot issue item_1, they are debarred
1766
    # Patron cannot issue item_1, they are debarred
1777
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
1767
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
1778
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->borrowernumber, expiration => $tomorrow } );
1768
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->borrowernumber, expiration => $tomorrow } );
1779
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1769
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1780
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . str($error, $question, $alerts) );
1770
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . str($error, $question, $alerts) );
1781
    is( $error->{USERBLOCKEDWITHENDDATE}, output_pref( { dt => $tomorrow, dateformat => 'sql', dateonly => 1 } ), 'USERBLOCKEDWITHENDDATE should be tomorrow' );
1771
    is( $error->{USERBLOCKEDWITHENDDATE}, output_pref( { dt => $tomorrow, dateformat => 'sql', dateonly => 1 } ), 'USERBLOCKEDWITHENDDATE should be tomorrow' );
1782
1772
1783
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->borrowernumber } );
1773
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->borrowernumber } );
1784
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1774
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1785
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . str($error, $question, $alerts) );
1775
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . str($error, $question, $alerts) );
1786
    is( $error->{USERBLOCKEDNOENDDATE},    '9999-12-31', 'USERBLOCKEDNOENDDATE should be 9999-12-31 for unlimited debarments' );
1776
    is( $error->{USERBLOCKEDNOENDDATE},    '9999-12-31', 'USERBLOCKEDNOENDDATE should be 9999-12-31 for unlimited debarments' );
1787
};
1777
};
Lines 1812-1820 subtest 'CanBookBeIssued + Statistic patrons "X"' => sub { Link Here
1812
        {
1802
        {
1813
            library => $library->{branchcode},
1803
            library => $library->{branchcode},
1814
        }
1804
        }
1815
    )->unblessed;
1805
    );
1816
1806
1817
    my ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_1->{barcode} );
1807
    my ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_1->barcode );
1818
    is( $error->{STATS}, 1, '"Error" flag "STATS" must be set if CanBookBeIssued is called with a statistic patron (category_type=X)' );
1808
    is( $error->{STATS}, 1, '"Error" flag "STATS" must be set if CanBookBeIssued is called with a statistic patron (category_type=X)' );
1819
1809
1820
    # TODO There are other tests to provide here
1810
    # TODO There are other tests to provide here
Lines 1944-1963 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1944
            biblionumber => $biblionumber,
1934
            biblionumber => $biblionumber,
1945
            library      => $library->{branchcode},
1935
            library      => $library->{branchcode},
1946
        }
1936
        }
1947
    )->unblessed;
1937
    );
1948
1938
1949
    my $item_2 = $builder->build_sample_item(
1939
    my $item_2 = $builder->build_sample_item(
1950
        {
1940
        {
1951
            biblionumber => $biblionumber,
1941
            biblionumber => $biblionumber,
1952
            library      => $library->{branchcode},
1942
            library      => $library->{branchcode},
1953
        }
1943
        }
1954
    )->unblessed;
1944
    );
1955
1945
1956
    my ( $error, $question, $alerts );
1946
    my ( $error, $question, $alerts );
1957
    my $issue = AddIssue( $patron->unblessed, $item_1->{barcode}, dt_from_string->add( days => 1 ) );
1947
    my $issue = AddIssue( $patron->unblessed, $item_1->barcode, dt_from_string->add( days => 1 ) );
1958
1948
1959
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1949
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1960
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1950
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1961
    cmp_deeply(
1951
    cmp_deeply(
1962
        { error => $error, alerts => $alerts },
1952
        { error => $error, alerts => $alerts },
1963
        { error => {}, alerts => {} },
1953
        { error => {}, alerts => {} },
Lines 1966-1972 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1966
    is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' );
1956
    is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' );
1967
1957
1968
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1958
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1969
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1959
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1970
    cmp_deeply(
1960
    cmp_deeply(
1971
        { error => $error, question => $question, alerts => $alerts },
1961
        { error => $error, question => $question, alerts => $alerts },
1972
        { error => {}, question => {}, alerts => {} },
1962
        { error => {}, question => {}, alerts => {} },
Lines 1977-1983 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1977
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1967
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1978
1968
1979
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1969
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1980
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1970
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1981
    cmp_deeply(
1971
    cmp_deeply(
1982
        { error => $error, question => $question, alerts => $alerts },
1972
        { error => $error, question => $question, alerts => $alerts },
1983
        { error => {}, question => {}, alerts => {} },
1973
        { error => {}, question => {}, alerts => {} },
Lines 1985-1991 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1985
    );
1975
    );
1986
1976
1987
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1977
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1988
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1978
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
1989
    cmp_deeply(
1979
    cmp_deeply(
1990
        { error => $error, question => $question, alerts => $alerts },
1980
        { error => $error, question => $question, alerts => $alerts },
1991
        { error => {}, question => {}, alerts => {} },
1981
        { error => {}, question => {}, alerts => {} },
Lines 2010-2022 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2010
            biblionumber => $biblionumber,
2000
            biblionumber => $biblionumber,
2011
            library      => $library->{branchcode},
2001
            library      => $library->{branchcode},
2012
        }
2002
        }
2013
    )->unblessed;
2003
    );
2014
    my $item_2 = $builder->build_sample_item(
2004
    my $item_2 = $builder->build_sample_item(
2015
        {
2005
        {
2016
            biblionumber => $biblionumber,
2006
            biblionumber => $biblionumber,
2017
            library      => $library->{branchcode},
2007
            library      => $library->{branchcode},
2018
        }
2008
        }
2019
    )->unblessed;
2009
    );
2020
2010
2021
    # And the circulation rule
2011
    # And the circulation rule
2022
    Koha::CirculationRules->search->delete;
2012
    Koha::CirculationRules->search->delete;
Lines 2038-2049 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2038
    my $now = dt_from_string;
2028
    my $now = dt_from_string;
2039
    my $five_days_ago = $now->clone->subtract( days => 5 );
2029
    my $five_days_ago = $now->clone->subtract( days => 5 );
2040
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2030
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2041
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
2031
    AddIssue( $patron, $item_1->barcode, $five_days_ago );    # Add an overdue
2042
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
2032
    AddIssue( $patron, $item_2->barcode, $ten_days_ago )
2043
      ;    # Add another overdue
2033
      ;    # Add another overdue
2044
2034
2045
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
2035
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
2046
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, $now );
2036
    AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2047
    my $debarments = Koha::Patron::Debarments::GetDebarments(
2037
    my $debarments = Koha::Patron::Debarments::GetDebarments(
2048
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2038
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2049
    is( scalar(@$debarments), 1 );
2039
    is( scalar(@$debarments), 1 );
Lines 2059-2065 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2059
    );
2049
    );
2060
    is( $debarments->[0]->{expiration}, $expected_expiration );
2050
    is( $debarments->[0]->{expiration}, $expected_expiration );
2061
2051
2062
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, $now );
2052
    AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now );
2063
    $debarments = Koha::Patron::Debarments::GetDebarments(
2053
    $debarments = Koha::Patron::Debarments::GetDebarments(
2064
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2054
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2065
    is( scalar(@$debarments), 1 );
2055
    is( scalar(@$debarments), 1 );
Lines 2076-2085 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2076
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2066
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2077
2067
2078
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' );
2068
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' );
2079
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
2069
    AddIssue( $patron, $item_1->barcode, $five_days_ago );    # Add an overdue
2080
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
2070
    AddIssue( $patron, $item_2->barcode, $ten_days_ago )
2081
      ;    # Add another overdue
2071
      ;    # Add another overdue
2082
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, $now );
2072
    AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2083
    $debarments = Koha::Patron::Debarments::GetDebarments(
2073
    $debarments = Koha::Patron::Debarments::GetDebarments(
2084
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2074
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2085
    is( scalar(@$debarments), 1 );
2075
    is( scalar(@$debarments), 1 );
Lines 2092-2098 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2092
    );
2082
    );
2093
    is( $debarments->[0]->{expiration}, $expected_expiration );
2083
    is( $debarments->[0]->{expiration}, $expected_expiration );
2094
2084
2095
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, $now );
2085
    AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now );
2096
    $debarments = Koha::Patron::Debarments::GetDebarments(
2086
    $debarments = Koha::Patron::Debarments::GetDebarments(
2097
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2087
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2098
    is( scalar(@$debarments), 1 );
2088
    is( scalar(@$debarments), 1 );
Lines 2122-2128 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2122
            biblionumber => $biblionumber,
2112
            biblionumber => $biblionumber,
2123
            library      => $library->{branchcode},
2113
            library      => $library->{branchcode},
2124
        }
2114
        }
2125
    )->unblessed;
2115
    );
2126
2116
2127
    # And the issuing rule
2117
    # And the issuing rule
2128
    Koha::CirculationRules->search->delete;
2118
    Koha::CirculationRules->search->delete;
Lines 2336-2352 subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { Link Here
2336
        {
2326
        {
2337
            library      => $library->branchcode,
2327
            library      => $library->branchcode,
2338
        }
2328
        }
2339
    )->unblessed;
2329
    );
2340
2330
2341
    my ( $error, $question, $alerts );
2331
    my ( $error, $question, $alerts );
2342
    my $issue = AddIssue( $patron1->unblessed, $item->{barcode} );
2332
    my $issue = AddIssue( $patron1->unblessed, $item->barcode );
2343
2333
2344
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
2334
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
2345
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->{barcode} );
2335
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->barcode );
2346
    is( $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER question flag should be set if AutoReturnCheckedOutItems is disabled and item is checked out to another' );
2336
    is( $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER question flag should be set if AutoReturnCheckedOutItems is disabled and item is checked out to another' );
2347
2337
2348
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 1);
2338
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 1);
2349
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->{barcode} );
2339
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->barcode );
2350
    is( $alerts->{RETURNED_FROM_ANOTHER}->{patron}->borrowernumber, $patron1->borrowernumber, 'RETURNED_FROM_ANOTHER alert flag should be set if AutoReturnCheckedOutItems is enabled and item is checked out to another' );
2340
    is( $alerts->{RETURNED_FROM_ANOTHER}->{patron}->borrowernumber, $patron1->borrowernumber, 'RETURNED_FROM_ANOTHER alert flag should be set if AutoReturnCheckedOutItems is enabled and item is checked out to another' );
2351
2341
2352
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
2342
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
Lines 2371-2377 subtest 'AddReturn | is_overdue' => sub { Link Here
2371
            library      => $library->{branchcode},
2361
            library      => $library->{branchcode},
2372
            replacementprice => 7
2362
            replacementprice => 7
2373
        }
2363
        }
2374
    )->unblessed;
2364
    );
2375
2365
2376
    Koha::CirculationRules->search->delete;
2366
    Koha::CirculationRules->search->delete;
2377
    Koha::CirculationRules->set_rules(
2367
    Koha::CirculationRules->set_rules(
Lines 2396-2421 subtest 'AddReturn | is_overdue' => sub { Link Here
2396
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2386
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2397
2387
2398
    # No return date specified, today will be used => 10 days overdue charged
2388
    # No return date specified, today will be used => 10 days overdue charged
2399
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2389
    AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago
2400
    AddReturn( $item->{barcode}, $library->{branchcode} );
2390
    AddReturn( $item->barcode, $library->{branchcode} );
2401
    is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' );
2391
    is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' );
2402
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2392
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2403
2393
2404
    # specify return date 5 days before => no overdue charged
2394
    # specify return date 5 days before => no overdue charged
2405
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
2395
    AddIssue( $patron->unblessed, $item->barcode, $five_days_ago ); # date due was 5d ago
2406
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $ten_days_ago );
2396
    AddReturn( $item->barcode, $library->{branchcode}, undef, $ten_days_ago );
2407
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2397
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2408
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2398
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2409
2399
2410
    # specify return date 5 days later => 5 days overdue charged
2400
    # specify return date 5 days later => 5 days overdue charged
2411
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2401
    AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago
2412
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $five_days_ago );
2402
    AddReturn( $item->barcode, $library->{branchcode}, undef, $five_days_ago );
2413
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
2403
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
2414
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2404
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2415
2405
2416
    # specify return date 5 days later, specify exemptfine => no overdue charge
2406
    # specify return date 5 days later, specify exemptfine => no overdue charge
2417
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2407
    AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago
2418
    AddReturn( $item->{barcode}, $library->{branchcode}, 1, $five_days_ago );
2408
    AddReturn( $item->barcode, $library->{branchcode}, 1, $five_days_ago );
2419
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2409
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2420
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2410
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2421
2411
Lines 2423-2429 subtest 'AddReturn | is_overdue' => sub { Link Here
2423
2413
2424
        plan tests => 3;
2414
        plan tests => 3;
2425
2415
2426
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago );    # date due was 10d ago
2416
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago );    # date due was 10d ago
2427
2417
2428
        # Fake fines cronjob on this checkout
2418
        # Fake fines cronjob on this checkout
2429
        my ($fine) =
2419
        my ($fine) =
Lines 2432-2438 subtest 'AddReturn | is_overdue' => sub { Link Here
2432
        UpdateFine(
2422
        UpdateFine(
2433
            {
2423
            {
2434
                issue_id       => $issue->issue_id,
2424
                issue_id       => $issue->issue_id,
2435
                itemnumber     => $item->{itemnumber},
2425
                itemnumber     => $item->itemnumber,
2436
                borrowernumber => $patron->borrowernumber,
2426
                borrowernumber => $patron->borrowernumber,
2437
                amount         => $fine,
2427
                amount         => $fine,
2438
                due            => output_pref($ten_days_ago)
2428
                due            => output_pref($ten_days_ago)
Lines 2442-2453 subtest 'AddReturn | is_overdue' => sub { Link Here
2442
            10, "Overdue fine of 10 days overdue" );
2432
            10, "Overdue fine of 10 days overdue" );
2443
2433
2444
        # Fake longoverdue with charge and not marking returned
2434
        # Fake longoverdue with charge and not marking returned
2445
        LostItem( $item->{itemnumber}, 'cronjob', 0 );
2435
        LostItem( $item->itemnumber, 'cronjob', 0 );
2446
        is( int( $patron->account->balance() ),
2436
        is( int( $patron->account->balance() ),
2447
            17, "Lost fine of 7 plus 10 days overdue" );
2437
            17, "Lost fine of 7 plus 10 days overdue" );
2448
2438
2449
        # Now we return it today
2439
        # Now we return it today
2450
        AddReturn( $item->{barcode}, $library->{branchcode} );
2440
        AddReturn( $item->barcode, $library->{branchcode} );
2451
        is( int( $patron->account->balance() ),
2441
        is( int( $patron->account->balance() ),
2452
            17, "Should have a single 10 days overdue fine and lost charge" );
2442
            17, "Should have a single 10 days overdue fine and lost charge" );
2453
2443
Lines 2461-2467 subtest 'AddReturn | is_overdue' => sub { Link Here
2461
2451
2462
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2452
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2463
2453
2464
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $one_day_ago );    # date due was 1d ago
2454
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $one_day_ago );    # date due was 1d ago
2465
2455
2466
        # Fake fines cronjob on this checkout
2456
        # Fake fines cronjob on this checkout
2467
        my ($fine) =
2457
        my ($fine) =
Lines 2470-2476 subtest 'AddReturn | is_overdue' => sub { Link Here
2470
        UpdateFine(
2460
        UpdateFine(
2471
            {
2461
            {
2472
                issue_id       => $issue->issue_id,
2462
                issue_id       => $issue->issue_id,
2473
                itemnumber     => $item->{itemnumber},
2463
                itemnumber     => $item->itemnumber,
2474
                borrowernumber => $patron->borrowernumber,
2464
                borrowernumber => $patron->borrowernumber,
2475
                amount         => $fine,
2465
                amount         => $fine,
2476
                due            => output_pref($one_day_ago)
2466
                due            => output_pref($one_day_ago)
Lines 2480-2492 subtest 'AddReturn | is_overdue' => sub { Link Here
2480
            1, "Overdue fine of 1 day overdue" );
2470
            1, "Overdue fine of 1 day overdue" );
2481
2471
2482
        # Backdated return (dropbox mode example - charge should be removed)
2472
        # Backdated return (dropbox mode example - charge should be removed)
2483
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2473
        AddReturn( $item->barcode, $library->{branchcode}, 1, $one_day_ago );
2484
        is( int( $patron->account->balance() ),
2474
        is( int( $patron->account->balance() ),
2485
            0, "Overdue fine should be annulled" );
2475
            0, "Overdue fine should be annulled" );
2486
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2476
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2487
        is( $lines->count, 0, "Overdue fine accountline has been removed");
2477
        is( $lines->count, 0, "Overdue fine accountline has been removed");
2488
2478
2489
        $issue = AddIssue( $patron->unblessed, $item->{barcode}, $two_days_ago );    # date due was 2d ago
2479
        $issue = AddIssue( $patron->unblessed, $item->barcode, $two_days_ago );    # date due was 2d ago
2490
2480
2491
        # Fake fines cronjob on this checkout
2481
        # Fake fines cronjob on this checkout
2492
        ($fine) =
2482
        ($fine) =
Lines 2495-2501 subtest 'AddReturn | is_overdue' => sub { Link Here
2495
        UpdateFine(
2485
        UpdateFine(
2496
            {
2486
            {
2497
                issue_id       => $issue->issue_id,
2487
                issue_id       => $issue->issue_id,
2498
                itemnumber     => $item->{itemnumber},
2488
                itemnumber     => $item->itemnumber,
2499
                borrowernumber => $patron->borrowernumber,
2489
                borrowernumber => $patron->borrowernumber,
2500
                amount         => $fine,
2490
                amount         => $fine,
2501
                due            => output_pref($one_day_ago)
2491
                due            => output_pref($one_day_ago)
Lines 2526-2532 subtest 'AddReturn | is_overdue' => sub { Link Here
2526
        is( $line->amountoutstanding+0, 0, "Overdue fine amountoutstanding reduced to 0");
2516
        is( $line->amountoutstanding+0, 0, "Overdue fine amountoutstanding reduced to 0");
2527
2517
2528
        # Backdated return (dropbox mode example - charge should be removed)
2518
        # Backdated return (dropbox mode example - charge should be removed)
2529
        AddReturn( $item->{barcode}, $library->{branchcode}, undef, $one_day_ago );
2519
        AddReturn( $item->barcode, $library->{branchcode}, undef, $one_day_ago );
2530
        is( int( $patron->account->balance() ),
2520
        is( int( $patron->account->balance() ),
2531
            -1, "Refund credit has been applied" );
2521
            -1, "Refund credit has been applied" );
2532
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber }, { order_by => { '-asc' => 'accountlines_id' }});
2522
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber }, { order_by => { '-asc' => 'accountlines_id' }});
Lines 2553-2559 subtest 'AddReturn | is_overdue' => sub { Link Here
2553
2543
2554
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2544
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2555
2545
2556
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $one_day_ago );    # date due was 1d ago
2546
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $one_day_ago );    # date due was 1d ago
2557
2547
2558
        # Fake fines cronjob on this checkout
2548
        # Fake fines cronjob on this checkout
2559
        my ($fine) =
2549
        my ($fine) =
Lines 2562-2568 subtest 'AddReturn | is_overdue' => sub { Link Here
2562
        UpdateFine(
2552
        UpdateFine(
2563
            {
2553
            {
2564
                issue_id       => $issue->issue_id,
2554
                issue_id       => $issue->issue_id,
2565
                itemnumber     => $item->{itemnumber},
2555
                itemnumber     => $item->itemnumber,
2566
                borrowernumber => $patron->borrowernumber,
2556
                borrowernumber => $patron->borrowernumber,
2567
                amount         => $fine,
2557
                amount         => $fine,
2568
                due            => output_pref($one_day_ago)
2558
                due            => output_pref($one_day_ago)
Lines 2572-2578 subtest 'AddReturn | is_overdue' => sub { Link Here
2572
            1, "Overdue fine of 1 day overdue" );
2562
            1, "Overdue fine of 1 day overdue" );
2573
2563
2574
        # Backdated return (dropbox mode example - charge should no longer exist)
2564
        # Backdated return (dropbox mode example - charge should no longer exist)
2575
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2565
        AddReturn( $item->barcode, $library->{branchcode}, 1, $one_day_ago );
2576
        is( int( $patron->account->balance() ),
2566
        is( int( $patron->account->balance() ),
2577
            0, "Overdue fine should be annulled" );
2567
            0, "Overdue fine should be annulled" );
2578
2568
Lines 2586-2598 subtest 'AddReturn | is_overdue' => sub { Link Here
2586
        t::lib::Mocks::mock_preference( 'CalculateFinesOnBackdate', 1 );
2576
        t::lib::Mocks::mock_preference( 'CalculateFinesOnBackdate', 1 );
2587
2577
2588
        my $due_date = dt_from_string;
2578
        my $due_date = dt_from_string;
2589
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $due_date );
2579
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $due_date );
2590
2580
2591
        # Add fine
2581
        # Add fine
2592
        UpdateFine(
2582
        UpdateFine(
2593
            {
2583
            {
2594
                issue_id       => $issue->issue_id,
2584
                issue_id       => $issue->issue_id,
2595
                itemnumber     => $item->{itemnumber},
2585
                itemnumber     => $item->itemnumber,
2596
                borrowernumber => $patron->borrowernumber,
2586
                borrowernumber => $patron->borrowernumber,
2597
                amount         => 0.25,
2587
                amount         => 0.25,
2598
                due            => output_pref($due_date)
2588
                due            => output_pref($due_date)
Lines 2603-2609 subtest 'AddReturn | is_overdue' => sub { Link Here
2603
2593
2604
        # Backdate return to exact due date and time
2594
        # Backdate return to exact due date and time
2605
        my ( undef, $message ) =
2595
        my ( undef, $message ) =
2606
          AddReturn( $item->{barcode}, $library->{branchcode},
2596
          AddReturn( $item->barcode, $library->{branchcode},
2607
            undef, $due_date );
2597
            undef, $due_date );
2608
2598
2609
        my $accountline =
2599
        my $accountline =
Lines 2611-2623 subtest 'AddReturn | is_overdue' => sub { Link Here
2611
        ok( !$accountline, 'accountline removed as expected' );
2601
        ok( !$accountline, 'accountline removed as expected' );
2612
2602
2613
        # Re-issue
2603
        # Re-issue
2614
        $issue = AddIssue( $patron->unblessed, $item->{barcode}, $due_date );
2604
        $issue = AddIssue( $patron->unblessed, $item->barcode, $due_date );
2615
2605
2616
        # Add fine
2606
        # Add fine
2617
        UpdateFine(
2607
        UpdateFine(
2618
            {
2608
            {
2619
                issue_id       => $issue->issue_id,
2609
                issue_id       => $issue->issue_id,
2620
                itemnumber     => $item->{itemnumber},
2610
                itemnumber     => $item->itemnumber,
2621
                borrowernumber => $patron->borrowernumber,
2611
                borrowernumber => $patron->borrowernumber,
2622
                amount         => .25,
2612
                amount         => .25,
2623
                due            => output_pref($due_date)
2613
                due            => output_pref($due_date)
Lines 2647-2653 subtest 'AddReturn | is_overdue' => sub { Link Here
2647
2637
2648
        # Backdate return to exact due date and time
2638
        # Backdate return to exact due date and time
2649
        ( undef, $message ) =
2639
        ( undef, $message ) =
2650
          AddReturn( $item->{barcode}, $library->{branchcode},
2640
          AddReturn( $item->barcode, $library->{branchcode},
2651
            undef, $due_date );
2641
            undef, $due_date );
2652
2642
2653
        $lines = Koha::Account::Lines->search(
2643
        $lines = Koha::Account::Lines->search(
Lines 2766-2811 subtest 'Set waiting flag' => sub { Link Here
2766
        {
2756
        {
2767
            library      => $library_1->{branchcode},
2757
            library      => $library_1->{branchcode},
2768
        }
2758
        }
2769
    )->unblessed;
2759
    );
2770
2760
2771
    set_userenv( $library_2 );
2761
    set_userenv( $library_2 );
2772
    my $reserve_id = AddReserve(
2762
    my $reserve_id = AddReserve(
2773
        {
2763
        {
2774
            branchcode     => $library_2->{branchcode},
2764
            branchcode     => $library_2->{branchcode},
2775
            borrowernumber => $patron_2->{borrowernumber},
2765
            borrowernumber => $patron_2->{borrowernumber},
2776
            biblionumber   => $item->{biblionumber},
2766
            biblionumber   => $item->biblionumber,
2777
            priority       => 1,
2767
            priority       => 1,
2778
            itemnumber     => $item->{itemnumber},
2768
            itemnumber     => $item->itemnumber,
2779
        }
2769
        }
2780
    );
2770
    );
2781
2771
2782
    set_userenv( $library_1 );
2772
    set_userenv( $library_1 );
2783
    my $do_transfer = 1;
2773
    my $do_transfer = 1;
2784
    my ( $res, $rr ) = AddReturn( $item->{barcode}, $library_1->{branchcode} );
2774
    my ( $res, $rr ) = AddReturn( $item->barcode, $library_1->{branchcode} );
2785
    ModReserveAffect( $item->{itemnumber}, undef, $do_transfer, $reserve_id );
2775
    ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id );
2786
    my $hold = Koha::Holds->find( $reserve_id );
2776
    my $hold = Koha::Holds->find( $reserve_id );
2787
    is( $hold->found, 'T', 'Hold is in transit' );
2777
    is( $hold->found, 'T', 'Hold is in transit' );
2788
2778
2789
    my ( $status ) = CheckReserves($item->{itemnumber});
2779
    my ( $status ) = CheckReserves($item->itemnumber);
2790
    is( $status, 'Reserved', 'Hold is not waiting yet');
2780
    is( $status, 'Reserved', 'Hold is not waiting yet');
2791
2781
2792
    set_userenv( $library_2 );
2782
    set_userenv( $library_2 );
2793
    $do_transfer = 0;
2783
    $do_transfer = 0;
2794
    AddReturn( $item->{barcode}, $library_2->{branchcode} );
2784
    AddReturn( $item->barcode, $library_2->{branchcode} );
2795
    ModReserveAffect( $item->{itemnumber}, undef, $do_transfer, $reserve_id );
2785
    ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id );
2796
    $hold = Koha::Holds->find( $reserve_id );
2786
    $hold = Koha::Holds->find( $reserve_id );
2797
    is( $hold->found, 'W', 'Hold is waiting' );
2787
    is( $hold->found, 'W', 'Hold is waiting' );
2798
    ( $status ) = CheckReserves($item->{itemnumber});
2788
    ( $status ) = CheckReserves($item->itemnumber);
2799
    is( $status, 'Waiting', 'Now the hold is waiting');
2789
    is( $status, 'Waiting', 'Now the hold is waiting');
2800
2790
2801
    #Bug 21944 - Waiting transfer checked in at branch other than pickup location
2791
    #Bug 21944 - Waiting transfer checked in at branch other than pickup location
2802
    set_userenv( $library_1 );
2792
    set_userenv( $library_1 );
2803
    (undef, my $messages, undef, undef ) = AddReturn ( $item->{barcode}, $library_1->{branchcode} );
2793
    (undef, my $messages, undef, undef ) = AddReturn ( $item->barcode, $library_1->{branchcode} );
2804
    $hold = Koha::Holds->find( $reserve_id );
2794
    $hold = Koha::Holds->find( $reserve_id );
2805
    is( $hold->found, undef, 'Hold is no longer marked waiting' );
2795
    is( $hold->found, undef, 'Hold is no longer marked waiting' );
2806
    is( $hold->priority, 1,  "Hold is now priority one again");
2796
    is( $hold->priority, 1,  "Hold is now priority one again");
2807
    is( $hold->waitingdate, undef, "Hold no longer has a waiting date");
2797
    is( $hold->waitingdate, undef, "Hold no longer has a waiting date");
2808
    is( $hold->itemnumber, $item->{itemnumber}, "Hold has retained its' itemnumber");
2798
    is( $hold->itemnumber, $item->itemnumber, "Hold has retained its' itemnumber");
2809
    is( $messages->{ResFound}->{ResFound}, "Reserved", "Hold is still returned");
2799
    is( $messages->{ResFound}->{ResFound}, "Reserved", "Hold is still returned");
2810
    is( $messages->{ResFound}->{found}, undef, "Hold is no longer marked found in return message");
2800
    is( $messages->{ResFound}->{found}, undef, "Hold is no longer marked found in return message");
2811
    is( $messages->{ResFound}->{priority}, 1, "Hold is priority 1 in return message");
2801
    is( $messages->{ResFound}->{priority}, 1, "Hold is priority 1 in return message");
Lines 2898-2909 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
2898
        {
2888
        {
2899
            library      => $library->{branchcode},
2889
            library      => $library->{branchcode},
2900
        }
2890
        }
2901
    )->unblessed;
2891
    );
2902
2892
2903
    my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $five_days_go ); # date due was 10d ago
2893
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $five_days_go ); # date due was 10d ago
2904
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
2894
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
2905
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), $five_days_go, "First issue works");
2895
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), $five_days_go, "First issue works");
2906
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef);
2896
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->barcode,$ten_days_go, undef, undef, undef);
2907
    is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal");
2897
    is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal");
2908
    is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal");
2898
    is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal");
2909
};
2899
};
Lines 3524-3543 subtest 'CanBookBeIssued & RentalFeesCheckoutConfirmation' => sub { Link Here
3524
        }
3514
        }
3525
    );
3515
    );
3526
3516
3527
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
3517
    my $item = $builder->build_sample_item(
3528
    my $item = $builder->build_object(
3529
        {
3518
        {
3530
            class => 'Koha::Items',
3519
            library    => $library->id,
3531
            value  => {
3520
            notforloan => 0,
3532
                homebranch    => $library->id,
3521
            itemlost   => 0,
3533
                holdingbranch => $library->id,
3522
            withdrawn  => 0,
3534
                notforloan    => 0,
3523
            itype      => $itemtype->id,
3535
                itemlost      => 0,
3536
                withdrawn     => 0,
3537
                itype         => $itemtype->id,
3538
                biblionumber  => $biblioitem->{biblionumber},
3539
                biblioitemnumber => $biblioitem->{biblioitemnumber},
3540
            }
3541
        }
3524
        }
3542
    )->store;
3525
    )->store;
3543
3526
(-)a/t/db_dependent/Circulation/CalcFine.t (-26 / +18 lines)
Lines 44-58 my $patron = $builder->build( Link Here
44
    }
44
    }
45
);
45
);
46
46
47
my $biblio = $builder->build(
48
    {
49
        source => 'Biblio',
50
        value  => {
51
            branchcode => $branch->{branchcode},
52
        },
53
    }
54
);
55
56
my $itemtype = $builder->build(
47
my $itemtype = $builder->build(
57
    {
48
    {
58
        source => 'Itemtype',
49
        source => 'Itemtype',
Lines 62-77 my $itemtype = $builder->build( Link Here
62
    }
53
    }
63
);
54
);
64
55
65
my $item = $builder->build(
56
my $item = $builder->build_sample_item(
66
    {
57
    {
67
        source => 'Item',
58
        library          => $branch->{branchcode},
68
        value  => {
59
        replacementprice => '5.00',
69
            biblionumber     => $biblio->{biblionumber},
60
        itype            => $itemtype->{itemtype},
70
            homebranch       => $branch->{branchcode},
71
            holdingbranch    => $branch->{branchcode},
72
            replacementprice => '5.00',
73
            itype            => $itemtype->{itemtype},
74
        },
75
    }
61
    }
76
);
62
);
77
63
Lines 107-113 subtest 'Test basic functionality' => sub { Link Here
107
        day        => 30,
93
        day        => 30,
108
    );
94
    );
109
95
110
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
96
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
111
97
112
    is( $amount, 29, 'Amount is calculated correctly' );
98
    is( $amount, 29, 'Amount is calculated correctly' );
113
99
Lines 147-161 subtest 'Test cap_fine_to_replacement_price' => sub { Link Here
147
        day        => 30,
133
        day        => 30,
148
    );
134
    );
149
135
150
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
136
    my $item = $builder->build_sample_item(
137
        {
138
            library          => $branch->{branchcode},
139
            replacementprice => 5,
140
            itype            => $itemtype->{itemtype},
141
        }
142
    );
151
143
152
    is( int($amount), 5, 'Amount is calculated correctly' );
144
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
153
145
146
    is( int($amount), 5, 'Amount is calculated correctly' );
154
147
155
    # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0
148
    # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0
156
    my $item_obj = Koha::Items->find($item->{itemnumber});
149
    $item->replacementprice(0)->store;
157
    $item_obj->replacementprice(0)->store;
150
    ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
158
    ($amount) = CalcFine( $item_obj->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
159
    is( int($amount), 6, 'Amount is calculated correctly' );
151
    is( int($amount), 6, 'Amount is calculated correctly' );
160
152
161
    teardown();
153
    teardown();
Lines 194-204 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { Link Here
194
        day        => 30,
186
        day        => 30,
195
    );
187
    );
196
188
197
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
189
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
198
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
190
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
199
191
200
    Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, categorycode => undef, itemtype => undef });
192
    Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, categorycode => undef, itemtype => undef });
201
    ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
193
    ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
202
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
194
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
203
195
204
    teardown();
196
    teardown();
(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-33 / +9 lines)
Lines 48-64 subtest 'Failure tests' => sub { Link Here
48
            value => { branchcode => $library->branchcode, categorycode => $category->categorycode }
48
            value => { branchcode => $library->branchcode, categorycode => $category->categorycode }
49
        }
49
        }
50
    );
50
    );
51
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
51
    my $item = $builder->build_sample_item(
52
    my $item       = $builder->build_object(
52
        {
53
        {   class => 'Koha::Items',
53
            library => $library->branchcode,
54
            value  => {
55
                homebranch    => $library->branchcode,
56
                holdingbranch => $library->branchcode,
57
                notforloan    => 0,
58
                itemlost      => 0,
59
                withdrawn     => 0,
60
                biblionumber  => $biblioitem->biblionumber,
61
            }
62
        }
54
        }
63
    );
55
    );
64
56
Lines 95-111 subtest 'Anonymous patron tests' => sub { Link Here
95
            value => { branchcode => $library->branchcode, categorycode => $category->categorycode }
87
            value => { branchcode => $library->branchcode, categorycode => $category->categorycode }
96
        }
88
        }
97
    );
89
    );
98
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
90
    my $item = $builder->build_sample_item(
99
    my $item       = $builder->build_object(
91
        {
100
        {   class => 'Koha::Items',
92
            library => $library->branchcode,
101
            value  => {
102
                homebranch    => $library->branchcode,
103
                holdingbranch => $library->branchcode,
104
                notforloan    => 0,
105
                itemlost      => 0,
106
                withdrawn     => 0,
107
                biblionumber  => $biblioitem->biblionumber,
108
            }
109
        }
93
        }
110
    );
94
    );
111
95
Lines 149-165 subtest 'Manually pass a return date' => sub { Link Here
149
            value => { branchcode => $library->branchcode, categorycode => $category->categorycode }
133
            value => { branchcode => $library->branchcode, categorycode => $category->categorycode }
150
        }
134
        }
151
    );
135
    );
152
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
136
    my $item = $builder->build_sample_item(
153
    my $item       = $builder->build_object(
137
        {
154
        {   class => 'Koha::Items',
138
            library => $library->branchcode,
155
            value  => {
156
                homebranch    => $library->branchcode,
157
                holdingbranch => $library->branchcode,
158
                notforloan    => 0,
159
                itemlost      => 0,
160
                withdrawn     => 0,
161
                biblionumber  => $biblioitem->biblionumber,
162
            }
163
        }
139
        }
164
    );
140
    );
165
141
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-12 / +3 lines)
Lines 33-48 $schema->storage->txn_begin; Link Here
33
33
34
my $builder = t::lib::TestBuilder->new();
34
my $builder = t::lib::TestBuilder->new();
35
35
36
my $item = $builder->build(
36
my $item = $builder->build_sample_item;
37
    {
38
        source => 'Item',
39
        value  => {
40
            biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber},
41
            notforloan => 0,
42
            withdrawn  => 0
43
        }
44
    }
45
);
46
37
47
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
38
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
48
my $patron = $builder->build_object(
39
my $patron = $builder->build_object(
Lines 77-88 my $r = $builder->build_object( Link Here
77
t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees', '5.00' );
68
t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees', '5.00' );
78
t::lib::Mocks::mock_preference( 'AllowFineOverride', '' );
69
t::lib::Mocks::mock_preference( 'AllowFineOverride', '' );
79
70
80
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
71
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode );
81
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
72
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
82
73
83
my $account = Koha::Account->new( { patron_id => $guarantee->id } );
74
my $account = Koha::Account->new( { patron_id => $guarantee->id } );
84
$account->add_debit({ amount => 10.00, type => 'LOST', interface => 'test' });
75
$account->add_debit({ amount => 10.00, type => 'LOST', interface => 'test' });
85
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
76
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode );
86
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
77
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
87
78
88
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
79
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
(-)a/t/db_dependent/Circulation/ReturnClaims.t (-24 / +2 lines)
Lines 62-79 subtest 'Test Koha::Checkout::claim_returned' => sub { Link Here
62
    plan tests => 6;
62
    plan tests => 6;
63
63
64
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
64
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
65
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
65
    my $item   = $builder->build_sample_item;
66
    my $item   = $builder->build_object(
67
        {
68
            class => 'Koha::Items',
69
            value => {
70
                biblionumber => $biblio->biblionumber,
71
                notforloan   => 0,
72
                itemlost     => 0,
73
                withdrawn    => 0,
74
            }
75
        }
76
    );
77
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
66
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
78
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
67
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
79
68
Lines 96-113 subtest 'Test Koha::Patronn::return_claims' => sub { Link Here
96
    plan tests => 7;
85
    plan tests => 7;
97
86
98
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
87
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
99
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
88
    my $item   = $builder->build_sample_item;
100
    my $item   = $builder->build_object(
101
        {
102
            class => 'Koha::Items',
103
            value => {
104
                biblionumber => $biblio->biblionumber,
105
                notforloan   => 0,
106
                itemlost     => 0,
107
                withdrawn    => 0,
108
            }
109
        }
110
    );
111
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
89
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
112
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
90
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
113
91
(-)a/t/db_dependent/Circulation/Returns.t (-108 / +40 lines)
Lines 104-156 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
104
        MARC::Field->new($tagfield,'','', $tagsubfield => $blevel_itemtype )
104
        MARC::Field->new($tagfield,'','', $tagsubfield => $blevel_itemtype )
105
    );
105
    );
106
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
106
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
107
    my $item_with_itemtype = $builder->build(
107
    my $item_with_itemtype = $builder->build_sample_item(
108
        {
108
        {
109
            source => 'Item',
109
            biblionumber => $biblionumber,
110
            value  => {
110
            library      => $branch,
111
                biblionumber     => $biblionumber,
111
            itype        => $ilevel_itemtype
112
                biblioitemnumber => $biblioitemnumber,
113
                homebranch       => $branch,
114
                holdingbranch    => $branch,
115
                itype            => $ilevel_itemtype
116
            }
117
        }
112
        }
118
    );
113
    );
119
    my $item_without_itemtype = $builder->build(
114
    my $item_without_itemtype = $builder->build_sample_item(
120
        {
115
        {
121
            source => 'Item',
116
            biblionumber => $biblionumber,
122
            value  => {
117
            library      => $branch,
123
                biblionumber     => $biblionumber,
124
                biblioitemnumber => $biblioitemnumber,
125
                homebranch       => $branch,
126
                holdingbranch    => $branch,
127
                itype            => undef
128
            }
129
        }
118
        }
130
    );
119
    )->_result->update({ itype => undef });
131
120
132
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
121
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
133
    AddIssue( $borrower, $item_with_itemtype->{ barcode } );
122
    AddIssue( $borrower, $item_with_itemtype->barcode );
134
    AddReturn( $item_with_itemtype->{ barcode }, $branch );
123
    AddReturn( $item_with_itemtype->barcode, $branch );
135
    # Test item-level itemtype was recorded on the 'statistics' table
124
    # Test item-level itemtype was recorded on the 'statistics' table
136
    my $stat = $schema->resultset('Statistic')->search({
125
    my $stat = $schema->resultset('Statistic')->search({
137
        branch     => $branch,
126
        branch     => $branch,
138
        type       => 'return',
127
        type       => 'return',
139
        itemnumber => $item_with_itemtype->{ itemnumber }
128
        itemnumber => $item_with_itemtype->itemnumber
140
    }, { order_by => { -asc => 'datetime' } })->next();
129
    }, { order_by => { -asc => 'datetime' } })->next();
141
130
142
    is( $stat->itemtype, $ilevel_itemtype,
131
    is( $stat->itemtype, $ilevel_itemtype,
143
        "item-level itype recorded on statistics for return");
132
        "item-level itype recorded on statistics for return");
144
    warning_like { AddIssue( $borrower, $item_without_itemtype->{ barcode } ) }
133
    warning_like { AddIssue( $borrower, $item_without_itemtype->barcode ) }
145
                 [qr/^item-level_itypes set but no itemtype set for item/,
134
                 [qr/^item-level_itypes set but no itemtype set for item/,
146
                 qr/^item-level_itypes set but no itemtype set for item/],
135
                 qr/^item-level_itypes set but no itemtype set for item/],
147
                 'Item without itemtype set raises warning on AddIssue';
136
                 'Item without itemtype set raises warning on AddIssue';
148
    AddReturn( $item_without_itemtype->{ barcode }, $branch );
137
    AddReturn( $item_without_itemtype->barcode, $branch );
149
    # Test biblio-level itemtype was recorded on the 'statistics' table
138
    # Test biblio-level itemtype was recorded on the 'statistics' table
150
    $stat = $schema->resultset('Statistic')->search({
139
    $stat = $schema->resultset('Statistic')->search({
151
        branch     => $branch,
140
        branch     => $branch,
152
        type       => 'return',
141
        type       => 'return',
153
        itemnumber => $item_without_itemtype->{ itemnumber }
142
        itemnumber => $item_without_itemtype->itemnumber
154
    }, { order_by => { -asc => 'datetime' } })->next();
143
    }, { order_by => { -asc => 'datetime' } })->next();
155
144
156
    is( $stat->itemtype, $blevel_itemtype,
145
    is( $stat->itemtype, $blevel_itemtype,
Lines 194-241 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
194
        MARC::Field->new($tagfield,'','', $tagsubfield => $blevel_itemtype )
183
        MARC::Field->new($tagfield,'','', $tagsubfield => $blevel_itemtype )
195
    );
184
    );
196
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
185
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
197
    my $item_with_itemtype = $builder->build({
186
    my $item_with_itemtype = $builder->build_sample_item(
198
        source => 'Item',
187
        {
199
        value  => {
188
            biblionumber => $biblionumber,
200
            biblionumber  => $biblionumber,
189
            library      => $branch,
201
            biblioitemnumber => $biblioitemnumber,
190
            itype        => $ilevel_itemtype
202
            homebranch    => $branch,
203
            holdingbranch => $branch,
204
            itype         => $ilevel_itemtype
205
        }
191
        }
206
    });
192
    );
207
    my $item_without_itemtype = $builder->build({
193
    my $item_without_itemtype = $builder->build_sample_item(
208
        source => 'Item',
194
        {
209
        value  => {
195
            biblionumber => $biblionumber,
210
            biblionumber  => $biblionumber,
196
            library      => $branch,
211
            biblioitemnumber => $biblioitemnumber,
197
            itype        => undef
212
            homebranch    => $branch,
213
            holdingbranch => $branch,
214
            itype         => undef
215
        }
198
        }
216
    });
199
    );
217
200
218
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
201
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
219
202
220
    AddIssue( $borrower, $item_with_itemtype->{ barcode } );
203
    AddIssue( $borrower, $item_with_itemtype->barcode );
221
    AddReturn( $item_with_itemtype->{ barcode }, $branch );
204
    AddReturn( $item_with_itemtype->barcode, $branch );
222
    # Test item-level itemtype was recorded on the 'statistics' table
205
    # Test item-level itemtype was recorded on the 'statistics' table
223
    my $stat = $schema->resultset('Statistic')->search({
206
    my $stat = $schema->resultset('Statistic')->search({
224
        branch     => $branch,
207
        branch     => $branch,
225
        type       => 'return',
208
        type       => 'return',
226
        itemnumber => $item_with_itemtype->{ itemnumber }
209
        itemnumber => $item_with_itemtype->itemnumber
227
    }, { order_by => { -asc => 'datetime' } })->next();
210
    }, { order_by => { -asc => 'datetime' } })->next();
228
211
229
    is( $stat->itemtype, $blevel_itemtype,
212
    is( $stat->itemtype, $blevel_itemtype,
230
        "biblio-level itype recorded on statistics for return");
213
        "biblio-level itype recorded on statistics for return");
231
214
232
    AddIssue( $borrower, $item_without_itemtype->{ barcode } );
215
    AddIssue( $borrower, $item_without_itemtype->barcode );
233
    AddReturn( $item_without_itemtype->{ barcode }, $branch );
216
    AddReturn( $item_without_itemtype->barcode, $branch );
234
    # Test biblio-level itemtype was recorded on the 'statistics' table
217
    # Test biblio-level itemtype was recorded on the 'statistics' table
235
    $stat = $schema->resultset('Statistic')->search({
218
    $stat = $schema->resultset('Statistic')->search({
236
        branch     => $branch,
219
        branch     => $branch,
237
        type       => 'return',
220
        type       => 'return',
238
        itemnumber => $item_without_itemtype->{ itemnumber }
221
        itemnumber => $item_without_itemtype->itemnumber
239
    }, { order_by => { -asc => 'datetime' } })->next();
222
    }, { order_by => { -asc => 'datetime' } })->next();
240
223
241
    is( $stat->itemtype, $blevel_itemtype,
224
    is( $stat->itemtype, $blevel_itemtype,
Lines 261-284 subtest 'Handle ids duplication' => sub { Link Here
261
        }
244
        }
262
    );
245
    );
263
246
264
    my $biblio = $builder->build( { source => 'Biblio' } );
265
    my $itemtype = $builder->build( { source => 'Itemtype', value => { rentalcharge => 5 } } );
247
    my $itemtype = $builder->build( { source => 'Itemtype', value => { rentalcharge => 5 } } );
266
    my $item = $builder->build(
248
    my $item = $builder->build_sample_item(
267
        {
249
        {
268
            source => 'Item',
250
            itype => $itemtype->{itemtype},
269
            value  => {
270
                biblionumber => $biblio->{biblionumber},
271
                notforloan => 0,
272
                itemlost   => 0,
273
                withdrawn  => 0,
274
                itype      => $itemtype->{itemtype},
275
            }
276
        }
251
        }
277
    );
252
    );
278
    my $patron = $builder->build({source => 'Borrower'});
253
    my $patron = $builder->build({source => 'Borrower'});
279
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
254
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
280
255
281
    my $original_checkout = AddIssue( $patron->unblessed, $item->{barcode}, dt_from_string->subtract( days => 50 ) );
256
    my $original_checkout = AddIssue( $patron->unblessed, $item->barcode, dt_from_string->subtract( days => 50 ) );
282
    my $issue_id = $original_checkout->issue_id;
257
    my $issue_id = $original_checkout->issue_id;
283
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
258
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
284
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
259
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
Lines 293-299 subtest 'Handle ids duplication' => sub { Link Here
293
    my ($doreturn, $messages, $new_checkout, $borrower);
268
    my ($doreturn, $messages, $new_checkout, $borrower);
294
    warning_like {
269
    warning_like {
295
        ( $doreturn, $messages, $new_checkout, $borrower ) =
270
        ( $doreturn, $messages, $new_checkout, $borrower ) =
296
          AddReturn( $item->{barcode}, undef, undef, undef, dt_from_string );
271
          AddReturn( $item->barcode, undef, undef, undef, dt_from_string );
297
    }
272
    }
298
    [
273
    [
299
        qr{.*DBD::mysql::st execute failed: Duplicate entry.*},
274
        qr{.*DBD::mysql::st execute failed: Duplicate entry.*},
Lines 313-330 subtest 'Handle ids duplication' => sub { Link Here
313
288
314
subtest 'BlockReturnOfLostItems' => sub {
289
subtest 'BlockReturnOfLostItems' => sub {
315
    plan tests => 4;
290
    plan tests => 4;
316
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
291
    my $item = $builder->build_sample_item;
317
    my $item = $builder->build_object(
318
        {
319
            class  => 'Koha::Items',
320
            value  => {
321
                biblionumber => $biblio->biblionumber,
322
                notforloan => 0,
323
                itemlost   => 0,
324
                withdrawn  => 0,
325
        }
326
    }
327
    );
328
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
292
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
329
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
293
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
330
294
Lines 348-365 subtest 'Checkin of an item claimed as returned should generate a message' => su Link Here
348
    plan tests => 1;
312
    plan tests => 1;
349
313
350
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
314
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
351
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
315
    my $item = $builder->build_sample_item;
352
    my $item = $builder->build_object(
353
        {
354
            class  => 'Koha::Items',
355
            value  => {
356
                biblionumber => $biblio->biblionumber,
357
                notforloan => 0,
358
                itemlost   => 0,
359
                withdrawn  => 0,
360
        }
361
    }
362
    );
363
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
316
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
364
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
317
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
365
318
Lines 376-393 subtest 'BranchTransferLimitsType' => sub { Link Here
376
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
329
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
377
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
330
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
378
331
379
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
332
    my $item = $builder->build_sample_item;
380
    my $item = $builder->build_object(
381
        {
382
            class  => 'Koha::Items',
383
            value  => {
384
                biblionumber => $biblio->biblionumber,
385
                notforloan => 0,
386
                itemlost   => 0,
387
                withdrawn  => 0,
388
        }
389
    }
390
    );
391
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
333
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
392
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
334
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
393
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
335
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
Lines 406-422 subtest 'Backdated returns should reduce fine if needed' => sub { Link Here
406
    t::lib::Mocks::mock_preference( "CalculateFinesOnBackdate", 1 );
348
    t::lib::Mocks::mock_preference( "CalculateFinesOnBackdate", 1 );
407
349
408
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
350
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
409
    my $item = $builder->build_object(
351
    my $item = $builder->build_sample_item;
410
        {
411
            class  => 'Koha::Items',
412
            value  => {
413
                biblionumber => $biblio->biblionumber,
414
                notforloan => 0,
415
                itemlost   => 0,
416
                withdrawn  => 0,
417
        }
418
    }
419
    );
420
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
352
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
421
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
353
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
422
    my $fine = Koha::Account::Line->new({
354
    my $fine = Koha::Account::Line->new({
(-)a/t/db_dependent/Circulation/StoreLastBorrower.t (-28 / +20 lines)
Lines 45-78 subtest 'Test StoreLastBorrower' => sub { Link Here
45
        }
45
        }
46
    );
46
    );
47
47
48
    my $item = $builder->build(
48
    my $item = $builder->build_sample_item;
49
        {
50
            source => 'Item',
51
            value  => {
52
                itemlost  => 0,
53
                withdrawn => 0,
54
            },
55
        }
56
    );
57
49
58
    my $issue = $builder->build(
50
    my $issue = $builder->build(
59
        {
51
        {
60
            source => 'Issue',
52
            source => 'Issue',
61
            value  => {
53
            value  => {
62
                borrowernumber => $patron->{borrowernumber},
54
                borrowernumber => $patron->{borrowernumber},
63
                itemnumber     => $item->{itemnumber},
55
                itemnumber     => $item->itemnumber,
64
            },
56
            },
65
        }
57
        }
66
    );
58
    );
67
59
68
    my $item_object   = Koha::Items->find( $item->{itemnumber} );
60
    $item = $item->get_from_storage;
69
    my $patron_object = $item_object->last_returned_by();
61
    my $patron_object = $item->last_returned_by();
70
    is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' );
62
    is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' );
71
63
72
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode},  undef, dt_from_string('2010-10-10') );
64
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, $patron->{branchcode},  undef, dt_from_string('2010-10-10') );
73
65
74
    $item_object   = Koha::Items->find( $item->{itemnumber} );
66
    $item = $item->get_from_storage;
75
    $patron_object = $item_object->last_returned_by();
67
    $patron_object = $item->last_returned_by();
76
    is( ref($patron_object), 'Koha::Patron', 'Koha::Item::last_returned_by returned Koha::Patron' );
68
    is( ref($patron_object), 'Koha::Patron', 'Koha::Item::last_returned_by returned Koha::Patron' );
77
69
78
    $patron = $builder->build(
70
    $patron = $builder->build(
Lines 87-101 subtest 'Test StoreLastBorrower' => sub { Link Here
87
            source => 'Issue',
79
            source => 'Issue',
88
            value  => {
80
            value  => {
89
                borrowernumber => $patron->{borrowernumber},
81
                borrowernumber => $patron->{borrowernumber},
90
                itemnumber     => $item->{itemnumber},
82
                itemnumber     => $item->itemnumber,
91
            },
83
            },
92
        }
84
        }
93
    );
85
    );
94
86
95
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
87
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
96
88
97
    $item_object   = Koha::Items->find( $item->{itemnumber} );
89
    $item = $item->get_from_storage;
98
    $patron_object = $item_object->last_returned_by();
90
    $patron_object = $item->last_returned_by();
99
    is( $patron_object->id, $patron->{borrowernumber}, 'Second patron to return item replaces the first' );
91
    is( $patron_object->id, $patron->{borrowernumber}, 'Second patron to return item replaces the first' );
100
92
101
    $patron = $builder->build(
93
    $patron = $builder->build(
Lines 106-120 subtest 'Test StoreLastBorrower' => sub { Link Here
106
    );
98
    );
107
    $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
99
    $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
108
100
109
    $item_object->last_returned_by($patron_object);
101
    $item->last_returned_by($patron_object);
110
    $item_object = Koha::Items->find( $item->{itemnumber} );
102
    $item = $item->get_from_storage;
111
    my $patron_object2 = $item_object->last_returned_by();
103
    my $patron_object2 = $item->last_returned_by();
112
    is( $patron_object->id, $patron_object2->id,
104
    is( $patron_object->id, $patron_object2->id,
113
        'Calling last_returned_by with Borrower object sets last_returned_by to that borrower' );
105
        'Calling last_returned_by with Borrower object sets last_returned_by to that borrower' );
114
106
115
    $patron_object->delete;
107
    $patron_object->delete;
116
    $item_object = Koha::Items->find( $item->{itemnumber} );
108
    $item = $item->get_from_storage;
117
    is( $item_object->last_returned_by, undef, 'last_returned_by should return undef if the last patron to return the item has been deleted' );
109
    is( $item->last_returned_by, undef, 'last_returned_by should return undef if the last patron to return the item has been deleted' );
118
110
119
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '0' );
111
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '0' );
120
    $patron = $builder->build(
112
    $patron = $builder->build(
Lines 129-142 subtest 'Test StoreLastBorrower' => sub { Link Here
129
            source => 'Issue',
121
            source => 'Issue',
130
            value  => {
122
            value  => {
131
                borrowernumber => $patron->{borrowernumber},
123
                borrowernumber => $patron->{borrowernumber},
132
                itemnumber     => $item->{itemnumber},
124
                itemnumber     => $item->itemnumber,
133
            },
125
            },
134
        }
126
        }
135
    );
127
    );
136
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
128
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
137
129
138
    $item_object   = Koha::Items->find( $item->{itemnumber} );
130
    $item = $item->get_from_storage;
139
    is( $item_object->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' );
131
    is( $item->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' );
140
};
132
};
141
133
142
$schema->storage->txn_rollback;
134
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-51 / +24 lines)
Lines 57-85 my $patron = $builder->build_object({ Link Here
57
});
57
});
58
my $patron_unblessed = $patron->unblessed;
58
my $patron_unblessed = $patron->unblessed;
59
59
60
my $biblio = $builder->build({
60
my $item = $builder->build_sample_item(
61
    source => 'Biblio',
62
    value => {
63
        branchcode => $branch->{branchcode},
64
    },
65
});
66
$builder->build(
67
    {
61
    {
68
        source => 'Biblioitem',
62
        library => $branch->{branchcode},
69
        value  => { biblionumber => $biblio->{biblionumber} }
70
    }
63
    }
71
);
64
);
72
my $item = $builder->build({
73
    source => 'Item',
74
    value => {
75
        biblionumber => $biblio->{biblionumber},
76
        homebranch => $branch->{branchcode},
77
        holdingbranch => $branch->{branchcode},
78
        notforloan => 0,
79
        withdrawn => 0,
80
        lost => 0,
81
    },
82
});
83
65
84
Koha::CirculationRules->search()->delete();
66
Koha::CirculationRules->search()->delete();
85
Koha::CirculationRules->set_rules(
67
Koha::CirculationRules->set_rules(
Lines 103-156 t::lib::Mocks::mock_userenv({ patron => $patron }); Link Here
103
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
85
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
104
86
105
# Add onsite checkout
87
# Add onsite checkout
106
C4::Circulation::AddIssue( $patron_unblessed, $item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
88
C4::Circulation::AddIssue( $patron_unblessed, $item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
107
89
108
my ( $impossible, $messages );
90
my ( $impossible, $messages );
109
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
91
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
110
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
92
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
111
is( $impossible->{NO_RENEWAL_FOR_ONSITE_CHECKOUTS}, 1, 'Do not renew on-site checkouts' );
93
is( $impossible->{NO_RENEWAL_FOR_ONSITE_CHECKOUTS}, 1, 'Do not renew on-site checkouts' );
112
94
113
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 1);
95
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 1);
114
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
96
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
115
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
97
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
116
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
98
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
117
C4::Circulation::AddIssue( $patron_unblessed, $item->{barcode}, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
99
C4::Circulation::AddIssue( $patron_unblessed, $item->barcode, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
118
my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
100
my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
119
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
101
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
120
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
102
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
121
is( dt_from_string($issue->date_due, 'sql'), $five_days_after, 'The date_due should have been set depending on the circ rules when the on-site checkout has been switched' );
103
is( dt_from_string($issue->date_due, 'sql'), $five_days_after, 'The date_due should have been set depending on the circ rules when the on-site checkout has been switched' );
122
104
123
# Specific case
105
# Specific case
124
t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
106
t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
125
my $another_item = $builder->build({
107
my $another_item = $builder->build_sample_item(
126
    source => 'Item',
108
    {
127
    value => {
109
        biblionumber => $item->biblionumber,
128
        biblionumber => $biblio->{biblionumber},
110
        library      => $branch->{branchcode},
129
        homebranch => $branch->{branchcode},
111
    }
130
        holdingbranch => $branch->{branchcode},
112
);
131
        notforloan => 0,
132
        withdrawn => 0,
133
        lost => 0,
134
    },
135
});
136
113
137
C4::Circulation::AddIssue( $patron_unblessed, $another_item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
114
C4::Circulation::AddIssue( $patron_unblessed, $another_item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
138
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
115
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->barcode );
139
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
116
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
140
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
117
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
141
118
142
my $yet_another_item = $builder->build({
119
my $yet_another_item = $builder->build_sample_item(
143
    source => 'Item',
120
    {
144
    value => {
121
        biblionumber => $item->biblionumber,
145
        biblionumber => $biblio->{biblionumber},
122
        library      => $branch->{branchcode},
146
        homebranch => $branch->{branchcode},
123
    }
147
        holdingbranch => $branch->{branchcode},
124
);
148
        notforloan => 0,
125
149
        withdrawn => 0,
126
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->barcode );
150
        lost => 0,
151
    },
152
});
153
( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} );
154
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
127
is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' );
155
128
156
Koha::CirculationRules->search()->delete();
129
Koha::CirculationRules->search()->delete();
Lines 165-171 Koha::CirculationRules->set_rules( Link Here
165
        }
138
        }
166
    }
139
    }
167
);
140
);
168
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
141
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->barcode );
169
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
142
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' );
170
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
143
is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' );
171
144
(-)a/t/db_dependent/Circulation/dateexpiry.t (-11 / +11 lines)
Lines 46-52 subtest 'Tests for CalcDateDue related to dateexpiry' => sub { Link Here
46
};
46
};
47
47
48
sub can_book_be_issued {
48
sub can_book_be_issued {
49
    my $item    = $builder->build( { source => 'Item', value => { biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber} } } );
49
    my $item    = $builder->build_sample_item;
50
    my $patron  = $builder->build_object(
50
    my $patron  = $builder->build_object(
51
        {   class  => 'Koha::Patrons',
51
        {   class  => 'Koha::Patrons',
52
            value  => {
52
            value  => {
Lines 56-67 sub can_book_be_issued { Link Here
56
        }
56
        }
57
    );
57
    );
58
    my $duration = gettimeofday();
58
    my $duration = gettimeofday();
59
    my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
59
    my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
60
    $duration = gettimeofday() - $duration;
60
    $duration = gettimeofday() - $duration;
61
    cmp_ok $duration, '<', 1, "CanBookBeIssued should not be take more than 1s if the patron is expired";
61
    cmp_ok $duration, '<', 1, "CanBookBeIssued should not be take more than 1s if the patron is expired";
62
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' );
62
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' );
63
63
64
    $item   = $builder->build( { source => 'Item', value => { biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber} } } );
64
    $item   = $builder->build_sample_item;
65
    $patron = $builder->build_object(
65
    $patron = $builder->build_object(
66
        {   class  => 'Koha::Patrons',
66
        {   class  => 'Koha::Patrons',
67
            value  => {
67
            value  => {
Lines 70-80 sub can_book_be_issued { Link Here
70
            }
70
            }
71
        }
71
        }
72
    );
72
    );
73
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
73
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
74
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is not set' );
74
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is not set' );
75
75
76
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
76
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
77
    $item   = $builder->build( { source => 'Item', value => { biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber} } } );
77
    $item   = $builder->build_sample_item;
78
    $patron = $builder->build_object(
78
    $patron = $builder->build_object(
79
        {   class  => 'Koha::Patrons',
79
        {   class  => 'Koha::Patrons',
80
            value  => {
80
            value  => {
Lines 83-89 sub can_book_be_issued { Link Here
83
            },
83
            },
84
        }
84
        }
85
    );
85
    );
86
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
86
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
87
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' );
87
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' );
88
88
89
}
89
}
Lines 99-118 sub calc_date_due { Link Here
99
            categorycode => $patron_category->{categorycode},
99
            categorycode => $patron_category->{categorycode},
100
        }
100
        }
101
    });
101
    });
102
    my $item   = $builder->build( { source => 'Item' } );
102
    my $item   = $builder->build_sample_item;
103
    my $branch = $builder->build( { source => 'Branch' } );
103
    my $branch = $builder->build( { source => 'Branch' } );
104
    my $today  = dt_from_string();
104
    my $today  = dt_from_string();
105
105
106
    # first test with empty expiry date
106
    # first test with empty expiry date
107
    # note that this expiry date will never lead to an issue btw !!
107
    # note that this expiry date will never lead to an issue btw !!
108
    $patron->{dateexpiry} = '0000-00-00';
108
    $patron->{dateexpiry} = '0000-00-00';
109
    my $d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron );
109
    my $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
110
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry 0000-00-00" );
110
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry 0000-00-00" );
111
111
112
    # second test expiry date==today
112
    # second test expiry date==today
113
    my $d2 = output_pref( { dt => $today, dateonly => 1, dateformat => 'sql' } );
113
    my $d2 = output_pref( { dt => $today, dateonly => 1, dateformat => 'sql' } );
114
    $patron->{dateexpiry} = $d2;
114
    $patron->{dateexpiry} = $d2;
115
    $d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron );
115
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
116
    is( ref $d eq "DateTime" && DateTime->compare( $d->truncate( to => 'day' ), $today->truncate( to => 'day' ) ) == 0, 1, "CalcDateDue with expiry today" );
116
    is( ref $d eq "DateTime" && DateTime->compare( $d->truncate( to => 'day' ), $today->truncate( to => 'day' ) ) == 0, 1, "CalcDateDue with expiry today" );
117
117
118
    # third test expiry date tomorrow
118
    # third test expiry date tomorrow
Lines 120-132 sub calc_date_due { Link Here
120
    my $tomorrow = $today->clone->add_duration($dur);
120
    my $tomorrow = $today->clone->add_duration($dur);
121
    $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } );
121
    $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } );
122
    $patron->{dateexpiry} = $d2;
122
    $patron->{dateexpiry} = $d2;
123
    $d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron );
123
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
124
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry tomorrow" );
124
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry tomorrow" );
125
125
126
    # fourth test far future
126
    # fourth test far future
127
    $patron->{dateexpiry} = '9876-12-31';
127
    $patron->{dateexpiry} = '9876-12-31';
128
    my $t1 = time;
128
    my $t1 = time;
129
    $d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron );
129
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
130
    my $t2 = time;
130
    my $t2 = time;
131
    is( ref $d eq "DateTime" && $t2 - $t1 < 1, 1, "CalcDateDue with expiry in year 9876 in " . sprintf( "%6.4f", $t2 - $t1 ) . " seconds." );
131
    is( ref $d eq "DateTime" && $t2 - $t1 < 1, 1, "CalcDateDue with expiry in year 9876 in " . sprintf( "%6.4f", $t2 - $t1 ) . " seconds." );
132
}
132
}
(-)a/t/db_dependent/CourseReserves/CourseItems.t (-17 / +8 lines)
Lines 492-513 sub create_dependent_objects { Link Here
492
}
492
}
493
493
494
sub create_bib_and_item {
494
sub create_bib_and_item {
495
    my $biblio = $builder->build({
495
    my $item = $builder->build_sample_item(
496
        source => 'Biblio',
496
        {
497
        value  => {
497
            itype    => 'CD_foo',
498
            title => 'Title',
498
            ccode    => 'CD',
499
        }
499
            location => 'HR',
500
    });
500
            library  => 'B1',
501
    my $item = $builder->build({
502
        source => 'Item',
503
        value  => {
504
            biblionumber  => $biblio->{biblionumber},
505
            itype         => 'CD_foo',
506
            ccode         => 'CD',
507
            location      => 'HR',
508
            homebranch    => 'B1',
509
            holdingbranch => 'B1',
510
        }
501
        }
511
    });
502
    );
512
    return ($biblio->{biblionumber}, $item->{itemnumber});
503
    return ($item->biblionumber, $item->itemnumber);
513
}
504
}
(-)a/t/db_dependent/Exporter/Record.t (-31 / +16 lines)
Lines 63-94 Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcx Link Here
63
my $bad_biblionumber = $bad_biblio->id;
63
my $bad_biblionumber = $bad_biblio->id;
64
64
65
my $builder = t::lib::TestBuilder->new;
65
my $builder = t::lib::TestBuilder->new;
66
my $item_1_1 = $builder->build({
66
my $item_1_1 = $builder->build_sample_item(
67
    source => 'Item',
67
    {
68
    value => {
69
        biblionumber => $biblionumber_1,
68
        biblionumber => $biblionumber_1,
70
        more_subfields_xml => '',
71
    }
69
    }
72
});
70
)->unblessed;
73
my $item_1_2 = $builder->build({
71
my $item_1_2 = $builder->build_sample_item(
74
    source => 'Item',
72
    {
75
    value => {
76
        biblionumber => $biblionumber_1,
73
        biblionumber => $biblionumber_1,
77
        more_subfields_xml => '',
78
    }
74
    }
79
});
75
)->unblessed;
80
my $item_2_1 = $builder->build({
76
my $item_2_1 = $builder->build_sample_item(
81
    source => 'Item',
77
    {
82
    value => {
83
        biblionumber => $biblionumber_2,
78
        biblionumber => $biblionumber_2,
84
        more_subfields_xml => '',
85
    }
79
    }
86
});
80
)->unblessed;
87
my $bad_item = $builder->build({
81
my $bad_item = $builder->build({ # Cannot call build_sample_item, we want inconsistent data on purpose
88
    source => 'Item',
82
    source => 'Item',
89
    value => {
83
    value => {
90
        biblionumber => $bad_biblionumber,
84
        biblionumber => $bad_biblionumber,
91
        more_subfields_xml => '',
92
    }
85
    }
93
});
86
});
94
87
Lines 223-246 subtest '_get_biblio_for_export' => sub { Link Here
223
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
216
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
224
    my $branch_a = $builder->build({source => 'Branch',});
217
    my $branch_a = $builder->build({source => 'Branch',});
225
    my $branch_b = $builder->build({source => 'Branch',});
218
    my $branch_b = $builder->build({source => 'Branch',});
226
    my $item_branch_a = $builder->build(
219
    my $item_branch_a = $builder->build_sample_item(
227
        {
220
        {
228
            source => 'Item',
221
            biblionumber => $biblionumber,
229
            value  => {
222
            library      => $branch_a->{branchcode},
230
                biblionumber       => $biblionumber,
231
                homebranch         => $branch_a->{branchcode},
232
                more_subfields_xml => '',
233
            }
234
        }
223
        }
235
    );
224
    );
236
    my $item_branch_b = $builder->build(
225
    my $item_branch_b = $builder->build_sample_item(
237
        {
226
        {
238
            source => 'Item',
227
            biblionumber => $biblionumber,
239
            value  => {
228
            library      => $branch_b->{branchcode},
240
                biblionumber       => $biblionumber,
241
                homebranch         => $branch_b->{branchcode},
242
                more_subfields_xml => '',
243
            }
244
        }
229
        }
245
    );
230
    );
246
231
(-)a/t/db_dependent/Holds/HoldFulfillmentPolicy.t (-1 / +1 lines)
Lines 30-36 my $library2 = $builder->build({ Link Here
30
my $library3 = $builder->build({
30
my $library3 = $builder->build({
31
    source => 'Branch',
31
    source => 'Branch',
32
});
32
});
33
my $itemtype = $builder->build({ source => 'Item' })->{itype};
33
my $itemtype = $builder->build_sample_item->itype;
34
34
35
my $bib_title = "Test Title";
35
my $bib_title = "Test Title";
36
36
(-)a/t/db_dependent/Holds/WaitingReserves.t (-60 / +18 lines)
Lines 59-115 my $patron2 = $builder->build({ Link Here
59
    },
59
    },
60
});
60
});
61
61
62
my $biblio = $builder->build({
62
my $biblio  = $builder->build_sample_biblio;
63
    source => 'Biblio',
63
my $biblio2 = $builder->build_sample_biblio;
64
    value  => {
64
my $biblio3 = $builder->build_sample_biblio;
65
        title => 'Title 1',    },
65
my $biblio4 = $builder->build_sample_biblio;
66
});
67
68
my $biblio2 = $builder->build({
69
    source => 'Biblio',
70
    value  => {
71
        title => 'Title 2',    },
72
});
73
74
my $biblio3 = $builder->build({
75
    source => 'Biblio',
76
    value  => {
77
        title => 'Title 3',    },
78
});
79
80
my $biblio4 = $builder->build({
81
    source => 'Biblio',
82
    value  => {
83
        title => 'Title 4',    },
84
});
85
86
my $item1 = $builder->build({
87
    source => 'Item',
88
    value  => {
89
        biblionumber => $biblio->{biblionumber},
90
    },
91
});
92
66
93
my $item2 = $builder->build({
67
my $item1 = $builder->build_sample_item({biblionumber => $biblio->biblionumber});
94
    source => 'Item',
68
my $item2 = $builder->build_sample_item({biblionumber => $biblio2->biblionumber});
95
    value  => {
69
my $item3 = $builder->build_sample_item({biblionumber => $biblio3->biblionumber});
96
        biblionumber => $biblio2->{biblionumber},
70
my $item4 = $builder->build_sample_item({biblionumber => $biblio4->biblionumber});
97
    },
98
});
99
100
my $item3 = $builder->build({
101
    source => 'Item',
102
    value  => {
103
        biblionumber => $biblio3->{biblionumber},
104
    },
105
});
106
107
my $item4 = $builder->build({
108
    source => 'Item',
109
    value  => {
110
        biblionumber => $biblio4->{biblionumber},
111
    },
112
});
113
71
114
my $today = dt_from_string();
72
my $today = dt_from_string();
115
73
Lines 125-131 my $reserve1 = $builder->build({ Link Here
125
        borrowernumber => $patron1->{borrowernumber},
83
        borrowernumber => $patron1->{borrowernumber},
126
        reservedate => $reserve1_reservedate->ymd,
84
        reservedate => $reserve1_reservedate->ymd,
127
        expirationdate => undef,
85
        expirationdate => undef,
128
        biblionumber => $biblio->{biblionumber},
86
        biblionumber => $biblio->biblionumber,
129
        branchcode => 'LIB1',
87
        branchcode => 'LIB1',
130
        priority => 1,
88
        priority => 1,
131
        found => '',
89
        found => '',
Lines 135-148 my $reserve1 = $builder->build({ Link Here
135
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelay', 1);
93
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelay', 1);
136
t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 6);
94
t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 6);
137
95
138
ModReserveAffect( $item1->{itemnumber}, $patron1->{borrowernumber});
96
ModReserveAffect( $item1->itemnumber, $patron1->{borrowernumber});
139
my $r = Koha::Holds->find($reserve1->{reserve_id});
97
my $r = Koha::Holds->find($reserve1->{reserve_id});
140
98
141
is($r->waitingdate, $today->ymd, 'Waiting date should be set to today' );
99
is($r->waitingdate, $today->ymd, 'Waiting date should be set to today' );
142
is($r->expirationdate, $reserve1_expirationdate->ymd, 'Expiration date should be set to today + 6' );
100
is($r->expirationdate, $reserve1_expirationdate->ymd, 'Expiration date should be set to today + 6' );
143
is($r->found, 'W', 'Reserve status is now "waiting"' );
101
is($r->found, 'W', 'Reserve status is now "waiting"' );
144
is($r->priority, 0, 'Priority should be 0' );
102
is($r->priority, 0, 'Priority should be 0' );
145
is($r->itemnumber, $item1->{itemnumber}, 'Item number should be set correctly' );
103
is($r->itemnumber, $item1->itemnumber, 'Item number should be set correctly' );
146
104
147
my $reserve2 = $builder->build({
105
my $reserve2 = $builder->build({
148
    source => 'Reserve',
106
    source => 'Reserve',
Lines 150-168 my $reserve2 = $builder->build({ Link Here
150
        borrowernumber => $patron2->{borrowernumber},
108
        borrowernumber => $patron2->{borrowernumber},
151
        reservedate => $reserve1_reservedate->ymd,
109
        reservedate => $reserve1_reservedate->ymd,
152
        expirationdate => undef,
110
        expirationdate => undef,
153
        biblionumber => $biblio2->{biblionumber},
111
        biblionumber => $biblio2->biblionumber,
154
        branchcode => 'LIB1',
112
        branchcode => 'LIB1',
155
        priority => 1,
113
        priority => 1,
156
        found => '',
114
        found => '',
157
    },
115
    },
158
});
116
});
159
117
160
ModReserveAffect( $item2->{itemnumber}, $patron2->{borrowernumber}, 1);
118
ModReserveAffect( $item2->itemnumber, $patron2->{borrowernumber}, 1);
161
my $r2 = Koha::Holds->find($reserve2->{reserve_id});
119
my $r2 = Koha::Holds->find($reserve2->{reserve_id});
162
120
163
is($r2->found, 'T', '2nd reserve - Reserve status is now "To transfer"' );
121
is($r2->found, 'T', '2nd reserve - Reserve status is now "To transfer"' );
164
is($r2->priority, 0, '2nd reserve - Priority should be 0' );
122
is($r2->priority, 0, '2nd reserve - Priority should be 0' );
165
is($r2->itemnumber, $item2->{itemnumber}, '2nd reserve - Item number should be set correctly' );
123
is($r2->itemnumber, $item2->itemnumber, '2nd reserve - Item number should be set correctly' );
166
124
167
my $reserve3 = $builder->build({
125
my $reserve3 = $builder->build({
168
    source => 'Reserve',
126
    source => 'Reserve',
Lines 170-176 my $reserve3 = $builder->build({ Link Here
170
        borrowernumber => $patron2->{borrowernumber},
128
        borrowernumber => $patron2->{borrowernumber},
171
        reservedate => $reserve1_reservedate->ymd,
129
        reservedate => $reserve1_reservedate->ymd,
172
        expirationdate => undef,
130
        expirationdate => undef,
173
        biblionumber => $biblio3->{biblionumber},
131
        biblionumber => $biblio3->biblionumber,
174
        branchcode => 'LIB1',
132
        branchcode => 'LIB1',
175
        priority => 1,
133
        priority => 1,
176
        found => '',
134
        found => '',
Lines 210-216 my $holiday2 = $builder->build({ Link Here
210
Koha::Caches->get_instance->flush_all;
168
Koha::Caches->get_instance->flush_all;
211
169
212
t::lib::Mocks::mock_preference('ExcludeHolidaysFromMaxPickUpDelay', 1);
170
t::lib::Mocks::mock_preference('ExcludeHolidaysFromMaxPickUpDelay', 1);
213
ModReserveAffect( $item3->{itemnumber}, $patron2->{borrowernumber});
171
ModReserveAffect( $item3->itemnumber, $patron2->{borrowernumber});
214
172
215
# Add 6 days of pickup delay + 1 day of holiday.
173
# Add 6 days of pickup delay + 1 day of holiday.
216
my $expected_expiration = $today->clone;
174
my $expected_expiration = $today->clone;
Lines 228-234 my $reserve4 = $builder->build({ Link Here
228
        borrowernumber => $patron2->{borrowernumber},
186
        borrowernumber => $patron2->{borrowernumber},
229
        reservedate => $reserve4_reservedate->ymd,
187
        reservedate => $reserve4_reservedate->ymd,
230
        expirationdate => $requested_expiredate->ymd,
188
        expirationdate => $requested_expiredate->ymd,
231
        biblionumber => $biblio4->{biblionumber},
189
        biblionumber => $biblio4->biblionumber,
232
        branchcode => 'LIB1',
190
        branchcode => 'LIB1',
233
        priority => 1,
191
        priority => 1,
234
        found => '',
192
        found => '',
Lines 236-242 my $reserve4 = $builder->build({ Link Here
236
});
194
});
237
195
238
t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 10);
196
t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 10);
239
ModReserveAffect( $item4->{itemnumber}, $patron2->{borrowernumber}, 0, $reserve4->{reserve_id});
197
ModReserveAffect( $item4->itemnumber, $patron2->{borrowernumber}, 0, $reserve4->{reserve_id});
240
198
241
my $r4 = Koha::Holds->find($reserve4->{reserve_id});
199
my $r4 = Koha::Holds->find($reserve4->{reserve_id});
242
is($r4->expirationdate, $requested_expiredate->ymd, 'Requested expiration date should be kept' );
200
is($r4->expirationdate, $requested_expiredate->ymd, 'Requested expiration date should be kept' );
(-)a/t/db_dependent/ILSDI_Services.t (-115 / +41 lines)
Lines 310-386 subtest 'Holds test' => sub { Link Here
310
        source => 'Borrower',
310
        source => 'Borrower',
311
    });
311
    });
312
312
313
    my $biblio = $builder->build({
313
    my $item = $builder->build_sample_item(
314
        source => 'Biblio',
314
        {
315
    });
316
317
    my $biblioitems = $builder->build({
318
        source => 'Biblioitem',
319
        value => {
320
            biblionumber => $biblio->{biblionumber},
321
        }
322
    });
323
324
    my $item = $builder->build({
325
        source => 'Item',
326
        value => {
327
            biblionumber => $biblio->{biblionumber},
328
            damaged => 1
315
            damaged => 1
329
        }
316
        }
330
    });
317
    );
331
318
332
    my $query = new CGI;
319
    my $query = new CGI;
333
    $query->param( 'patron_id', $patron->{borrowernumber});
320
    $query->param( 'patron_id', $patron->{borrowernumber});
334
    $query->param( 'bib_id', $biblio->{biblionumber});
321
    $query->param( 'bib_id', $item->biblionumber);
335
322
336
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
323
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
337
    is( $reply->{code}, 'damaged', "Item damaged" );
324
    is( $reply->{code}, 'damaged', "Item damaged" );
338
325
339
    my $item_o = Koha::Items->find($item->{itemnumber});
326
    $item->damaged(0)->store;
340
    $item_o->damaged(0)->store;
341
327
342
    my $hold = $builder->build({
328
    my $hold = $builder->build({
343
        source => 'Reserve',
329
        source => 'Reserve',
344
        value => {
330
        value => {
345
            borrowernumber => $patron->{borrowernumber},
331
            borrowernumber => $patron->{borrowernumber},
346
            biblionumber => $biblio->{biblionumber},
332
            biblionumber => $item->biblionumber,
347
            itemnumber => $item->{itemnumber}
333
            itemnumber => $item->itemnumber
348
        }
334
        }
349
    });
335
    });
350
336
351
    $reply = C4::ILSDI::Services::HoldTitle( $query );
337
    $reply = C4::ILSDI::Services::HoldTitle( $query );
352
    is( $reply->{code}, 'itemAlreadyOnHold', "Item already on hold" );
338
    is( $reply->{code}, 'itemAlreadyOnHold', "Item already on hold" );
353
339
354
    my $biblio_with_no_item = $builder->build({
340
    my $biblio_with_no_item = $builder->build_sample_biblio;
355
        source => 'Biblio',
356
    });
357
341
358
    $query = new CGI;
342
    $query = new CGI;
359
    $query->param( 'patron_id', $patron->{borrowernumber});
343
    $query->param( 'patron_id', $patron->{borrowernumber});
360
    $query->param( 'bib_id', $biblio_with_no_item->{biblionumber});
344
    $query->param( 'bib_id', $biblio_with_no_item->biblionumber);
361
345
362
    $reply = C4::ILSDI::Services::HoldTitle( $query );
346
    $reply = C4::ILSDI::Services::HoldTitle( $query );
363
    is( $reply->{code}, 'NoItems', 'Biblio has no item' );
347
    is( $reply->{code}, 'NoItems', 'Biblio has no item' );
364
348
365
    my $biblio2 = $builder->build({
349
    my $item2 = $builder->build_sample_item(
366
        source => 'Biblio',
350
        {
367
    });
368
369
    my $biblioitems2 = $builder->build({
370
        source => 'Biblioitem',
371
        value => {
372
            biblionumber => $biblio2->{biblionumber},
373
        }
374
    });
375
376
    my $item2 = $builder->build({
377
        source => 'Item',
378
        value => {
379
            biblionumber => $biblio2->{biblionumber},
380
            damaged => 0,
351
            damaged => 0,
381
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
382
        }
352
        }
383
    });
353
    );
384
354
385
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
355
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
386
    Koha::CirculationRules->set_rule(
356
    Koha::CirculationRules->set_rule(
Lines 395-435 subtest 'Holds test' => sub { Link Here
395
365
396
    $query = new CGI;
366
    $query = new CGI;
397
    $query->param( 'patron_id', $patron->{borrowernumber});
367
    $query->param( 'patron_id', $patron->{borrowernumber});
398
    $query->param( 'bib_id', $biblio2->{biblionumber});
368
    $query->param( 'bib_id', $item2->biblionumber);
399
    $query->param( 'item_id', $item2->{itemnumber});
369
    $query->param( 'item_id', $item2->itemnumber);
400
370
401
    $reply = C4::ILSDI::Services::HoldItem( $query );
371
    $reply = C4::ILSDI::Services::HoldItem( $query );
402
    is( $reply->{code}, 'tooManyReserves', "Too many reserves" );
372
    is( $reply->{code}, 'tooManyReserves', "Too many reserves" );
403
373
404
    my $biblio3 = $builder->build({
405
        source => 'Biblio',
406
    });
407
408
    my $biblioitems3 = $builder->build({
409
        source => 'Biblioitem',
410
        value => {
411
            biblionumber => $biblio3->{biblionumber},
412
        }
413
    });
414
415
    # Adding a holdable item to biblio 3.
374
    # Adding a holdable item to biblio 3.
416
    my $item3 = $builder->build({
375
    my $item3 = $builder->build_sample_item(
417
        source => 'Item',
376
        {
418
        value => {
419
            biblionumber => $biblio3->{biblionumber},
420
            damaged => 0,
377
            damaged => 0,
421
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
422
        }
378
        }
423
    });
379
    );
424
380
425
    my $item4 = $builder->build({
381
    my $item4 = $builder->build_sample_item(
426
        source => 'Item',
382
        {
427
        value => {
383
            biblionumber => $item3->biblionumber,
428
            biblionumber => $biblio3->{biblionumber},
384
            damaged      => 1,
429
            damaged => 1,
430
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
431
        }
385
        }
432
    });
386
    );
433
387
434
    Koha::CirculationRules->set_rule(
388
    Koha::CirculationRules->set_rule(
435
        {
389
        {
Lines 443-450 subtest 'Holds test' => sub { Link Here
443
397
444
    $query = new CGI;
398
    $query = new CGI;
445
    $query->param( 'patron_id', $patron->{borrowernumber});
399
    $query->param( 'patron_id', $patron->{borrowernumber});
446
    $query->param( 'bib_id', $biblio3->{biblionumber});
400
    $query->param( 'bib_id', $item3->biblionumber);
447
    $query->param( 'item_id', $item4->{itemnumber});
401
    $query->param( 'item_id', $item4->itemnumber);
448
402
449
    $reply = C4::ILSDI::Services::HoldItem( $query );
403
    $reply = C4::ILSDI::Services::HoldItem( $query );
450
    is( $reply->{code}, 'damaged', "Item is damaged" );
404
    is( $reply->{code}, 'damaged', "Item is damaged" );
Lines 483-508 subtest 'Holds test for branch transfer limits' => sub { Link Here
483
        }
437
        }
484
    );
438
    );
485
439
486
    my $biblio = $builder->build({
440
    my $item = $builder->build_sample_item(
487
        source => 'Biblio',
441
        {
488
    });
442
            library => $origin_branch->{branchcode},
489
    my $biblioitem = $builder->build({
490
        source => 'Biblioitem',
491
        value => {
492
            biblionumber => $biblio->{biblionumber},
493
        }
494
    });
495
    my $item = $builder->build({
496
        source => 'Item',
497
        value => {
498
            homebranch => $origin_branch->{branchcode},
499
            holdingbranch => $origin_branch->{branchcode},
500
            biblionumber => $biblio->{biblionumber},
501
            damaged => 0,
502
            itemlost => 0,
503
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
504
        }
443
        }
505
    });
444
    );
506
445
507
    Koha::CirculationRules->set_rule(
446
    Koha::CirculationRules->set_rule(
508
        {
447
        {
Lines 516-530 subtest 'Holds test for branch transfer limits' => sub { Link Here
516
455
517
    my $limit = Koha::Item::Transfer::Limit->new({
456
    my $limit = Koha::Item::Transfer::Limit->new({
518
        toBranch => $pickup_branch->{branchcode},
457
        toBranch => $pickup_branch->{branchcode},
519
        fromBranch => $item->{holdingbranch},
458
        fromBranch => $item->holdingbranch,
520
        itemtype => $item->{itype},
459
        itemtype => $item->effective_itemtype,
521
    })->store();
460
    })->store();
522
461
523
    my $query = new CGI;
462
    my $query = new CGI;
524
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
463
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
525
    $query->param( 'patron_id', $patron->{borrowernumber});
464
    $query->param( 'patron_id', $patron->{borrowernumber});
526
    $query->param( 'bib_id', $biblio->{biblionumber});
465
    $query->param( 'bib_id', $item->biblionumber);
527
    $query->param( 'item_id', $item->{itemnumber});
466
    $query->param( 'item_id', $item->itemnumber);
528
467
529
    my $reply = C4::ILSDI::Services::HoldItem( $query );
468
    my $reply = C4::ILSDI::Services::HoldItem( $query );
530
    is( $reply->{code}, 'cannotBeTransferred', "Item hold, Item cannot be transferred" );
469
    is( $reply->{code}, 'cannotBeTransferred', "Item hold, Item cannot be transferred" );
Lines 536-549 subtest 'Holds test for branch transfer limits' => sub { Link Here
536
475
537
    $reply = C4::ILSDI::Services::HoldItem( $query );
476
    $reply = C4::ILSDI::Services::HoldItem( $query );
538
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
477
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
539
    my $hold = Koha::Holds->search({ itemnumber => $item->{itemnumber}, borrowernumber => $patron->{borrowernumber} })->next;
478
    my $hold = Koha::Holds->search({ itemnumber => $item->itemnumber, borrowernumber => $patron->{borrowernumber} })->next;
540
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
479
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
541
480
542
    Koha::Holds->search()->delete();
481
    Koha::Holds->search()->delete();
543
482
544
    $reply = C4::ILSDI::Services::HoldTitle( $query );
483
    $reply = C4::ILSDI::Services::HoldTitle( $query );
545
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
484
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
546
    $hold = Koha::Holds->search({ biblionumber => $biblio->{biblionumber}, borrowernumber => $patron->{borrowernumber} })->next;
485
    $hold = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->{borrowernumber} })->next;
547
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
486
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
548
487
549
    $schema->storage->txn_rollback;
488
    $schema->storage->txn_rollback;
Lines 622-651 subtest 'GetRecords' => sub { Link Here
622
        source => 'Branch',
561
        source => 'Branch',
623
    });
562
    });
624
563
625
    my $biblio = $builder->build({
564
    my $item = $builder->build_sample_item(
626
        source => 'Biblio',
565
        {
627
    });
566
            library => $branch1->{branchcode},
628
    my $biblioitem = $builder->build({
567
        }
629
        source => 'Biblioitem',
568
    );
630
        value => {
631
            biblionumber => $biblio->{biblionumber},
632
        },
633
    });
634
    my $item = $builder->build_object({
635
        class => 'Koha::Items',
636
        value => {
637
            biblionumber => $biblio->{biblionumber},
638
            biblioitemnumber => $biblioitem->{biblioitemnumber},
639
            homebranch => $branch1->{branchcode},
640
            holdingbranch => $branch1->{branchcode},
641
        },
642
    });
643
569
644
    ModItemTransfer($item->itemnumber, $branch1->{branchcode}, $branch2->{branchcode});
570
    ModItemTransfer($item->itemnumber, $branch1->{branchcode}, $branch2->{branchcode});
645
571
646
    my $cgi = new CGI;
572
    my $cgi = new CGI;
647
    $cgi->param(service => 'GetRecords');
573
    $cgi->param(service => 'GetRecords');
648
    $cgi->param(id => $biblio->{biblionumber});
574
    $cgi->param(id => $item->biblionumber);
649
575
650
    my $reply = C4::ILSDI::Services::GetRecords($cgi);
576
    my $reply = C4::ILSDI::Services::GetRecords($cgi);
651
577
Lines 668-674 subtest 'RenewHold' => sub { Link Here
668
594
669
    my $cgi    = new CGI;
595
    my $cgi    = new CGI;
670
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
596
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
671
    my $item   = $builder->build_object( { class => 'Koha::Items' } );
597
    my $item   = $builder->build_sample_item;
672
    $cgi->param( patron_id => $patron->borrowernumber );
598
    $cgi->param( patron_id => $patron->borrowernumber );
673
    $cgi->param( item_id   => $item->itemnumber );
599
    $cgi->param( item_id   => $item->itemnumber );
674
600
(-)a/t/db_dependent/ImportBatch.t (-1 / +1 lines)
Lines 133-139 is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecor Link Here
133
# Add a few tests for GetItemNumbersFromImportBatch
133
# Add a few tests for GetItemNumbersFromImportBatch
134
my @a = GetItemNumbersFromImportBatch( $id_import_batch1 );
134
my @a = GetItemNumbersFromImportBatch( $id_import_batch1 );
135
is( @a, 0, 'No item numbers expected since we did not commit' );
135
is( @a, 0, 'No item numbers expected since we did not commit' );
136
my $itemno = $builder->build({ source => 'Item' })->{itemnumber};
136
my $itemno = $builder->build_sample_item->itemnumber;
137
# Link this item to the import item to fool GetItemNumbersFromImportBatch
137
# Link this item to the import item to fool GetItemNumbersFromImportBatch
138
my $sql = "UPDATE import_items SET itemnumber=? WHERE import_record_id=?";
138
my $sql = "UPDATE import_items SET itemnumber=? WHERE import_record_id=?";
139
$dbh->do( $sql, undef, $itemno, $import_record_id );
139
$dbh->do( $sql, undef, $itemno, $import_record_id );
(-)a/t/db_dependent/Items.t (-10 / +9 lines)
Lines 870-883 subtest 'Check stockrotationitem relationship' => sub { Link Here
870
    $schema->storage->txn_begin();
870
    $schema->storage->txn_begin();
871
871
872
    my $builder = t::lib::TestBuilder->new;
872
    my $builder = t::lib::TestBuilder->new;
873
    my $item = $builder->build({ source => 'Item' });
873
    my $item = $builder->build_sample_item;
874
874
875
    $builder->build({
875
    $builder->build({
876
        source => 'Stockrotationitem',
876
        source => 'Stockrotationitem',
877
        value  => { itemnumber_id => $item->{itemnumber} }
877
        value  => { itemnumber_id => $item->itemnumber }
878
    });
878
    });
879
879
880
    my $sritem = Koha::Items->find($item->{itemnumber})->stockrotationitem;
880
    my $sritem = Koha::Items->find($item->itemnumber)->stockrotationitem;
881
    isa_ok( $sritem, 'Koha::StockRotationItem', "Relationship works and correctly creates Koha::Object." );
881
    isa_ok( $sritem, 'Koha::StockRotationItem', "Relationship works and correctly creates Koha::Object." );
882
882
883
    $schema->storage->txn_rollback;
883
    $schema->storage->txn_rollback;
Lines 889-895 subtest 'Check add_to_rota method' => sub { Link Here
889
    $schema->storage->txn_begin();
889
    $schema->storage->txn_begin();
890
890
891
    my $builder = t::lib::TestBuilder->new;
891
    my $builder = t::lib::TestBuilder->new;
892
    my $item = $builder->build({ source => 'Item' });
892
    my $item = $builder->build_sample_item;
893
    my $rota = $builder->build({ source => 'Stockrotationrota' });
893
    my $rota = $builder->build({ source => 'Stockrotationrota' });
894
    my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
894
    my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
895
895
Lines 898-908 subtest 'Check add_to_rota method' => sub { Link Here
898
        value  => { rota_id => $rota->{rota_id} },
898
        value  => { rota_id => $rota->{rota_id} },
899
    });
899
    });
900
900
901
    my $sritem = Koha::Items->find($item->{itemnumber});
901
    my $sritem = Koha::Items->find($item->itemnumber);
902
    $sritem->add_to_rota($rota->{rota_id});
902
    $sritem->add_to_rota($rota->{rota_id});
903
903
904
    is(
904
    is(
905
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
905
        Koha::StockRotationItems->find($item->itemnumber)->stage_id,
906
        $srrota->stockrotationstages->next->stage_id,
906
        $srrota->stockrotationstages->next->stage_id,
907
        "Adding to a rota a new sritem item being assigned to its first stage."
907
        "Adding to a rota a new sritem item being assigned to its first stage."
908
    );
908
    );
Lines 919-925 subtest 'Check add_to_rota method' => sub { Link Here
919
    $sritem->add_to_rota($newrota->{rota_id});
919
    $sritem->add_to_rota($newrota->{rota_id});
920
920
921
    is(
921
    is(
922
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
922
        Koha::StockRotationItems->find($item->itemnumber)->stage_id,
923
        $srnewrota->stockrotationstages->next->stage_id,
923
        $srnewrota->stockrotationstages->next->stage_id,
924
        "Moving an item results in that sritem being assigned to the new first stage."
924
        "Moving an item results in that sritem being assigned to the new first stage."
925
    );
925
    );
Lines 932-939 subtest 'Split subfields in Item2Marc (Bug 21774)' => sub { Link Here
932
    $schema->storage->txn_begin;
932
    $schema->storage->txn_begin;
933
933
934
    my $builder = t::lib::TestBuilder->new;
934
    my $builder = t::lib::TestBuilder->new;
935
    my $biblio = $builder->build({ source => 'Biblio', value => { frameworkcode => q{} } });
935
    my $item = $builder->build_sample_item({ ccode => 'A|B' });
936
    my $item = $builder->build({ source => 'Item', value => { biblionumber => $biblio->{biblionumber}, ccode => 'A|B' } });
937
936
938
    Koha::MarcSubfieldStructures->search({ tagfield => '952', tagsubfield => '8' })->delete; # theoretical precaution
937
    Koha::MarcSubfieldStructures->search({ tagfield => '952', tagsubfield => '8' })->delete; # theoretical precaution
939
    Koha::MarcSubfieldStructures->search({ kohafield => 'items.ccode' })->delete;
938
    Koha::MarcSubfieldStructures->search({ kohafield => 'items.ccode' })->delete;
Lines 949-955 subtest 'Split subfields in Item2Marc (Bug 21774)' => sub { Link Here
949
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
948
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
950
949
951
    # Start testing
950
    # Start testing
952
    my $marc = C4::Items::Item2Marc( $item, $biblio->{biblionumber} );
951
    my $marc = C4::Items::Item2Marc( $item->unblessed, $item->biblionumber );
953
    my @subs = $marc->subfield( $mapping->tagfield, $mapping->tagsubfield );
952
    my @subs = $marc->subfield( $mapping->tagfield, $mapping->tagsubfield );
954
    is( @subs, 2, 'Expect two subfields' );
953
    is( @subs, 2, 'Expect two subfields' );
955
    is( $subs[0], 'A', 'First subfield matches' );
954
    is( $subs[0], 'A', 'First subfield matches' );
(-)a/t/db_dependent/Items/GetHostItemsInfo.t (-6 / +6 lines)
Lines 14-27 subtest 'GetHostItemsInfo' => sub { Link Here
14
    plan tests => 3;
14
    plan tests => 3;
15
15
16
    my $builder = t::lib::TestBuilder->new;
16
    my $builder = t::lib::TestBuilder->new;
17
    my $bib1 = $builder->build({ source => 'Biblio' });
17
    my $bib1 = $builder->build_sample_biblio;
18
    my $itm1 = $builder->build({ source => 'Item', value => { biblionumber => $bib1->{biblionumber} }});
18
    my $itm1 = $builder->build_sample_item({ biblionumber => $bib1->biblionumber });
19
    my $itm2 = $builder->build({ source => 'Item', value => { biblionumber => $bib1->{biblionumber} }});
19
    my $itm2 = $builder->build_sample_item({ biblionumber => $bib1->biblionumber });
20
    my $marc = MARC::Record->new;
20
    my $marc = MARC::Record->new;
21
    $marc->append_fields(
21
    $marc->append_fields(
22
        MARC::Field->new( '461', '', '', 0 => $bib1->{biblionumber}, 9 => $itm1->{itemnumber} ),
22
        MARC::Field->new( '461', '', '', 0 => $bib1->biblionumber, 9 => $itm1->itemnumber ),
23
        MARC::Field->new( '773', '', '', 0 => $bib1->{biblionumber}, 9 => $itm1->{itemnumber} ),
23
        MARC::Field->new( '773', '', '', 0 => $bib1->biblionumber, 9 => $itm1->itemnumber ),
24
        MARC::Field->new( '773', '', '', 0 => $bib1->{biblionumber}, 9 => $itm2->{itemnumber} ),
24
        MARC::Field->new( '773', '', '', 0 => $bib1->biblionumber, 9 => $itm2->itemnumber ),
25
    );
25
    );
26
26
27
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
27
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
(-)a/t/db_dependent/Items/GetItemsForInventory.t (-1 / +1 lines)
Lines 164-170 subtest 'Use cn_sort rather than callnumber to determine correct location' => su Link Here
164
        class_source => $class_source->{cn_source},
164
        class_source => $class_source->{cn_source},
165
    });
165
    });
166
166
167
    my $item_1 = $builder->build({
167
    my $item_1 = $builder->build({ # Cannot call build_sample_item or cn_sort will be replaced by Koha::Item->store
168
            source => 'Item',
168
            source => 'Item',
169
            value  => {
169
            value  => {
170
                itemcallnumber => 'GT95',
170
                itemcallnumber => 'GT95',
(-)a/t/db_dependent/Items/MoveItemFromBiblio.t (-39 / +25 lines)
Lines 31-99 my $schema = Koha::Database->new->schema; Link Here
31
$schema->storage->txn_begin;
31
$schema->storage->txn_begin;
32
my $builder = t::lib::TestBuilder->new;
32
my $builder = t::lib::TestBuilder->new;
33
33
34
# NOTE This is a trick, if we want to populate the biblioitems table, we should not create a Biblio but a Biblioitem
34
my $from_biblio = $builder->build_sample_biblio;
35
my $param = { source => 'Biblioitem' };
35
my $to_biblio = $builder->build_sample_biblio;
36
my $from_biblio = {
36
37
    biblionumber => $builder->build($param)->{biblionumber},
37
my $item1 = $builder->build_sample_item(
38
};
38
    { biblionumber => $from_biblio->biblionumber, } );
39
my $to_biblio = {
39
my $item2 = $builder->build_sample_item(
40
    biblionumber => $builder->build($param)->{biblionumber},
40
    { biblionumber => $from_biblio->biblionumber, } );
41
};
41
my $item3 = $builder->build_sample_item(
42
42
    { biblionumber => $to_biblio->biblionumber, } );
43
my $item1       = $builder->build(
43
44
    {   source => 'Item',
45
        value  => { biblionumber => $from_biblio->{biblionumber}, },
46
    }
47
);
48
my $item2 = $builder->build(
49
    {   source => 'Item',
50
        value  => { biblionumber => $from_biblio->{biblionumber}, },
51
    }
52
);
53
my $item3 = $builder->build(
54
    {   source => 'Item',
55
        value  => { biblionumber => $to_biblio->{biblionumber}, },
56
    }
57
);
58
44
59
my $bib_level_hold_not_to_move = $builder->build(
45
my $bib_level_hold_not_to_move = $builder->build(
60
    {   source => 'Reserve',
46
    {   source => 'Reserve',
61
        value  => { biblionumber => $from_biblio->{biblionumber}, },
47
        value  => { biblionumber => $from_biblio->biblionumber, },
62
    }
48
    }
63
);
49
);
64
my $item_level_hold_not_to_move = $builder->build(
50
my $item_level_hold_not_to_move = $builder->build(
65
    {   source => 'Reserve',
51
    {   source => 'Reserve',
66
        value  => { biblionumber => $from_biblio->{biblionumber}, itemnumber => $item1->{itemnumber} },
52
        value  => { biblionumber => $from_biblio->biblionumber, itemnumber => $item1->itemnumber },
67
    }
53
    }
68
);
54
);
69
my $item_level_hold_to_move = $builder->build(
55
my $item_level_hold_to_move = $builder->build(
70
    {   source => 'Reserve',
56
    {   source => 'Reserve',
71
        value  => { biblionumber => $from_biblio->{biblionumber}, itemnumber => $item2->{itemnumber} },
57
        value  => { biblionumber => $from_biblio->biblionumber, itemnumber => $item2->itemnumber },
72
    }
58
    }
73
);
59
);
74
60
75
my $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber} );
61
my $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->itemnumber, $from_biblio->biblionumber, $to_biblio->biblionumber );
76
62
77
is( $to_biblionumber_after_moved, $to_biblio->{biblionumber}, 'MoveItemFromBiblio should return the to_biblionumber if success' );
63
is( $to_biblionumber_after_moved, $to_biblio->biblionumber, 'MoveItemFromBiblio should return the to_biblionumber if success' );
78
64
79
$to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber} );
65
$to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->itemnumber, $from_biblio->biblionumber, $to_biblio->biblionumber );
80
66
81
is( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' );
67
is( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' );
82
68
83
my $get_item1 = Koha::Items->find( $item1->{itemnumber} );
69
my $get_item1 = Koha::Items->find( $item1->itemnumber );
84
is( $get_item1->biblionumber, $from_biblio->{biblionumber}, 'The item1 should not have been moved' );
70
is( $get_item1->biblionumber, $from_biblio->biblionumber, 'The item1 should not have been moved' );
85
my $get_item2 = Koha::Items->find( $item2->{itemnumber} );
71
my $get_item2 = Koha::Items->find( $item2->itemnumber );
86
is( $get_item2->biblionumber, $to_biblio->{biblionumber}, 'The item2 should have been moved' );
72
is( $get_item2->biblionumber, $to_biblio->biblionumber, 'The item2 should have been moved' );
87
my $get_item3 = Koha::Items->find( $item3->{itemnumber} );
73
my $get_item3 = Koha::Items->find( $item3->itemnumber );
88
is( $get_item3->biblionumber, $to_biblio->{biblionumber}, 'The item3 should not have been moved' );
74
is( $get_item3->biblionumber, $to_biblio->biblionumber, 'The item3 should not have been moved' );
89
75
90
my $get_bib_level_hold    = Koha::Holds->find( $bib_level_hold_not_to_move->{reserve_id} );
76
my $get_bib_level_hold    = Koha::Holds->find( $bib_level_hold_not_to_move->{reserve_id} );
91
my $get_item_level_hold_1 = Koha::Holds->find( $item_level_hold_not_to_move->{reserve_id} );
77
my $get_item_level_hold_1 = Koha::Holds->find( $item_level_hold_not_to_move->{reserve_id} );
92
my $get_item_level_hold_2 = Koha::Holds->find( $item_level_hold_to_move->{reserve_id} );
78
my $get_item_level_hold_2 = Koha::Holds->find( $item_level_hold_to_move->{reserve_id} );
93
79
94
is( $get_bib_level_hold->biblionumber,    $from_biblio->{biblionumber}, 'MoveItemFromBiblio should not have moved the biblio-level hold' );
80
is( $get_bib_level_hold->biblionumber,    $from_biblio->biblionumber, 'MoveItemFromBiblio should not have moved the biblio-level hold' );
95
is( $get_item_level_hold_1->biblionumber, $from_biblio->{biblionumber}, 'MoveItemFromBiblio should not have moved the item-level hold placed on item 1' );
81
is( $get_item_level_hold_1->biblionumber, $from_biblio->biblionumber, 'MoveItemFromBiblio should not have moved the item-level hold placed on item 1' );
96
is( $get_item_level_hold_2->biblionumber, $to_biblio->{biblionumber},   'MoveItemFromBiblio should have moved the item-level hold placed on item 2' );
82
is( $get_item_level_hold_2->biblionumber, $to_biblio->biblionumber,   'MoveItemFromBiblio should have moved the item-level hold placed on item 2' );
97
83
98
$schema->storage->txn_rollback;
84
$schema->storage->txn_rollback;
99
85
(-)a/t/db_dependent/Koha/Account/Line.t (-11 / +8 lines)
Lines 73-89 subtest 'item() tests' => sub { Link Here
73
    $schema->storage->txn_begin;
73
    $schema->storage->txn_begin;
74
74
75
    my $library = $builder->build( { source => 'Branch' } );
75
    my $library = $builder->build( { source => 'Branch' } );
76
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
77
    my $patron = $builder->build( { source => 'Borrower' } );
76
    my $patron = $builder->build( { source => 'Borrower' } );
78
    my $item = Koha::Item->new(
77
    my $item = $builder->build_sample_item(
79
    {
78
        {
80
        biblionumber     => $biblioitem->{biblionumber},
79
            library => $library->{branchcode},
81
        biblioitemnumber => $biblioitem->{biblioitemnumber},
80
            barcode => 'some_barcode_12',
82
        homebranch       => $library->{branchcode},
81
            itype   => 'BK',
83
        holdingbranch    => $library->{branchcode},
82
        }
84
        barcode          => 'some_barcode_12',
83
    );
85
        itype            => 'BK',
86
    })->store;
87
84
88
    my $line = Koha::Account::Line->new(
85
    my $line = Koha::Account::Line->new(
89
    {
86
    {
Lines 347-353 subtest 'Keep account info when related patron, staff, item or cash_register is Link Here
347
344
348
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
345
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
349
    my $staff = $builder->build_object( { class => 'Koha::Patrons' } );
346
    my $staff = $builder->build_object( { class => 'Koha::Patrons' } );
350
    my $item = $builder->build_object({ class => 'Koha::Items' });
347
    my $item = $builder->build_sample_item;
351
    my $issue = $builder->build_object(
348
    my $issue = $builder->build_object(
352
        {
349
        {
353
            class => 'Koha::Checkouts',
350
            class => 'Koha::Checkouts',
(-)a/t/db_dependent/Koha/Biblios.t (-10 / +4 lines)
Lines 96-118 subtest 'holds + current_holds' => sub { Link Here
96
96
97
subtest 'waiting_or_in_transit' => sub {
97
subtest 'waiting_or_in_transit' => sub {
98
    plan tests => 4;
98
    plan tests => 4;
99
    my $biblio = $builder->build( { source => 'Biblio' } );
99
    my $item = $builder->build_sample_item;
100
    my $item = $builder->build({
101
        source => 'Item',
102
        value => {
103
            biblionumber => $biblio->{biblionumber}
104
        }
105
    });
106
    my $reserve = $builder->build({
100
    my $reserve = $builder->build({
107
        source => 'Reserve',
101
        source => 'Reserve',
108
        value => {
102
        value => {
109
            biblionumber => $biblio->{biblionumber},
103
            biblionumber => $item->biblionumber,
110
            found => undef
104
            found => undef
111
        }
105
        }
112
    });
106
    });
113
107
114
    $reserve = Koha::Holds->find($reserve->{reserve_id});
108
    $reserve = Koha::Holds->find($reserve->{reserve_id});
115
    $biblio = Koha::Biblios->find($biblio->{biblionumber});
109
    $biblio = $item->biblio;
116
110
117
    is($biblio->has_items_waiting_or_intransit, 0, 'Item is neither waiting nor in transit');
111
    is($biblio->has_items_waiting_or_intransit, 0, 'Item is neither waiting nor in transit');
118
112
Lines 125-131 subtest 'waiting_or_in_transit' => sub { Link Here
125
    my $transfer = $builder->build({
119
    my $transfer = $builder->build({
126
        source => 'Branchtransfer',
120
        source => 'Branchtransfer',
127
        value => {
121
        value => {
128
            itemnumber => $item->{itemnumber},
122
            itemnumber => $item->itemnumber,
129
            datearrived => undef
123
            datearrived => undef
130
        }
124
        }
131
    });
125
    });
(-)a/t/db_dependent/Koha/Checkouts.t (-6 / +6 lines)
Lines 34-51 $schema->storage->txn_begin; Link Here
34
my $builder         = t::lib::TestBuilder->new;
34
my $builder         = t::lib::TestBuilder->new;
35
my $library         = $builder->build( { source => 'Branch' } );
35
my $library         = $builder->build( { source => 'Branch' } );
36
my $patron          = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } );
36
my $patron          = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } );
37
my $item_1          = $builder->build( { source => 'Item' } );
37
my $item_1          = $builder->build_sample_item;
38
my $item_2          = $builder->build( { source => 'Item' } );
38
my $item_2          = $builder->build_sample_item;
39
my $nb_of_checkouts = Koha::Checkouts->search->count;
39
my $nb_of_checkouts = Koha::Checkouts->search->count;
40
my $new_checkout_1  = Koha::Checkout->new(
40
my $new_checkout_1  = Koha::Checkout->new(
41
    {   borrowernumber => $patron->{borrowernumber},
41
    {   borrowernumber => $patron->{borrowernumber},
42
        itemnumber     => $item_1->{itemnumber},
42
        itemnumber     => $item_1->itemnumber,
43
        branchcode     => $library->{branchcode},
43
        branchcode     => $library->{branchcode},
44
    }
44
    }
45
)->store;
45
)->store;
46
my $new_checkout_2 = Koha::Checkout->new(
46
my $new_checkout_2 = Koha::Checkout->new(
47
    {   borrowernumber => $patron->{borrowernumber},
47
    {   borrowernumber => $patron->{borrowernumber},
48
        itemnumber     => $item_2->{itemnumber},
48
        itemnumber     => $item_2->itemnumber,
49
        branchcode     => $library->{branchcode},
49
        branchcode     => $library->{branchcode},
50
    }
50
    }
51
)->store;
51
)->store;
Lines 91-104 subtest 'item' => sub { Link Here
91
    plan tests => 2;
91
    plan tests => 2;
92
    my $item = $retrieved_checkout_1->item;
92
    my $item = $retrieved_checkout_1->item;
93
    is( ref( $item ), 'Koha::Item', 'Koha::Checkout->item should return a Koha::Item' );
93
    is( ref( $item ), 'Koha::Item', 'Koha::Checkout->item should return a Koha::Item' );
94
    is( $item->itemnumber, $item_1->{itemnumber}, 'Koha::Checkout->item should return the correct item' );
94
    is( $item->itemnumber, $item_1->itemnumber, 'Koha::Checkout->item should return the correct item' );
95
};
95
};
96
96
97
subtest 'patron' => sub {
97
subtest 'patron' => sub {
98
    plan tests => 3;
98
    plan tests => 3;
99
    my $patron = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}});
99
    my $patron = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}});
100
100
101
    my $item = $builder->build_object( { class=> 'Koha::Items' } );
101
    my $item = $builder->build_sample_item;
102
    my $checkout = Koha::Checkout->new(
102
    my $checkout = Koha::Checkout->new(
103
        {   borrowernumber => $patron->borrowernumber,
103
        {   borrowernumber => $patron->borrowernumber,
104
            itemnumber     => $item->itemnumber,
104
            itemnumber     => $item->itemnumber,
(-)a/t/db_dependent/Koha/Filter/EmbedItemsAvailability.t (-42 / +24 lines)
Lines 62-92 subtest 'EmbedItemsAvailability tests' => sub { Link Here
62
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio(MARC::Record->new(), '');
62
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio(MARC::Record->new(), '');
63
63
64
    # Add some items with different onloan values
64
    # Add some items with different onloan values
65
    $builder->build(
65
    $builder->build_sample_item(
66
        {   source => 'Item',
66
        {
67
            value  => {
67
            biblionumber => $biblionumber,
68
                biblionumber     => $biblionumber,
68
            onloan       => '2017-01-01'
69
                biblioitemnumber => $biblioitemnumber,
70
                onloan           => '2017-01-01'
71
            }
72
        }
69
        }
73
    );
70
    );
74
    $builder->build(
71
    $builder->build_sample_item(
75
        {   source => 'Item',
72
        {
76
            value  => {
73
            biblionumber => $biblionumber,
77
                biblionumber     => $biblionumber,
74
            onloan       => undef
78
                biblioitemnumber => $biblioitemnumber,
79
                onloan           => undef
80
            }
81
        }
75
        }
82
    );
76
    );
83
    $builder->build(
77
    $builder->build_sample_item(
84
        {   source => 'Item',
78
        {
85
            value  => {
79
            biblionumber => $biblionumber,
86
                biblionumber     => $biblionumber,
80
            onloan       => '2017-01-02'
87
                biblioitemnumber => $biblioitemnumber,
88
                onloan           => '2017-01-02'
89
            }
90
        }
81
        }
91
    );
82
    );
92
83
Lines 110-140 subtest 'EmbedItemsAvailability tests' => sub { Link Here
110
    ( $biblionumber, $biblioitemnumber ) = AddBiblio(MARC::Record->new(), '');
101
    ( $biblionumber, $biblioitemnumber ) = AddBiblio(MARC::Record->new(), '');
111
102
112
    # Add some items with different onloan values
103
    # Add some items with different onloan values
113
    $builder->build(
104
    $builder->build_sample_item(
114
        {   source => 'Item',
105
        {
115
            value  => {
106
            biblionumber => $biblionumber,
116
                biblionumber     => $biblionumber,
107
            onloan       => '2017-01-01'
117
                biblioitemnumber => $biblioitemnumber,
118
                onloan           => '2017-01-01'
119
            }
120
        }
108
        }
121
    );
109
    );
122
    $builder->build(
110
    $builder->build_sample_item(
123
        {   source => 'Item',
111
        {
124
            value  => {
112
            biblionumber => $biblionumber,
125
                biblionumber     => $biblionumber,
113
            onloan       => undef
126
                biblioitemnumber => $biblioitemnumber,
127
                onloan           => undef
128
            }
129
        }
114
        }
130
    );
115
    );
131
    $builder->build(
116
    $builder->build_sample_item(
132
        {   source => 'Item',
117
        {
133
            value  => {
118
            biblionumber => $biblionumber,
134
                biblionumber     => $biblionumber,
119
            onloan       => '2017-01-02'
135
                biblioitemnumber => $biblioitemnumber,
136
                onloan           => '2017-01-02'
137
            }
138
        }
120
        }
139
    );
121
    );
140
122
(-)a/t/db_dependent/Koha/Item.t (-19 / +17 lines)
Lines 192-216 subtest 'pickup_locations' => sub { Link Here
192
    my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
192
    my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
193
    my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
193
    my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
194
194
195
    my $biblioitem  = $builder->build( { source => 'Biblioitem' } );
195
    my $item1 = $builder->build_sample_item(
196
196
        {
197
    my $item1  = Koha::Item->new({
197
            homebranch    => $library1->branchcode,
198
        biblionumber     => $biblioitem->{biblionumber},
198
            holdingbranch => $library2->branchcode,
199
        biblioitemnumber => $biblioitem->{biblioitemnumber},
199
            barcode       => '1',
200
        homebranch       => $library1->branchcode,
200
            itype         => 'test',
201
        holdingbranch    => $library2->branchcode,
201
        }
202
        barcode          => '1',
202
    )->store;
203
        itype            => 'test',
203
204
    })->store;
204
    my $item3 = $builder->build_sample_item(
205
205
        {
206
    my $item3  = Koha::Item->new({
206
            homebranch    => $library3->branchcode,
207
        biblionumber     => $biblioitem->{biblionumber},
207
            holdingbranch => $library4->branchcode,
208
        biblioitemnumber => $biblioitem->{biblioitemnumber},
208
            barcode       => '3',
209
        homebranch       => $library3->branchcode,
209
            itype         => 'test',
210
        holdingbranch    => $library4->branchcode,
210
        }
211
        barcode          => '3',
211
    )->store;
212
        itype            => 'test',
213
    })->store;
214
212
215
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
213
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
216
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
214
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
(-)a/t/db_dependent/Koha/Item/Transfers.t (-10 / +12 lines)
Lines 35-45 $schema->storage->txn_begin; Link Here
35
my $builder      = t::lib::TestBuilder->new;
35
my $builder      = t::lib::TestBuilder->new;
36
my $library_from = $builder->build( { source => 'Branch' } );
36
my $library_from = $builder->build( { source => 'Branch' } );
37
my $library_to   = $builder->build( { source => 'Branch' } );
37
my $library_to   = $builder->build( { source => 'Branch' } );
38
my $item         = $builder->build( { source => 'Item', value => { holding_branch => $library_from->{branchcode}, homebranch => $library_to->{branchcode} } } );
38
my $item = $builder->build_sample_item(
39
    {
40
        holdingbranch => $library_from->{branchcode},
41
        homebranch    => $library_to->{branchcode}
42
    }
43
);
39
44
40
my $nb_of_transfers = Koha::Item::Transfers->search->count;
45
my $nb_of_transfers = Koha::Item::Transfers->search->count;
41
my $new_transfer_1  = Koha::Item::Transfer->new(
46
my $new_transfer_1  = Koha::Item::Transfer->new(
42
    {   itemnumber  => $item->{itemnumber},
47
    {   itemnumber  => $item->itemnumber,
43
        frombranch  => $library_from->{branchcode},
48
        frombranch  => $library_from->{branchcode},
44
        tobranch    => $library_to->{branchcode},
49
        tobranch    => $library_to->{branchcode},
45
        datearrived => dt_from_string,
50
        datearrived => dt_from_string,
Lines 47-53 my $new_transfer_1 = Koha::Item::Transfer->new( Link Here
47
    }
52
    }
48
)->store;
53
)->store;
49
my $new_transfer_2 = Koha::Item::Transfer->new(
54
my $new_transfer_2 = Koha::Item::Transfer->new(
50
    {   itemnumber  => $item->{itemnumber},
55
    {   itemnumber  => $item->itemnumber,
51
        frombranch  => $library_from->{branchcode},
56
        frombranch  => $library_from->{branchcode},
52
        tobranch    => $library_to->{branchcode},
57
        tobranch    => $library_to->{branchcode},
53
        datearrived => undef,
58
        datearrived => undef,
Lines 74-93 subtest 'daterequested tests' => sub { Link Here
74
    $schema->storage->txn_begin;
79
    $schema->storage->txn_begin;
75
    my $library_from = $builder->build( { source => 'Branch' } );
80
    my $library_from = $builder->build( { source => 'Branch' } );
76
    my $library_to   = $builder->build( { source => 'Branch' } );
81
    my $library_to   = $builder->build( { source => 'Branch' } );
77
    my $item         = $builder->build(
82
    my $item = $builder->build_sample_item(
78
        {
83
        {
79
            source => 'Item',
84
            holdingbranch => $library_from->{branchcode},
80
            value  => {
85
            homebranch    => $library_to->{branchcode}
81
                holding_branch => $library_from->{branchcode},
82
                homebranch     => $library_to->{branchcode}
83
            }
84
        }
86
        }
85
    );
87
    );
86
88
87
    my $now = dt_from_string;
89
    my $now = dt_from_string;
88
    my $transfer = Koha::Item::Transfer->new(
90
    my $transfer = Koha::Item::Transfer->new(
89
        {
91
        {
90
            itemnumber => $item->{itemnumber},
92
            itemnumber => $item->itemnumber,
91
            frombranch => $library_from->{branchcode},
93
            frombranch => $library_from->{branchcode},
92
            tobranch   => $library_to->{branchcode}
94
            tobranch   => $library_to->{branchcode}
93
        }
95
        }
(-)a/t/db_dependent/Koha/Patrons.t (-156 / +69 lines)
Lines 271-298 subtest 'siblings' => sub { Link Here
271
subtest 'has_overdues' => sub {
271
subtest 'has_overdues' => sub {
272
    plan tests => 3;
272
    plan tests => 3;
273
273
274
    my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
274
    my $item_1 = $builder->build_sample_item;
275
    my $item_1 = $builder->build(
276
        {   source => 'Item',
277
            value  => {
278
                homebranch    => $library->{branchcode},
279
                holdingbranch => $library->{branchcode},
280
                notforloan    => 0,
281
                itemlost      => 0,
282
                withdrawn     => 0,
283
                biblionumber  => $biblioitem_1->{biblionumber}
284
            }
285
        }
286
    );
287
    my $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
275
    my $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
288
    is( $retrieved_patron->has_overdues, 0, );
276
    is( $retrieved_patron->has_overdues, 0, );
289
277
290
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
278
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
291
    my $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->{itemnumber}, date_due => $tomorrow, branchcode => $library->{branchcode} })->store();
279
    my $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->itemnumber, date_due => $tomorrow, branchcode => $library->{branchcode} })->store();
292
    is( $retrieved_patron->has_overdues, 0, );
280
    is( $retrieved_patron->has_overdues, 0, );
293
    $issue->delete();
281
    $issue->delete();
294
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
282
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
295
    $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->{itemnumber}, date_due => $yesterday, branchcode => $library->{branchcode} })->store();
283
    $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->itemnumber, date_due => $yesterday, branchcode => $library->{branchcode} })->store();
296
    $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
284
    $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
297
    is( $retrieved_patron->has_overdues, 1, );
285
    is( $retrieved_patron->has_overdues, 1, );
298
    $issue->delete();
286
    $issue->delete();
Lines 579-619 subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub { Link Here
579
567
580
    my $library = $builder->build( { source => 'Branch' } );
568
    my $library = $builder->build( { source => 'Branch' } );
581
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
569
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
582
    my $item_1 = $builder->build(
570
    my $item_1 = $builder->build_sample_item(
583
        {
571
        {
584
            source => 'Item',
572
            library      => $library->{branchcode},
585
            value  => {
573
            biblionumber => $biblionumber_1,
586
                homebranch    => $library->{branchcode},
587
                holdingbranch => $library->{branchcode},
588
                biblionumber  => $biblionumber_1,
589
                itemlost      => 0,
590
                withdrawn     => 0,
591
            }
592
        }
574
        }
593
    );
575
    );
594
    my $item_2 = $builder->build(
576
    my $item_2 = $builder->build_sample_item(
595
        {
577
        {
596
            source => 'Item',
578
            library      => $library->{branchcode},
597
            value  => {
579
            biblionumber => $biblionumber_1,
598
                homebranch    => $library->{branchcode},
599
                holdingbranch => $library->{branchcode},
600
                biblionumber  => $biblionumber_1,
601
                itemlost      => 0,
602
                withdrawn     => 0,
603
            }
604
        }
580
        }
605
    );
581
    );
606
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
582
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
607
    my $item_3 = $builder->build(
583
    my $item_3 = $builder->build_sample_item(
608
        {
584
        {
609
            source => 'Item',
585
            library      => $library->{branchcode},
610
            value  => {
586
            biblionumber => $biblionumber_2,
611
                homebranch    => $library->{branchcode},
612
                holdingbranch => $library->{branchcode},
613
                biblionumber  => $biblionumber_2,
614
                itemlost      => 0,
615
                withdrawn     => 0,
616
            }
617
        }
587
        }
618
    );
588
    );
619
    my $patron = $builder->build(
589
    my $patron = $builder->build(
Lines 639-647 subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub { Link Here
639
609
640
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
610
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
641
611
642
    AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) );
612
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
643
    AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) );
613
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
644
    AddIssue( $patron, $item_3->{barcode} );
614
    AddIssue( $patron, $item_3->barcode );
645
615
646
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
616
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
647
    $checkouts = $patron->checkouts;
617
    $checkouts = $patron->checkouts;
Lines 652-668 subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub { Link Here
652
    is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
622
    is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
653
623
654
    my $first_checkout = $pending_checkouts->next;
624
    my $first_checkout = $pending_checkouts->next;
655
    is( $first_checkout->unblessed_all_relateds->{biblionumber}, $item_3->{biblionumber}, 'pending_checkouts should prefetch values from other tables (here biblio)' );
625
    is( $first_checkout->unblessed_all_relateds->{biblionumber}, $item_3->biblionumber, 'pending_checkouts should prefetch values from other tables (here biblio)' );
656
626
657
    my $overdues = $patron->get_overdues;
627
    my $overdues = $patron->get_overdues;
658
    is( $overdues->count, 2, 'Patron should have 2 overdues');
628
    is( $overdues->count, 2, 'Patron should have 2 overdues');
659
    is( ref($overdues), 'Koha::Checkouts', 'Koha::Patron->get_overdues should return Koha::Checkouts' );
629
    is( ref($overdues), 'Koha::Checkouts', 'Koha::Patron->get_overdues should return Koha::Checkouts' );
660
    is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
630
    is( $overdues->next->itemnumber, $item_1->itemnumber, 'The issue should be returned in the same order as they have been done, first is correct' );
661
    is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
631
    is( $overdues->next->itemnumber, $item_2->itemnumber, 'The issue should be returned in the same order as they have been done, second is correct' );
662
632
663
633
664
    C4::Circulation::AddReturn( $item_1->{barcode} );
634
    C4::Circulation::AddReturn( $item_1->barcode );
665
    C4::Circulation::AddReturn( $item_2->{barcode} );
635
    C4::Circulation::AddReturn( $item_2->barcode );
666
    $old_checkouts = $patron->old_checkouts;
636
    $old_checkouts = $patron->old_checkouts;
667
    is( $old_checkouts->count, 2, 'old_checkouts should return 2 old checkouts that patron' );
637
    is( $old_checkouts->count, 2, 'old_checkouts should return 2 old checkouts that patron' );
668
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
638
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
Lines 968-1004 subtest 'holds and old_holds' => sub { Link Here
968
938
969
    my $library = $builder->build( { source => 'Branch' } );
939
    my $library = $builder->build( { source => 'Branch' } );
970
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
940
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
971
    my $item_1 = $builder->build(
941
    my $item_1 = $builder->build_sample_item(
972
        {
942
        {
973
            source => 'Item',
943
            library      => $library->{branchcode},
974
            value  => {
944
            biblionumber => $biblionumber_1,
975
                homebranch    => $library->{branchcode},
976
                holdingbranch => $library->{branchcode},
977
                biblionumber  => $biblionumber_1
978
            }
979
        }
945
        }
980
    );
946
    );
981
    my $item_2 = $builder->build(
947
    my $item_2 = $builder->build_sample_item(
982
        {
948
        {
983
            source => 'Item',
949
            library      => $library->{branchcode},
984
            value  => {
950
            biblionumber => $biblionumber_1,
985
                homebranch    => $library->{branchcode},
986
                holdingbranch => $library->{branchcode},
987
                biblionumber  => $biblionumber_1
988
            }
989
        }
951
        }
990
    );
952
    );
991
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
953
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
992
    my $item_3 = $builder->build(
954
    my $item_3 = $builder->build_sample_item(
993
        {
955
        {
994
            source => 'Item',
956
            library      => $library->{branchcode},
995
            value  => {
957
            biblionumber => $biblionumber_2,
996
                homebranch    => $library->{branchcode},
997
                holdingbranch => $library->{branchcode},
998
                biblionumber  => $biblionumber_2
999
            }
1000
        }
958
        }
1001
    );
959
    );
960
1002
    my $patron = $builder->build(
961
    my $patron = $builder->build(
1003
        {
962
        {
1004
            source => 'Borrower',
963
            source => 'Borrower',
Lines 1086-1126 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1086
                value  => { privacy => 1, }
1045
                value  => { privacy => 1, }
1087
            }
1046
            }
1088
        );
1047
        );
1089
        my $item_1 = $builder->build(
1048
        my $item_1 = $builder->build_sample_item;
1090
            {   source => 'Item',
1091
                value  => {
1092
                    itemlost  => 0,
1093
                    withdrawn => 0,
1094
                },
1095
            }
1096
        );
1097
        my $issue_1 = $builder->build(
1049
        my $issue_1 = $builder->build(
1098
            {   source => 'Issue',
1050
            {   source => 'Issue',
1099
                value  => {
1051
                value  => {
1100
                    borrowernumber => $patron->{borrowernumber},
1052
                    borrowernumber => $patron->{borrowernumber},
1101
                    itemnumber     => $item_1->{itemnumber},
1053
                    itemnumber     => $item_1->itemnumber,
1102
                },
1103
            }
1104
        );
1105
        my $item_2 = $builder->build(
1106
            {   source => 'Item',
1107
                value  => {
1108
                    itemlost  => 0,
1109
                    withdrawn => 0,
1110
                },
1054
                },
1111
            }
1055
            }
1112
        );
1056
        );
1057
        my $item_2 = $builder->build_sample_item;
1113
        my $issue_2 = $builder->build(
1058
        my $issue_2 = $builder->build(
1114
            {   source => 'Issue',
1059
            {   source => 'Issue',
1115
                value  => {
1060
                value  => {
1116
                    borrowernumber => $patron->{borrowernumber},
1061
                    borrowernumber => $patron->{borrowernumber},
1117
                    itemnumber     => $item_2->{itemnumber},
1062
                    itemnumber     => $item_2->itemnumber,
1118
                },
1063
                },
1119
            }
1064
            }
1120
        );
1065
        );
1121
1066
1122
        my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->{barcode}, undef, undef, dt_from_string('2010-10-10') );
1067
        my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-10') );
1123
        my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->{barcode}, undef, undef, dt_from_string('2011-11-11') );
1068
        my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2011-11-11') );
1124
        is( $returned_1 && $returned_2, 1, 'The items should have been returned' );
1069
        is( $returned_1 && $returned_2, 1, 'The items should have been returned' );
1125
1070
1126
        my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } );
1071
        my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } );
Lines 1134-1159 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1134
1079
1135
        my $dbh = C4::Context->dbh;
1080
        my $dbh = C4::Context->dbh;
1136
        my $sth = $dbh->prepare(q|SELECT borrowernumber FROM old_issues where itemnumber = ?|);
1081
        my $sth = $dbh->prepare(q|SELECT borrowernumber FROM old_issues where itemnumber = ?|);
1137
        $sth->execute($item_1->{itemnumber});
1082
        $sth->execute($item_1->itemnumber);
1138
        my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1083
        my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1139
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'With privacy=1, the issue should have been anonymised' );
1084
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'With privacy=1, the issue should have been anonymised' );
1140
        $sth->execute($item_2->{itemnumber});
1085
        $sth->execute($item_2->itemnumber);
1141
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1086
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1142
        is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'The issue should not have been anonymised, the returned date is later' );
1087
        is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'The issue should not have been anonymised, the returned date is later' );
1143
1088
1144
        $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2011-11-12' } )->anonymise_issue_history;
1089
        $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2011-11-12' } )->anonymise_issue_history;
1145
        $sth->execute($item_2->{itemnumber});
1090
        $sth->execute($item_2->itemnumber);
1146
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1091
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1147
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue should have been anonymised, the returned date is before' );
1092
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue should have been anonymised, the returned date is before' );
1148
1093
1149
        my $sth_reset = $dbh->prepare(q|UPDATE old_issues SET borrowernumber = ? WHERE itemnumber = ?|);
1094
        my $sth_reset = $dbh->prepare(q|UPDATE old_issues SET borrowernumber = ? WHERE itemnumber = ?|);
1150
        $sth_reset->execute( $patron->{borrowernumber}, $item_1->{itemnumber} );
1095
        $sth_reset->execute( $patron->{borrowernumber}, $item_1->itemnumber );
1151
        $sth_reset->execute( $patron->{borrowernumber}, $item_2->{itemnumber} );
1096
        $sth_reset->execute( $patron->{borrowernumber}, $item_2->itemnumber );
1152
        $rows_affected = Koha::Patrons->search_patrons_to_anonymise->anonymise_issue_history;
1097
        $rows_affected = Koha::Patrons->search_patrons_to_anonymise->anonymise_issue_history;
1153
        $sth->execute($item_1->{itemnumber});
1098
        $sth->execute($item_1->itemnumber);
1154
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1099
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1155
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue 1 should have been anonymised, before parameter was not passed' );
1100
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue 1 should have been anonymised, before parameter was not passed' );
1156
        $sth->execute($item_2->{itemnumber});
1101
        $sth->execute($item_2->itemnumber);
1157
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1102
        ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array;
1158
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue 2 should have been anonymised, before parameter was not passed' );
1103
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue 2 should have been anonymised, before parameter was not passed' );
1159
1104
Lines 1169-1198 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1169
                value  => { privacy => 0, }
1114
                value  => { privacy => 0, }
1170
            }
1115
            }
1171
        );
1116
        );
1172
        my $item = $builder->build(
1117
        my $item = $builder->build_sample_item;
1173
            {   source => 'Item',
1174
                value  => {
1175
                    itemlost  => 0,
1176
                    withdrawn => 0,
1177
                },
1178
            }
1179
        );
1180
        my $issue = $builder->build(
1118
        my $issue = $builder->build(
1181
            {   source => 'Issue',
1119
            {   source => 'Issue',
1182
                value  => {
1120
                value  => {
1183
                    borrowernumber => $patron->{borrowernumber},
1121
                    borrowernumber => $patron->{borrowernumber},
1184
                    itemnumber     => $item->{itemnumber},
1122
                    itemnumber     => $item->itemnumber,
1185
                },
1123
                },
1186
            }
1124
            }
1187
        );
1125
        );
1188
1126
1189
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
1127
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, undef, undef, dt_from_string('2010-10-10') );
1190
        is( $returned, 1, 'The item should have been returned' );
1128
        is( $returned, 1, 'The item should have been returned' );
1191
1129
1192
        my $dbh = C4::Context->dbh;
1130
        my $dbh = C4::Context->dbh;
1193
        my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
1131
        my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
1194
            SELECT borrowernumber FROM old_issues where itemnumber = ?
1132
            SELECT borrowernumber FROM old_issues where itemnumber = ?
1195
        |, undef, $item->{itemnumber});
1133
        |, undef, $item->itemnumber);
1196
        is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'With privacy=0, the issue should not be anonymised' );
1134
        is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'With privacy=0, the issue should not be anonymised' );
1197
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1135
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1198
    };
1136
    };
Lines 1208-1231 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1208
                value  => { privacy => 1, }
1146
                value  => { privacy => 1, }
1209
            }
1147
            }
1210
        );
1148
        );
1211
        my $item = $builder->build(
1149
        my $item = $builder->build_sample_item;
1212
            {   source => 'Item',
1213
                value  => {
1214
                    itemlost  => 0,
1215
                    withdrawn => 0,
1216
                },
1217
            }
1218
        );
1219
        my $issue = $builder->build(
1150
        my $issue = $builder->build(
1220
            {   source => 'Issue',
1151
            {   source => 'Issue',
1221
                value  => {
1152
                value  => {
1222
                    borrowernumber => $patron->{borrowernumber},
1153
                    borrowernumber => $patron->{borrowernumber},
1223
                    itemnumber     => $item->{itemnumber},
1154
                    itemnumber     => $item->itemnumber,
1224
                },
1155
                },
1225
            }
1156
            }
1226
        );
1157
        );
1227
1158
1228
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
1159
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, undef, undef, dt_from_string('2010-10-10') );
1229
        is( $returned, 1, 'The item should have been returned' );
1160
        is( $returned, 1, 'The item should have been returned' );
1230
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
1161
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
1231
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
1162
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
Lines 1233-1239 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1233
        my $dbh = C4::Context->dbh;
1164
        my $dbh = C4::Context->dbh;
1234
        my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
1165
        my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
1235
            SELECT borrowernumber FROM old_issues where itemnumber = ?
1166
            SELECT borrowernumber FROM old_issues where itemnumber = ?
1236
        |, undef, $item->{itemnumber});
1167
        |, undef, $item->itemnumber);
1237
        is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' );
1168
        is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' );
1238
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1169
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1239
    };
1170
    };
Lines 1246-1269 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1246
                value  => { privacy => 1 }    # Another branchcode than the logged in librarian
1177
                value  => { privacy => 1 }    # Another branchcode than the logged in librarian
1247
            }
1178
            }
1248
        );
1179
        );
1249
        my $item = $builder->build(
1180
        my $item = $builder->build_sample_item;
1250
            {   source => 'Item',
1251
                value  => {
1252
                    itemlost  => 0,
1253
                    withdrawn => 0,
1254
                },
1255
            }
1256
        );
1257
        my $issue = $builder->build(
1181
        my $issue = $builder->build(
1258
            {   source => 'Issue',
1182
            {   source => 'Issue',
1259
                value  => {
1183
                value  => {
1260
                    borrowernumber => $patron->{borrowernumber},
1184
                    borrowernumber => $patron->{borrowernumber},
1261
                    itemnumber     => $item->{itemnumber},
1185
                    itemnumber     => $item->itemnumber,
1262
                },
1186
                },
1263
            }
1187
            }
1264
        );
1188
        );
1265
1189
1266
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
1190
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, undef, undef, dt_from_string('2010-10-10') );
1267
        is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 );
1191
        is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 );
1268
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1192
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1269
    };
1193
    };
Lines 1471-1507 subtest 'get_overdues' => sub { Link Here
1471
1395
1472
    my $library = $builder->build( { source => 'Branch' } );
1396
    my $library = $builder->build( { source => 'Branch' } );
1473
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
1397
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
1474
    my $item_1 = $builder->build(
1398
    my $item_1 = $builder->build_sample_item(
1475
        {
1399
        {
1476
            source => 'Item',
1400
            library      => $library->{branchcode},
1477
            value  => {
1401
            biblionumber => $biblionumber_1,
1478
                homebranch    => $library->{branchcode},
1479
                holdingbranch => $library->{branchcode},
1480
                biblionumber  => $biblionumber_1
1481
            }
1482
        }
1402
        }
1483
    );
1403
    );
1484
    my $item_2 = $builder->build(
1404
    my $item_2 = $builder->build_sample_item(
1485
        {
1405
        {
1486
            source => 'Item',
1406
            library      => $library->{branchcode},
1487
            value  => {
1407
            biblionumber => $biblionumber_1,
1488
                homebranch    => $library->{branchcode},
1489
                holdingbranch => $library->{branchcode},
1490
                biblionumber  => $biblionumber_1
1491
            }
1492
        }
1408
        }
1493
    );
1409
    );
1494
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
1410
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
1495
    my $item_3 = $builder->build(
1411
    my $item_3 = $builder->build_sample_item(
1496
        {
1412
        {
1497
            source => 'Item',
1413
            library      => $library->{branchcode},
1498
            value  => {
1414
            biblionumber => $biblionumber_2,
1499
                homebranch    => $library->{branchcode},
1500
                holdingbranch => $library->{branchcode},
1501
                biblionumber  => $biblionumber_2
1502
            }
1503
        }
1415
        }
1504
    );
1416
    );
1417
1505
    my $patron = $builder->build(
1418
    my $patron = $builder->build(
1506
        {
1419
        {
1507
            source => 'Borrower',
1420
            source => 'Borrower',
Lines 1511-1525 subtest 'get_overdues' => sub { Link Here
1511
1424
1512
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1425
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1513
1426
1514
    AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) );
1427
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
1515
    AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) );
1428
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
1516
    AddIssue( $patron, $item_3->{barcode} );
1429
    AddIssue( $patron, $item_3->barcode );
1517
1430
1518
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1431
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1519
    my $overdues = $patron->get_overdues;
1432
    my $overdues = $patron->get_overdues;
1520
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1433
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1521
    is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
1434
    is( $overdues->next->itemnumber, $item_1->itemnumber, 'The issue should be returned in the same order as they have been done, first is correct' );
1522
    is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
1435
    is( $overdues->next->itemnumber, $item_2->itemnumber, 'The issue should be returned in the same order as they have been done, second is correct' );
1523
1436
1524
    my $o = $overdues->reset->next;
1437
    my $o = $overdues->reset->next;
1525
    my $unblessed_overdue = $o->unblessed_all_relateds;
1438
    my $unblessed_overdue = $o->unblessed_all_relateds;
(-)a/t/db_dependent/Koha/Ratings.t (-2 / +2 lines)
Lines 31-38 my $builder = t::lib::TestBuilder->new; Link Here
31
31
32
my $patron_1 = $builder->build( { source => 'Borrower', } );
32
my $patron_1 = $builder->build( { source => 'Borrower', } );
33
my $patron_2 = $builder->build( { source => 'Borrower', } );
33
my $patron_2 = $builder->build( { source => 'Borrower', } );
34
my $biblio_1 = $builder->build( { source => 'Biblio', } );
34
my $biblio_1 = $builder->build_sample_biblio;
35
my $biblionumber = $biblio_1->{biblionumber};
35
my $biblionumber = $biblio_1->biblionumber;
36
36
37
my $rating_1 = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $patron_1->{borrowernumber}, rating_value => 3 } )->store;
37
my $rating_1 = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $patron_1->{borrowernumber}, rating_value => 3 } )->store;
38
my $rating_2 = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $patron_2->{borrowernumber}, rating_value => 4 } )->store;
38
my $rating_2 = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $patron_2->{borrowernumber}, rating_value => 4 } )->store;
(-)a/t/db_dependent/Koha/Reviews.t (-5 / +5 lines)
Lines 36-58 my $patron_1 = $builder->build({ source => 'Borrower', value => { flags => undef Link Here
36
my $patron_2 = $builder->build({ source => 'Borrower' });
36
my $patron_2 = $builder->build({ source => 'Borrower' });
37
$patron_1 = Koha::Patrons->find( $patron_1->{borrowernumber} );
37
$patron_1 = Koha::Patrons->find( $patron_1->{borrowernumber} );
38
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
38
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
39
my $biblio_1 = $builder->build({ source => 'Biblio' });
39
my $biblio_1 = $builder->build_sample_biblio;
40
my $biblio_2 = $builder->build({ source => 'Biblio' });
40
my $biblio_2 = $builder->build_sample_biblio;
41
my $nb_of_reviews = Koha::Reviews->search->count;
41
my $nb_of_reviews = Koha::Reviews->search->count;
42
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
42
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
43
my $new_review_1_1 = Koha::Review->new({
43
my $new_review_1_1 = Koha::Review->new({
44
    borrowernumber => $patron_1->borrowernumber,
44
    borrowernumber => $patron_1->borrowernumber,
45
    biblionumber => $biblio_1->{biblionumber},
45
    biblionumber => $biblio_1->biblionumber,
46
    review => 'a kind review',
46
    review => 'a kind review',
47
})->store;
47
})->store;
48
my $new_review_1_2 = Koha::Review->new({
48
my $new_review_1_2 = Koha::Review->new({
49
    borrowernumber => $patron_1->borrowernumber,
49
    borrowernumber => $patron_1->borrowernumber,
50
    biblionumber => $biblio_2->{biblionumber},
50
    biblionumber => $biblio_2->biblionumber,
51
    review => 'anoter kind review',
51
    review => 'anoter kind review',
52
})->store;
52
})->store;
53
my $new_review_2_1 = Koha::Review->new({
53
my $new_review_2_1 = Koha::Review->new({
54
    borrowernumber => $patron_2->borrowernumber,
54
    borrowernumber => $patron_2->borrowernumber,
55
    biblionumber => $biblio_1->{biblionumber},
55
    biblionumber => $biblio_1->biblionumber,
56
    review => 'just anoter review',
56
    review => 'just anoter review',
57
})->store;
57
})->store;
58
58
(-)a/t/db_dependent/Koha/SharedContent.t (-15 / +7 lines)
Lines 125-140 my $loggedinuser = $builder->build_object({ Link Here
125
    }
125
    }
126
});
126
});
127
127
128
my $biblio = $builder->build({
128
my $biblio = $builder->build_sample_biblio;
129
    source => 'Biblio',
130
});
131
132
my $biblioitem = $builder->build({
133
    source => 'Biblioitem',
134
    value => {
135
        biblionumber => $biblio->{biblionumber}
136
    }
137
});
138
129
139
my $subscriptionFrequency = $builder->build({
130
my $subscriptionFrequency = $builder->build({
140
    source => 'SubscriptionFrequency'
131
    source => 'SubscriptionFrequency'
Lines 147-153 my $subscriptionNumberpattern = $builder->build({ Link Here
147
my $subscription = $builder->build({
138
my $subscription = $builder->build({
148
    source => 'Subscription',
139
    source => 'Subscription',
149
    value => {
140
    value => {
150
        biblionumber => $biblio->{biblionumber},
141
        biblionumber => $biblio->biblionumber,
151
        periodicity => $subscriptionFrequency->{id},
142
        periodicity => $subscriptionFrequency->{id},
152
        numberpattern => $subscriptionNumberpattern->{id},
143
        numberpattern => $subscriptionNumberpattern->{id},
153
        mana_id => undef
144
        mana_id => undef
Lines 178-184 my $data = Koha::SharedContent::prepare_entity_data( Link Here
178
169
179
is($data->{language}, 'en', 'Language is set to default');
170
is($data->{language}, 'en', 'Language is set to default');
180
is($data->{exportemail}, $library->branchemail, 'Email is set with the userenv branch one');
171
is($data->{exportemail}, $library->branchemail, 'Email is set with the userenv branch one');
181
is($data->{title}, $biblio->{title}, 'Shared title');
172
is($data->{title}, $biblio->title, 'Shared title');
182
is($data->{sfdescription}, $subscriptionFrequency->{description}, 'Shared sfdescription');
173
is($data->{sfdescription}, $subscriptionFrequency->{description}, 'Shared sfdescription');
183
is($data->{unit}, $subscriptionFrequency->{unit}, 'Shared unit');
174
is($data->{unit}, $subscriptionFrequency->{unit}, 'Shared unit');
184
is($data->{unitsperissue}, $subscriptionFrequency->{unitsperissue}, 'Shared unitsperissue');
175
is($data->{unitsperissue}, $subscriptionFrequency->{unitsperissue}, 'Shared unitsperissue');
Lines 193-201 is($data->{every1}, $subscriptionNumberpattern->{every1}, 'Shared every1'); Link Here
193
is($data->{whenmorethan1}, $subscriptionNumberpattern->{whenmorethan1}, 'Shared whenmorethan1');
184
is($data->{whenmorethan1}, $subscriptionNumberpattern->{whenmorethan1}, 'Shared whenmorethan1');
194
is($data->{setto1}, $subscriptionNumberpattern->{setto1}, 'Shared setto1');
185
is($data->{setto1}, $subscriptionNumberpattern->{setto1}, 'Shared setto1');
195
is($data->{numbering1}, $subscriptionNumberpattern->{numbering1}, 'Shared numbering1');
186
is($data->{numbering1}, $subscriptionNumberpattern->{numbering1}, 'Shared numbering1');
196
is($data->{issn}, $biblioitem->{issn}, 'Shared ISSN');
187
my $biblioitem = $biblio->biblioitem;
197
is($data->{ean}, $biblioitem->{ean}, 'Shared EAN');
188
is($data->{issn}, $biblioitem->issn, 'Shared ISSN');
198
is($data->{publishercode}, $biblioitem->{publishercode}, 'Shared publishercode');
189
is($data->{ean}, $biblioitem->ean, 'Shared EAN');
190
is($data->{publishercode}, $biblioitem->publishercode, 'Shared publishercode');
199
191
200
sub mock_response {
192
sub mock_response {
201
    my $response = Test::MockObject->new();
193
    my $response = Test::MockObject->new();
(-)a/t/db_dependent/Koha/Subscription.t (-15 / +8 lines)
Lines 107-128 subtest 'Koha::Subscription->frequency' => sub { Link Here
107
};
107
};
108
108
109
my $nb_of_subs = Koha::Subscriptions->search->count;
109
my $nb_of_subs = Koha::Subscriptions->search->count;
110
my $biblio_1   = $builder->build( { source => 'Biblio' } );
110
my $biblio_1   = $builder->build_sample_biblio;
111
my $bi_1       = $builder->build(
111
my $bi_1       = $biblio_1->biblioitem;
112
    {
113
        source => 'Biblioitem',
114
        value  => {
115
            biblionumber => $biblio_1->{biblionumber}
116
        }
117
    }
118
);
119
my $sub_freq_1 = $builder->build( { source => 'SubscriptionFrequency' } );
112
my $sub_freq_1 = $builder->build( { source => 'SubscriptionFrequency' } );
120
my $sub_np_1   = $builder->build( { source => 'SubscriptionNumberpattern' } );
113
my $sub_np_1   = $builder->build( { source => 'SubscriptionNumberpattern' } );
121
my $sub_1      = $builder->build(
114
my $sub_1      = $builder->build(
122
    {
115
    {
123
        source => 'Subscription',
116
        source => 'Subscription',
124
        value  => {
117
        value  => {
125
            biblionumber  => $biblio_1->{biblionumber},
118
            biblionumber  => $biblio_1->biblionumber,
126
            periodicity   => $sub_freq_1->{id},
119
            periodicity   => $sub_freq_1->{id},
127
            numberpattern => $sub_np_1->{id}
120
            numberpattern => $sub_np_1->{id}
128
        }
121
        }
Lines 136-142 is( Link Here
136
);
129
);
137
is(
130
is(
138
    $sub_1->{biblionumber},
131
    $sub_1->{biblionumber},
139
    $biblio_1->{biblionumber},
132
    $biblio_1->biblionumber,
140
    'The link between sub and biblio is well done'
133
    'The link between sub and biblio is well done'
141
);
134
);
142
is( $sub_1->{periodicity}, $sub_freq_1->{id},
135
is( $sub_1->{periodicity}, $sub_freq_1->{id},
Lines 146-152 is( $sub_1->{numberpattern}, Link Here
146
    'The link between sub and sub_numberpattern is well done' );
139
    'The link between sub and sub_numberpattern is well done' );
147
140
148
my $ref = {
141
my $ref = {
149
    'title'           => $biblio_1->{title},
142
    'title'           => $biblio_1->title,
150
    'sfdescription'   => $sub_freq_1->{description},
143
    'sfdescription'   => $sub_freq_1->{description},
151
    'unit'            => $sub_freq_1->{unit},
144
    'unit'            => $sub_freq_1->{unit},
152
    'unitsperissue'   => $sub_freq_1->{unitsperissue},
145
    'unitsperissue'   => $sub_freq_1->{unitsperissue},
Lines 173-181 my $ref = { Link Here
173
    'whenmorethan3'   => $sub_np_1->{whenmorethan3},
166
    'whenmorethan3'   => $sub_np_1->{whenmorethan3},
174
    'setto3'          => $sub_np_1->{setto3},
167
    'setto3'          => $sub_np_1->{setto3},
175
    'numbering3'      => $sub_np_1->{numbering3},
168
    'numbering3'      => $sub_np_1->{numbering3},
176
    'issn'            => $bi_1->{issn},
169
    'issn'            => $bi_1->issn,
177
    'ean'             => $bi_1->{ean},
170
    'ean'             => $bi_1->ean,
178
    'publishercode'   => $bi_1->{publishercode}
171
    'publishercode'   => $bi_1->publishercode,
179
};
172
};
180
173
181
is_deeply( Koha::Subscription->get_sharable_info( $sub_1->{subscriptionid} ),
174
is_deeply( Koha::Subscription->get_sharable_info( $sub_1->{subscriptionid} ),
(-)a/t/db_dependent/Koha/Suggestions.t (-5 / +5 lines)
Lines 33-50 my $schema = Koha::Database->new->schema; Link Here
33
$schema->storage->txn_begin;
33
$schema->storage->txn_begin;
34
34
35
my $builder           = t::lib::TestBuilder->new;
35
my $builder           = t::lib::TestBuilder->new;
36
my $biblio_1          = $builder->build( { source => 'Biblio' } );
36
my $biblio_1          = $builder->build_sample_biblio;
37
my $biblio_2          = $builder->build( { source => 'Biblio' } );
37
my $biblio_2          = $builder->build_sample_biblio;
38
my $patron            = $builder->build( { source => 'Borrower' } );
38
my $patron            = $builder->build( { source => 'Borrower' } );
39
my $nb_of_suggestions = Koha::Suggestions->search->count;
39
my $nb_of_suggestions = Koha::Suggestions->search->count;
40
my $new_suggestion_1  = Koha::Suggestion->new(
40
my $new_suggestion_1  = Koha::Suggestion->new(
41
    {   suggestedby  => $patron->{borrowernumber},
41
    {   suggestedby  => $patron->{borrowernumber},
42
        biblionumber => $biblio_1->{biblionumber},
42
        biblionumber => $biblio_1->biblionumber,
43
    }
43
    }
44
)->store;
44
)->store;
45
my $new_suggestion_2 = Koha::Suggestion->new(
45
my $new_suggestion_2 = Koha::Suggestion->new(
46
    {   suggestedby  => $patron->{borrowernumber},
46
    {   suggestedby  => $patron->{borrowernumber},
47
        biblionumber => $biblio_2->{biblionumber},
47
        biblionumber => $biblio_2->biblionumber,
48
    }
48
    }
49
)->store;
49
)->store;
50
50
Lines 52-58 subtest 'store' => sub { Link Here
52
    plan tests => 3;
52
    plan tests => 3;
53
    my $suggestion  = Koha::Suggestion->new(
53
    my $suggestion  = Koha::Suggestion->new(
54
        {   suggestedby  => $patron->{borrowernumber},
54
        {   suggestedby  => $patron->{borrowernumber},
55
            biblionumber => $biblio_1->{biblionumber},
55
            biblionumber => $biblio_1->biblionumber,
56
        }
56
        }
57
    )->store;
57
    )->store;
58
58
(-)a/t/db_dependent/Koha/Z3950Responder/Session.t (-22 / +12 lines)
Lines 20-53 subtest 'add_item_status' => sub { Link Here
20
    plan tests => 2;
20
    plan tests => 2;
21
21
22
    ## FIRST ITEM HAS ALL THE STATUSES ##
22
    ## FIRST ITEM HAS ALL THE STATUSES ##
23
    my $item_1 = $builder->build({
23
    my $item_1 = $builder->build_sample_item(
24
        source => 'Item',
24
        {
25
        value => {
25
            onloan     => '2017-07-07',
26
            onloan => '2017-07-07',
26
            itemlost   => 1,
27
            itemlost => 1,
28
            notforloan => 1,
27
            notforloan => 1,
29
            damaged => 1,
28
            damaged    => 1,
30
            withdrawn => 1,
29
            withdrawn  => 1,
31
        }
30
        }
32
    });
31
    );
33
    my $item_marc_1 = C4::Items::GetMarcItem( $item_1->{biblionumber}, $item_1->{itemnumber} );
32
    my $item_marc_1 = C4::Items::GetMarcItem( $item_1->biblionumber, $item_1->itemnumber );
34
    my $item_field_1 = scalar $item_marc_1->field('952');
33
    my $item_field_1 = scalar $item_marc_1->field('952');
35
    $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->{itemnumber} } });
34
    $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->itemnumber } });
36
    $builder->build({ source => 'Branchtransfer', value=> { itemnumber => $item_1->{itemnumber}, datearrived => undef } });
35
    $builder->build({ source => 'Branchtransfer', value=> { itemnumber => $item_1->itemnumber, datearrived => undef } });
37
    ## END FIRST ITEM ##
36
    ## END FIRST ITEM ##
38
37
39
    ## SECOND ITEM HAS NO STATUSES ##
38
    ## SECOND ITEM HAS NO STATUSES ##
40
    my $item_2 = $builder->build({
39
    my $item_2 = $builder->build_sample_item;
41
        source => 'Item',
40
    my $item_marc_2 = C4::Items::GetMarcItem( $item_2->biblionumber, $item_2->itemnumber );
42
        value => {
43
            onloan => undef,
44
            itemlost => 0,
45
            notforloan => 0,
46
            damaged => 0,
47
            withdrawn => 0,
48
        }
49
    });
50
    my $item_marc_2 = C4::Items::GetMarcItem( $item_2->{biblionumber}, $item_2->{itemnumber} );
51
    my $item_field_2 = scalar $item_marc_2->field('952');
41
    my $item_field_2 = scalar $item_marc_2->field('952');
52
    ## END SECOND ITEM ##
42
    ## END SECOND ITEM ##
53
43
(-)a/t/db_dependent/Koha/Z3950Responder/Session2.t (-22 / +12 lines)
Lines 44-77 subtest 'add_item_status' => sub { Link Here
44
    });
44
    });
45
45
46
    ## FIRST ITEM HAS ALL THE STATUSES ##
46
    ## FIRST ITEM HAS ALL THE STATUSES ##
47
    my $item_1 = $builder->build({
47
    my $item_1 = $builder->build_sample_item(
48
        source => 'Item',
48
        {
49
        value => {
49
            onloan     => '2017-07-07',
50
            onloan => '2017-07-07',
50
            itemlost   => 1,
51
            itemlost => 1,
52
            notforloan => 1,
51
            notforloan => 1,
53
            damaged => 1,
52
            damaged    => 1,
54
            withdrawn => 1,
53
            withdrawn  => 1,
55
        }
54
        }
56
    });
55
    );
57
    my $item_marc_1 = C4::Items::GetMarcItem( $item_1->{biblionumber}, $item_1->{itemnumber} );
56
    my $item_marc_1 = C4::Items::GetMarcItem( $item_1->biblionumber, $item_1->itemnumber );
58
    my $item_field_1 = scalar $item_marc_1->field('952');
57
    my $item_field_1 = scalar $item_marc_1->field('952');
59
    $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->{itemnumber} } });
58
    $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->itemnumber } });
60
    $builder->build({ source => 'Branchtransfer', value=> { itemnumber => $item_1->{itemnumber}, datearrived => undef } });
59
    $builder->build({ source => 'Branchtransfer', value=> { itemnumber => $item_1->itemnumber, datearrived => undef } });
61
    ## END FIRST ITEM ##
60
    ## END FIRST ITEM ##
62
61
63
    ## SECOND ITEM HAS NO STATUSES ##
62
    ## SECOND ITEM HAS NO STATUSES ##
64
    my $item_2 = $builder->build({
63
    my $item_2 = $builder->build_sample_item;
65
        source => 'Item',
64
    my $item_marc_2 = C4::Items::GetMarcItem( $item_2->biblionumber, $item_2->itemnumber );
66
        value => {
67
            onloan => undef,
68
            itemlost => 0,
69
            notforloan => 0,
70
            damaged => 0,
71
            withdrawn => 0,
72
        }
73
    });
74
    my $item_marc_2 = C4::Items::GetMarcItem( $item_2->{biblionumber}, $item_2->{itemnumber} );
75
    my $item_field_2 = scalar $item_marc_2->field('952');
65
    my $item_field_2 = scalar $item_marc_2->field('952');
76
    ## END SECOND ITEM ##
66
    ## END SECOND ITEM ##
77
67
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-33 / +24 lines)
Lines 292-336 subtest 'regression tests' => sub { Link Here
292
292
293
    my $library = $builder->build( { source => 'Branch' } );
293
    my $library = $builder->build( { source => 'Branch' } );
294
    my $patron  = $builder->build( { source => 'Borrower' } );
294
    my $patron  = $builder->build( { source => 'Borrower' } );
295
    my $biblio1 = Koha::Biblio->new({title => 'Test Biblio 1', author => 'An author', })->store->unblessed;
295
    my $item1 = $builder->build_sample_item(
296
    my $biblioitem1 = Koha::Biblioitem->new({biblionumber => $biblio1->{biblionumber}})->store()->unblessed;
297
    my $item1 = Koha::Item->new(
298
        {
296
        {
299
            biblionumber     => $biblio1->{biblionumber},
297
            barcode        => 'a_t_barcode',
300
            biblioitemnumber => $biblioitem1->{biblioitemnumber},
298
            library        => $library->{branchcode},
301
            barcode          => 'a_t_barcode',
299
            itype          => 'BK',
302
            homebranch       => $library->{branchcode},
300
            itemcallnumber => 'itemcallnumber1',
303
            holdingbranch    => $library->{branchcode},
304
            itype            => 'BK',
305
            itemcallnumber   => 'itemcallnumber1',
306
        }
301
        }
307
    )->store->unblessed;
302
    );
308
    my $biblio2 = Koha::Biblio->new({title => 'Test Biblio 2'})->store->unblessed;
303
    my $biblio1 = $item1->biblio->unblessed;
309
    my $biblioitem2 = Koha::Biblioitem->new({biblionumber => $biblio2->{biblionumber}})->store()->unblessed;
304
    $item1 = $item1->unblessed;
310
    my $item2 = Koha::Item->new(
305
    my $item2   = $builder->build_sample_item(
311
        {
306
        {
312
            biblionumber     => $biblio2->{biblionumber},
307
            barcode        => 'another_t_barcode',
313
            biblioitemnumber => $biblioitem2->{biblioitemnumber},
308
            library        => $library->{branchcode},
314
            barcode          => 'another_t_barcode',
309
            itype          => 'BK',
315
            homebranch       => $library->{branchcode},
310
            itemcallnumber => 'itemcallnumber2',
316
            holdingbranch    => $library->{branchcode},
317
            itype            => 'BK',
318
            itemcallnumber   => 'itemcallnumber2',
319
        }
311
        }
320
    )->store->unblessed;
312
    );
321
    my $biblio3 = Koha::Biblio->new({title => 'Test Biblio 3'})->store->unblessed;
313
    my $biblio2 = $item2->biblio->unblessed;
322
    my $biblioitem3 = Koha::Biblioitem->new({biblionumber => $biblio3->{biblionumber}})->store()->unblessed;
314
    $item2 = $item2->unblessed;
323
    my $item3 = Koha::Item->new(
315
    my $item3   = $builder->build_sample_item(
324
        {
316
        {
325
            biblionumber     => $biblio3->{biblionumber},
317
            barcode        => 'another_t_barcode_3',
326
            biblioitemnumber => $biblioitem3->{biblioitemnumber},
318
            library        => $library->{branchcode},
327
            barcode          => 'another_t_barcode_3',
319
            itype          => 'BK',
328
            homebranch       => $library->{branchcode},
320
            itemcallnumber => 'itemcallnumber3',
329
            holdingbranch    => $library->{branchcode},
330
            itype            => 'BK',
331
            itemcallnumber   => 'itemcallnumber3',
332
        }
321
        }
333
    )->store->unblessed;
322
    );
323
    my $biblio3 = $item3->biblio->unblessed;
324
    $item3 = $item3->unblessed;
334
325
335
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
326
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
336
327
(-)a/t/db_dependent/Reserves.t (-5 / +2 lines)
Lines 87-96 my $bibnum = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->b Link Here
87
# Create a helper item instance for testing
87
# Create a helper item instance for testing
88
my $item = $builder->build_sample_item({ biblionumber => $bibnum, library => $branch_1, itype => $itemtype });
88
my $item = $builder->build_sample_item({ biblionumber => $bibnum, library => $branch_1, itype => $itemtype });
89
89
90
my $biblio_with_no_item = $builder->build({
90
my $biblio_with_no_item = $builder->build_sample_biblio;
91
    source => 'Biblio'
92
});
93
94
91
95
# Modify item; setting barcode.
92
# Modify item; setting barcode.
96
my $testbarcode = '97531';
93
my $testbarcode = '97531';
Lines 601-607 Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofb Link Here
601
598
602
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
599
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
603
600
604
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{biblionumber})->{status} , '', "Biblio with no item. Status is empty");
601
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->biblionumber)->{status} , '', "Biblio with no item. Status is empty");
605
       ####
602
       ####
606
####### EO Bug 13113 <<<
603
####### EO Bug 13113 <<<
607
       ####
604
       ####
(-)a/t/db_dependent/Reserves/CancelExpiredReserves.t (-7 / +5 lines)
Lines 111-120 subtest 'Test handling of waiting reserves by CancelExpiredReserves' => sub { Link Here
111
    my $builder = t::lib::TestBuilder->new();
111
    my $builder = t::lib::TestBuilder->new();
112
    my $category = $builder->build({ source => 'Category' });
112
    my $category = $builder->build({ source => 'Category' });
113
    my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
113
    my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
114
    my $biblio = $builder->build({ source => 'Biblio' });
114
    my $item = $builder->build_sample_item;
115
    my $bibnum = $biblio->{biblionumber};
115
    my $itemnumber = $item->itemnumber;
116
    my $item = $builder->build({ source => 'Item', value => { biblionumber => $bibnum }});
117
    my $itemnumber = $item->{itemnumber};
118
    my $borrowernumber = $builder->build({ source => 'Borrower', value => { categorycode => $category->{categorycode}, branchcode => $branchcode }})->{borrowernumber};
116
    my $borrowernumber = $builder->build({ source => 'Borrower', value => { categorycode => $category->{categorycode}, branchcode => $branchcode }})->{borrowernumber};
119
117
120
    my $resdate = dt_from_string->add( days => -20 );
118
    my $resdate = dt_from_string->add( days => -20 );
Lines 124-130 subtest 'Test handling of waiting reserves by CancelExpiredReserves' => sub { Link Here
124
    my $hold1 = Koha::Hold->new({
122
    my $hold1 = Koha::Hold->new({
125
        branchcode => $branchcode,
123
        branchcode => $branchcode,
126
        borrowernumber => $borrowernumber,
124
        borrowernumber => $borrowernumber,
127
        biblionumber => $bibnum,
125
        biblionumber => $item->biblionumber,
128
        priority => 1,
126
        priority => 1,
129
        reservedate => $resdate,
127
        reservedate => $resdate,
130
        expirationdate => $notexpdate,
128
        expirationdate => $notexpdate,
Lines 134-140 subtest 'Test handling of waiting reserves by CancelExpiredReserves' => sub { Link Here
134
    my $hold2 = Koha::Hold->new({
132
    my $hold2 = Koha::Hold->new({
135
        branchcode => $branchcode,
133
        branchcode => $branchcode,
136
        borrowernumber => $borrowernumber,
134
        borrowernumber => $borrowernumber,
137
        biblionumber => $bibnum,
135
        biblionumber => $item->biblionumber,
138
        priority => 2,
136
        priority => 2,
139
        reservedate => $resdate,
137
        reservedate => $resdate,
140
        expirationdate => $expdate,
138
        expirationdate => $expdate,
Lines 144-150 subtest 'Test handling of waiting reserves by CancelExpiredReserves' => sub { Link Here
144
    my $hold3 = Koha::Hold->new({
142
    my $hold3 = Koha::Hold->new({
145
        branchcode => $branchcode,
143
        branchcode => $branchcode,
146
        borrowernumber => $borrowernumber,
144
        borrowernumber => $borrowernumber,
147
        biblionumber => $bibnum,
145
        biblionumber => $item->biblionumber,
148
        itemnumber => $itemnumber,
146
        itemnumber => $itemnumber,
149
        priority => 0,
147
        priority => 0,
150
        reservedate => $resdate,
148
        reservedate => $resdate,
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-41 / +34 lines)
Lines 69-119 my $patron3 = $builder->build({ Link Here
69
});
69
});
70
70
71
# One biblio and two items
71
# One biblio and two items
72
my $biblio = $builder->build({
72
my $biblio = $builder->build_sample_biblio;
73
    source => 'Biblio',
73
my $item1 = $builder->build_sample_item(
74
    value  => {
74
    {
75
        title => 'Title 1',
75
        biblionumber => $biblio->biblionumber,
76
    },
76
        notforloan   => 0,
77
});
77
    }
78
my $item1 = $builder->build({
78
);
79
    source => 'Item',
79
my $item2 = $builder->build_sample_item(
80
    value  => {
80
    {
81
        biblionumber => $biblio->{biblionumber},
81
        biblionumber => $biblio->biblionumber,
82
        notforloan => 0,
82
        notforloan   => 0,
83
    },
83
    }
84
});
84
);
85
my $item2 = $builder->build({
86
    source => 'Item',
87
    value  => {
88
        biblionumber => $biblio->{biblionumber},
89
        notforloan => 0,
90
    },
91
});
92
85
93
subtest 'GetReserveFee' => sub {
86
subtest 'GetReserveFee' => sub {
94
    plan tests => 5;
87
    plan tests => 5;
95
88
96
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
89
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
97
    my $acc2 = acctlines( $patron2->{borrowernumber} );
90
    my $acc2 = acctlines( $patron2->{borrowernumber} );
98
    my $res1 = addreserve( $patron1->{borrowernumber} );
91
    my $res1 = addreserve( $patron1->{borrowernumber} );
99
92
100
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
93
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
101
    my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
94
    my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
102
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
95
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
103
    C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->{title} );
96
    C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->title );
104
    is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
97
    is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
105
98
106
    # If we delete the reserve, there should be no charge
99
    # If we delete the reserve, there should be no charge
107
    $dbh->do( "DELETE FROM reserves WHERE borrowernumber = ?", undef, ( $patron1->{borrowernumber}) );
100
    $dbh->do( "DELETE FROM reserves WHERE borrowernumber = ?", undef, ( $patron1->{borrowernumber}) );
108
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
101
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
109
    is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
102
    is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
110
103
111
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
104
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
112
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
105
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
113
    is( int($fee), 2, 'HoldFeeMode=any_time_is_placed, Patron 2 should be charged' );
106
    is( int($fee), 2, 'HoldFeeMode=any_time_is_placed, Patron 2 should be charged' );
114
107
115
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
108
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
116
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
109
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
117
    is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
110
    is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
118
};
111
};
119
112
Lines 126-144 subtest 'Integration with AddReserve' => sub { Link Here
126
        plan tests => 3;
119
        plan tests => 3;
127
120
128
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
121
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
129
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
122
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
130
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
123
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
131
        addreserve( $patron1->{borrowernumber} );
124
        addreserve( $patron1->{borrowernumber} );
132
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - No fee charged for patron 1 if not issued' );
125
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - No fee charged for patron 1 if not issued' );
133
126
134
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
127
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
135
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
128
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
136
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
129
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
137
        addreserve( $patron1->{borrowernumber} );
130
        addreserve( $patron1->{borrowernumber} );
138
        is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_placed - Patron should be always charged' );
131
        is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_placed - Patron should be always charged' );
139
132
140
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
133
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
141
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
134
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
142
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
135
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
143
        addreserve( $patron1->{borrowernumber} );
136
        addreserve( $patron1->{borrowernumber} );
144
        is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when placing a hold' );
137
        is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when placing a hold' );
Lines 147-169 subtest 'Integration with AddReserve' => sub { Link Here
147
    subtest 'Items are issued' => sub {
140
    subtest 'Items are issued' => sub {
148
        plan tests => 3;
141
        plan tests => 3;
149
142
150
        C4::Circulation::AddIssue( $patron2, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
143
        C4::Circulation::AddIssue( $patron2, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
151
144
152
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
145
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
153
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
146
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
154
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
147
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
155
        addreserve( $patron1->{borrowernumber} );
148
        addreserve( $patron1->{borrowernumber} );
156
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if items are not all checked out' );
149
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if items are not all checked out' );
157
150
158
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
151
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
159
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
152
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
160
        addreserve( $patron3->{borrowernumber} );
153
        addreserve( $patron3->{borrowernumber} );
161
        addreserve( $patron1->{borrowernumber} );
154
        addreserve( $patron1->{borrowernumber} );
162
        # FIXME Are we sure it's the expected behavior?
155
        # FIXME Are we sure it's the expected behavior?
163
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should be charged if all the items are not checked out and at least 1 hold is already placed' );
156
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should be charged if all the items are not checked out and at least 1 hold is already placed' );
164
157
165
        C4::Circulation::AddIssue( $patron3, $item2->{barcode}, '2015-12-31', 0, undef, 0, {} );
158
        C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} );
166
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
159
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
167
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
160
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
168
        addreserve( $patron1->{borrowernumber} );
161
        addreserve( $patron1->{borrowernumber} );
169
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should be charged if all items are checked out' );
162
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should be charged if all items are checked out' );
Lines 174-200 subtest 'Integration with AddIssue' => sub { Link Here
174
    plan tests => 5;
167
    plan tests => 5;
175
168
176
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
169
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
177
    $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
170
    $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
178
    $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
171
    $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
179
172
180
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
173
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
181
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
174
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
182
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
175
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
183
176
184
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
177
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
185
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
178
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
186
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
179
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
187
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
180
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
188
181
189
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
182
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
190
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
183
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
191
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
184
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
192
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
185
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
193
186
194
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
187
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
195
    my $id = addreserve( $patron1->{borrowernumber} );
188
    my $id = addreserve( $patron1->{borrowernumber} );
196
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged yet (just checking to make sure)');
189
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged yet (just checking to make sure)');
197
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
190
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
198
    is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
191
    is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
199
};
192
};
200
193
Lines 208-216 sub addreserve { Link Here
208
        {
201
        {
209
            branchcode     => $library->{branchcode},
202
            branchcode     => $library->{branchcode},
210
            borrowernumber => $_[0],
203
            borrowernumber => $_[0],
211
            biblionumber   => $biblio->{biblionumber},
204
            biblionumber   => $biblio->biblionumber,
212
            priority       => '1',
205
            priority       => '1',
213
            title          => $biblio->{title},
206
            title          => $biblio->title,
214
        }
207
        }
215
    );
208
    );
216
}
209
}
(-)a/t/db_dependent/Reserves/MultiplePerRecord.t (-56 / +28 lines)
Lines 64-117 my $itemtype2 = $builder->build( Link Here
64
    }
64
    }
65
);
65
);
66
66
67
my $biblio = $builder->build(
67
my $biblio = $builder->build_sample_biblio;
68
my $item1 = $builder->build_sample_item(
68
    {
69
    {
69
        source => 'Biblio',
70
        biblionumber => $biblio->biblionumber,
70
        value  => {
71
        itype        => $itemtype1->{itemtype},
71
            title => 'Title 1',
72
        library      => $library->{branchcode},
72
        },
73
    },
73
    }
74
);
75
my $biblioitem = $builder->build(
76
    {
77
        source => 'Biblioitem',
78
        value  => { biblionumber => $biblio->{biblionumber} }
79
    }
80
);
74
);
81
my $item1 = $builder->build(
75
my $item2 = $builder->build_sample_item(
82
    {
76
    {
83
        source => 'Item',
77
        biblionumber => $biblio->biblionumber,
84
        value  => {
78
        itype        => $itemtype2->{itemtype},
85
            biblionumber  => $biblio->{biblionumber},
79
        library      => $library->{branchcode},
86
            itype         => $itemtype1->{itemtype},
87
            homebranch    => $library->{branchcode},
88
            holdingbranch => $library->{branchcode},
89
            damaged       => 0,
90
        },
91
    }
80
    }
92
);
81
);
93
my $item2 = $builder->build(
82
my $item3 = $builder->build_sample_item(
94
    {
83
    {
95
        source => 'Item',
84
        biblionumber => $biblio->biblionumber,
96
        value  => {
85
        itype        => $itemtype2->{itemtype},
97
            biblionumber  => $biblio->{biblionumber},
86
        library      => $library->{branchcode},
98
            itype         => $itemtype2->{itemtype},
99
            homebranch    => $library->{branchcode},
100
            holdingbranch => $library->{branchcode},
101
            damaged       => 0,
102
        },
103
    }
104
);
105
my $item3 = $builder->build(
106
    {
107
        source => 'Item',
108
        value  => {
109
            biblionumber  => $biblio->{biblionumber},
110
            itype         => $itemtype2->{itemtype},
111
            homebranch    => $library->{branchcode},
112
            holdingbranch => $library->{branchcode},
113
            damaged       => 0,
114
        },
115
    }
87
    }
116
);
88
);
117
89
Lines 132-138 Koha::CirculationRules->set_rules( Link Here
132
104
133
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
105
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level
134
106
135
my $max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} );
107
my $max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
136
is( $max, 1, 'GetMaxPatronHoldsForRecord returns max of 1' );
108
is( $max, 1, 'GetMaxPatronHoldsForRecord returns max of 1' );
137
my $rule = C4::Reserves::GetHoldRule(
109
my $rule = C4::Reserves::GetHoldRule(
138
    $category->{categorycode},
110
    $category->{categorycode},
Lines 157-163 Koha::CirculationRules->set_rules( Link Here
157
    }
129
    }
158
);
130
);
159
131
160
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} );
132
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
161
is( $max, 2, 'GetMaxPatronHoldsForRecord returns max of 2' );
133
is( $max, 2, 'GetMaxPatronHoldsForRecord returns max of 2' );
162
$rule = C4::Reserves::GetHoldRule(
134
$rule = C4::Reserves::GetHoldRule(
163
    $category->{categorycode},
135
    $category->{categorycode},
Lines 182-188 Koha::CirculationRules->set_rules( Link Here
182
    }
154
    }
183
);
155
);
184
156
185
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} );
157
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
186
is( $max, 3, 'GetMaxPatronHoldsForRecord returns max of 3' );
158
is( $max, 3, 'GetMaxPatronHoldsForRecord returns max of 3' );
187
$rule = C4::Reserves::GetHoldRule(
159
$rule = C4::Reserves::GetHoldRule(
188
    $category->{categorycode},
160
    $category->{categorycode},
Lines 207-213 Koha::CirculationRules->set_rules( Link Here
207
    }
179
    }
208
);
180
);
209
181
210
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} );
182
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
211
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' );
183
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' );
212
$rule = C4::Reserves::GetHoldRule(
184
$rule = C4::Reserves::GetHoldRule(
213
    $category->{categorycode},
185
    $category->{categorycode},
Lines 232-238 Koha::CirculationRules->set_rules( Link Here
232
    }
204
    }
233
);
205
);
234
206
235
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} );
207
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
236
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 1' );
208
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 1' );
237
$rule = C4::Reserves::GetHoldRule(
209
$rule = C4::Reserves::GetHoldRule(
238
    $category->{categorycode},
210
    $category->{categorycode},
Lines 254-260 is( $holds->forced_hold_level, undef, "No holds does not force an item or record Link Here
254
my $hold = Koha::Hold->new({
226
my $hold = Koha::Hold->new({
255
    borrowernumber => $patron->{borrowernumber},
227
    borrowernumber => $patron->{borrowernumber},
256
    reservedate => '1981-06-10',
228
    reservedate => '1981-06-10',
257
    biblionumber => $biblio->{biblionumber},
229
    biblionumber => $biblio->biblionumber,
258
    branchcode => $library->{branchcode},
230
    branchcode => $library->{branchcode},
259
    priority => 1,
231
    priority => 1,
260
})->store();
232
})->store();
Lines 262-268 my $hold = Koha::Hold->new({ Link Here
262
$holds = Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } );
234
$holds = Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } );
263
is( $holds->forced_hold_level, 'record', "Record level hold forces record level holds" );
235
is( $holds->forced_hold_level, 'record', "Record level hold forces record level holds" );
264
236
265
$hold->itemnumber( $item1->{itemnumber} );
237
$hold->itemnumber( $item1->itemnumber );
266
$hold->store();
238
$hold->store();
267
239
268
$holds = Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } );
240
$holds = Koha::Holds->search( { borrowernumber => $patron->{borrowernumber} } );
Lines 283-320 Koha::CirculationRules->set_rules( Link Here
283
    }
255
    }
284
);
256
);
285
257
286
my $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
258
my $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->biblionumber);
287
is( $can->{status}, 'OK', 'Hold can be placed with 0 holds' );
259
is( $can->{status}, 'OK', 'Hold can be placed with 0 holds' );
288
my $hold_id = AddReserve(
260
my $hold_id = AddReserve(
289
    {
261
    {
290
        branchcode     => $library->{branchcode},
262
        branchcode     => $library->{branchcode},
291
        borrowernumber => $patron->{borrowernumber},
263
        borrowernumber => $patron->{borrowernumber},
292
        biblionumber   => $biblio->{biblionumber},
264
        biblionumber   => $biblio->biblionumber,
293
        priority       => 1
265
        priority       => 1
294
    }
266
    }
295
);
267
);
296
ok( $hold_id, 'First hold was placed' );
268
ok( $hold_id, 'First hold was placed' );
297
269
298
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
270
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->biblionumber);
299
is( $can->{status}, 'OK', 'Hold can be placed with 1 hold' );
271
is( $can->{status}, 'OK', 'Hold can be placed with 1 hold' );
300
$hold_id = AddReserve(
272
$hold_id = AddReserve(
301
    {
273
    {
302
        branchcode     => $library->{branchcode},
274
        branchcode     => $library->{branchcode},
303
        borrowernumber => $patron->{borrowernumber},
275
        borrowernumber => $patron->{borrowernumber},
304
        biblionumber   => $biblio->{biblionumber},
276
        biblionumber   => $biblio->biblionumber,
305
        priority       => 1
277
        priority       => 1
306
    }
278
    }
307
);
279
);
308
ok( $hold_id, 'Second hold was placed' );
280
ok( $hold_id, 'Second hold was placed' );
309
281
310
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
282
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->biblionumber);
311
is( $can->{status}, 'tooManyHoldsForThisRecord', 'Third hold exceeds limit of holds per record' );
283
is( $can->{status}, 'tooManyHoldsForThisRecord', 'Third hold exceeds limit of holds per record' );
312
284
313
Koha::Holds->find($hold_id)->found("W")->store;
285
Koha::Holds->find($hold_id)->found("W")->store;
314
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
286
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->biblionumber);
315
is( $can->{status}, 'tooManyHoldsForThisRecord', 'Third hold exceeds limit of holds per record' );
287
is( $can->{status}, 'tooManyHoldsForThisRecord', 'Third hold exceeds limit of holds per record' );
316
288
317
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber}, undef, { ignore_found_holds => 1 });
289
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->biblionumber, undef, { ignore_found_holds => 1 });
318
is( $can->{status}, 'OK', 'Third hold is allowed when ignoring waiting holds' );
290
is( $can->{status}, 'OK', 'Third hold is allowed when ignoring waiting holds' );
319
291
320
$schema->storage->txn_rollback;
292
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Reserves/ReserveSlip.t (-29 / +12 lines)
Lines 50-90 my $patron = $builder->build( Link Here
50
);
50
);
51
51
52
52
53
my $biblio = $builder->build(
53
my $biblio = $builder->build_sample_biblio;
54
my $item1 = $builder->build_sample_item(
54
    {
55
    {
55
        source => 'Biblio',
56
        biblionumber => $biblio->biblionumber,
56
        value  => {
57
        library      => $library->{branchcode},
57
            title => 'Title 1',
58
        },
59
    }
58
    }
60
);
59
);
61
60
my $item2 = $builder->build_sample_item(
62
my $item1 = $builder->build(
63
    {
61
    {
64
        source => 'Item',
62
        biblionumber => $biblio->biblionumber,
65
        value  => {
63
        library      => $library->{branchcode},
66
            biblionumber  => $biblio->{biblionumber},
67
            homebranch    => $library->{branchcode},
68
            holdingbranch => $library->{branchcode},
69
        },
70
    }
71
);
72
73
my $item2 = $builder->build(
74
    {
75
        source => 'Item',
76
        value  => {
77
            biblionumber  => $biblio->{biblionumber},
78
            homebranch    => $library->{branchcode},
79
            holdingbranch => $library->{branchcode},
80
        },
81
    }
64
    }
82
);
65
);
83
66
84
my $hold1 = Koha::Hold->new(
67
my $hold1 = Koha::Hold->new(
85
    {
68
    {
86
        biblionumber   => $biblio->{biblionumber},
69
        biblionumber   => $biblio->biblionumber,
87
        itemnumber     => $item1->{itemnumber},
70
        itemnumber     => $item1->itemnumber,
88
        waitingdate    => '2000-01-01',
71
        waitingdate    => '2000-01-01',
89
        borrowernumber => $patron->{borrowernumber},
72
        borrowernumber => $patron->{borrowernumber},
90
        branchcode     => $library->{branchcode},
73
        branchcode     => $library->{branchcode},
Lines 93-100 my $hold1 = Koha::Hold->new( Link Here
93
76
94
my $hold2 = Koha::Hold->new(
77
my $hold2 = Koha::Hold->new(
95
    {
78
    {
96
        biblionumber   => $biblio->{biblionumber},
79
        biblionumber   => $biblio->biblionumber,
97
        itemnumber     => $item2->{itemnumber},
80
        itemnumber     => $item2->itemnumber,
98
        waitingdate    => '2000-01-01',
81
        waitingdate    => '2000-01-01',
99
        borrowernumber => $patron->{borrowernumber},
82
        borrowernumber => $patron->{borrowernumber},
100
        branchcode     => $library->{branchcode},
83
        branchcode     => $library->{branchcode},
Lines 126-132 is (ReserveSlip({ Link Here
126
        branchcode     => $library->{branchcode},
109
        branchcode     => $library->{branchcode},
127
        reserve_id     => $hold1->reserve_id,
110
        reserve_id     => $hold1->reserve_id,
128
    })->{content},
111
    })->{content},
129
    "Hold found for $patron->{firstname}: Please pick up $biblio->{title} with barcode $item1->{barcode} at $library->{branchcode}.", "Hold slip contains correctly parsed content");
112
    sprintf( "Hold found for %s: Please pick up %s with barcode %s at %s.", $patron->{firstname}, $biblio->title, $item1->barcode, $library->{branchcode}),"Hold slip contains correctly parsed content");
130
113
131
$schema->storage->txn_rollback;
114
$schema->storage->txn_rollback;
132
115
(-)a/t/db_dependent/SIP/Message.t (-10 / +10 lines)
Lines 176-189 subtest "Test build_additional_item_fields_string" => sub { Link Here
176
176
177
    my $builder = t::lib::TestBuilder->new();
177
    my $builder = t::lib::TestBuilder->new();
178
178
179
    my $item = $builder->build( { source => 'Item' } );
179
    my $item = $builder->build_sample_item;
180
    my $ils_item = C4::SIP::ILS::Item->new( $item->{barcode} );
180
    my $ils_item = C4::SIP::ILS::Item->new( $item->barcode );
181
181
182
    my $server = {};
182
    my $server = {};
183
    $server->{account}->{item_field}->{code} = 'itemnumber';
183
    $server->{account}->{item_field}->{code} = 'itemnumber';
184
    $server->{account}->{item_field}->{field} = 'XY';
184
    $server->{account}->{item_field}->{field} = 'XY';
185
    my $attribute_string = $ils_item->build_additional_item_fields_string( $server );
185
    my $attribute_string = $ils_item->build_additional_item_fields_string( $server );
186
    is( $attribute_string, "XY$item->{itemnumber}|", 'Attribute field generated correctly with single param' );
186
    is( $attribute_string, "XY".$item->itemnumber."|", 'Attribute field generated correctly with single param' );
187
187
188
    $server = {};
188
    $server = {};
189
    $server->{account}->{item_field}->[0]->{code} = 'itemnumber';
189
    $server->{account}->{item_field}->[0]->{code} = 'itemnumber';
Lines 191-197 subtest "Test build_additional_item_fields_string" => sub { Link Here
191
    $server->{account}->{item_field}->[1]->{code} = 'biblionumber';
191
    $server->{account}->{item_field}->[1]->{code} = 'biblionumber';
192
    $server->{account}->{item_field}->[1]->{field} = 'YZ';
192
    $server->{account}->{item_field}->[1]->{field} = 'YZ';
193
    $attribute_string = $ils_item->build_additional_item_fields_string( $server );
193
    $attribute_string = $ils_item->build_additional_item_fields_string( $server );
194
    is( $attribute_string, "XY$item->{itemnumber}|YZ$item->{biblionumber}|", 'Attribute field generated correctly with multiple params' );
194
    is( $attribute_string, sprintf("XY%s|YZ%s|", $item->itemnumber, $item->biblionumber), 'Attribute field generated correctly with multiple params' );
195
195
196
    $schema->storage->txn_rollback;
196
    $schema->storage->txn_rollback;
197
};
197
};
Lines 604-617 sub test_hold_patron_bcode { Link Here
604
    my ( $response, $findpatron );
604
    my ( $response, $findpatron );
605
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
605
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
606
606
607
    my $item = $builder->build({
607
    my $item = $builder->build_sample_item(
608
        source => 'Item',
608
        {
609
        value => { damaged => 0, withdrawn => 0, itemlost => 0, restricted => 0, homebranch => $branchcode, holdingbranch => $branchcode },
609
            library => $branchcode
610
    });
610
        }
611
    my $item_object = Koha::Items->find( $item->{itemnumber} );
611
    );
612
612
613
    my $server = { ils => $mocks->{ils} };
613
    my $server = { ils => $mocks->{ils} };
614
    my $sip_item = C4::SIP::ILS::Item->new( $item->{barcode} );
614
    my $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
615
615
616
    is( $sip_item->hold_patron_bcode, q{}, "SIP item with no hold returns empty string" );
616
    is( $sip_item->hold_patron_bcode, q{}, "SIP item with no hold returns empty string" );
617
617
(-)a/t/db_dependent/StockRotationRotas.t (-5 / +5 lines)
Lines 66-77 subtest 'Basic object tests' => sub { Link Here
66
66
67
    #### Test add_item
67
    #### Test add_item
68
68
69
    my $item = $builder->build({ source => 'Item' });
69
    my $item = $builder->build_sample_item;
70
70
71
    $srrota->add_item($item->{itemnumber});
71
    $srrota->add_item($item->itemnumber);
72
72
73
    is(
73
    is(
74
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
74
        Koha::StockRotationItems->find($item->itemnumber)->stage_id,
75
        $srrota->first_stage->stage_id,
75
        $srrota->first_stage->stage_id,
76
        "Adding an item results in a new sritem item being assigned to the first stage."
76
        "Adding an item results in a new sritem item being assigned to the first stage."
77
    );
77
    );
Lines 85-94 subtest 'Basic object tests' => sub { Link Here
85
        value  => { rota_id => $newrota->{rota_id} },
85
        value  => { rota_id => $newrota->{rota_id} },
86
    });
86
    });
87
87
88
    $srnewrota->add_item($item->{itemnumber});
88
    $srnewrota->add_item($item->itemnumber);
89
89
90
    is(
90
    is(
91
        Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
91
        Koha::StockRotationItems->find($item->itemnumber)->stage_id,
92
        $srnewrota->stockrotationstages->next->stage_id,
92
        $srnewrota->stockrotationstages->next->stage_id,
93
        "Moving an item results in that sritem being assigned to the new first stage."
93
        "Moving an item results in that sritem being assigned to the new first stage."
94
    );
94
    );
(-)a/t/db_dependent/Virtualshelves.t (-36 / +35 lines)
Lines 174-183 subtest 'Shelf content' => sub { Link Here
174
    plan tests => 18;
174
    plan tests => 18;
175
    my $patron1 = $builder->build( { source => 'Borrower', } );
175
    my $patron1 = $builder->build( { source => 'Borrower', } );
176
    my $patron2 = $builder->build( { source => 'Borrower', } );
176
    my $patron2 = $builder->build( { source => 'Borrower', } );
177
    my $biblio1 = $builder->build( { source => 'Biblio', } );
177
    my $biblio1 = $builder->build_sample_biblio;
178
    my $biblio2 = $builder->build( { source => 'Biblio', } );
178
    my $biblio2 = $builder->build_sample_biblio;
179
    my $biblio3 = $builder->build( { source => 'Biblio', } );
179
    my $biblio3 = $builder->build_sample_biblio;
180
    my $biblio4 = $builder->build( { source => 'Biblio', } );
180
    my $biblio4 = $builder->build_sample_biblio;
181
    my $number_of_contents = Koha::Virtualshelfcontents->search->count;
181
    my $number_of_contents = Koha::Virtualshelfcontents->search->count;
182
182
183
    is( $number_of_contents, 0, 'No content should exist' );
183
    is( $number_of_contents, 0, 'No content should exist' );
Lines 193-207 subtest 'Shelf content' => sub { Link Here
193
193
194
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
194
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
195
    is( t::lib::Dates::compare( $shelf->lastmodified, $dt_yesterday), 0, 'The lastmodified has been set to yesterday, will be useful for another test later' );
195
    is( t::lib::Dates::compare( $shelf->lastmodified, $dt_yesterday), 0, 'The lastmodified has been set to yesterday, will be useful for another test later' );
196
    my $content1 = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
196
    my $content1 = $shelf->add_biblio( $biblio1->biblionumber, $patron1->{borrowernumber} );
197
    is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' );
197
    is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' );
198
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
198
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
199
    is( t::lib::Dates::compare( $shelf->lastmodified, dt_from_string), 0, 'Adding a biblio to a shelf should update the lastmodified for the shelf' );
199
    is( t::lib::Dates::compare( $shelf->lastmodified, dt_from_string), 0, 'Adding a biblio to a shelf should update the lastmodified for the shelf' );
200
    my $content2 = $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
200
    my $content2 = $shelf->add_biblio( $biblio2->biblionumber, $patron1->{borrowernumber} );
201
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
201
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
202
    is( $number_of_contents, 2, '2 biblio should have been inserted' );
202
    is( $number_of_contents, 2, '2 biblio should have been inserted' );
203
203
204
    my $content1_bis = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
204
    my $content1_bis = $shelf->add_biblio( $biblio1->biblionumber, $patron1->{borrowernumber} );
205
    is( $content1_bis, undef, 'add_biblio should return undef on duplicate' );    # Or an exception ?
205
    is( $content1_bis, undef, 'add_biblio should return undef on duplicate' );    # Or an exception ?
206
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
206
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
207
    is( $number_of_contents, 2, 'The biblio should not have been duplicated' );
207
    is( $number_of_contents, 2, 'The biblio should not have been duplicated' );
Lines 212-221 subtest 'Shelf content' => sub { Link Here
212
212
213
    # Patron 2 will try to remove biblios
213
    # Patron 2 will try to remove biblios
214
    # allow_change_from_owner = 1, allow_change_from_others = 0 (defaults)
214
    # allow_change_from_owner = 1, allow_change_from_others = 0 (defaults)
215
    my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
215
    my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->biblionumber ], borrowernumber => $patron2->{borrowernumber} } );
216
    is( $number_of_deleted_biblios, 0, 'Patron 2 removed nothing' );
216
    is( $number_of_deleted_biblios, 0, 'Patron 2 removed nothing' );
217
    # Now try with patron 1
217
    # Now try with patron 1
218
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
218
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->biblionumber ], borrowernumber => $patron1->{borrowernumber} } );
219
    is( $number_of_deleted_biblios, 1, 'Patron 1 removed biblio' );
219
    is( $number_of_deleted_biblios, 1, 'Patron 1 removed biblio' );
220
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
220
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
221
    is( $number_of_contents, 1, 'To be sure the content has been deleted' );
221
    is( $number_of_contents, 1, 'To be sure the content has been deleted' );
Lines 223-248 subtest 'Shelf content' => sub { Link Here
223
    # allow_change_from_owner == 0 (readonly)
223
    # allow_change_from_owner == 0 (readonly)
224
    $shelf->allow_change_from_owner( 0 );
224
    $shelf->allow_change_from_owner( 0 );
225
    $shelf->store;
225
    $shelf->store;
226
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
226
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->biblionumber ], borrowernumber => $patron1->{borrowernumber} } );
227
    is( $number_of_deleted_biblios, 0, 'Owner could not delete' );
227
    is( $number_of_deleted_biblios, 0, 'Owner could not delete' );
228
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
228
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
229
    is( $number_of_contents, 1, 'Number of entries still equal to 1' );
229
    is( $number_of_contents, 1, 'Number of entries still equal to 1' );
230
    $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
230
    $shelf->add_biblio( $biblio2->biblionumber, $patron1->{borrowernumber} );
231
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
231
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
232
    is( $number_of_contents, 1, 'Biblio not added to the list' );
232
    is( $number_of_contents, 1, 'Biblio not added to the list' );
233
    # Add back biblio1
233
    # Add back biblio1
234
    $shelf->allow_change_from_owner( 1 );
234
    $shelf->allow_change_from_owner( 1 );
235
    $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
235
    $shelf->add_biblio( $biblio1->biblionumber, $patron1->{borrowernumber} );
236
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
236
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
237
    is( $number_of_contents, 2, 'Biblio added to the list' );
237
    is( $number_of_contents, 2, 'Biblio added to the list' );
238
238
239
    # allow_change_from_others == 1
239
    # allow_change_from_others == 1
240
    $shelf->allow_change_from_others( 1 );
240
    $shelf->allow_change_from_others( 1 );
241
    my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
241
    my $content3 = $shelf->add_biblio( $biblio3->biblionumber, $patron2->{borrowernumber} );
242
    my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
242
    my $content4 = $shelf->add_biblio( $biblio4->biblionumber, $patron2->{borrowernumber} );
243
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
243
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
244
    is( $number_of_contents, 4, 'The biblio should have been added to the shelf by the patron 2' );
244
    is( $number_of_contents, 4, 'The biblio should have been added to the shelf by the patron 2' );
245
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
245
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->biblionumber ], borrowernumber => $patron2->{borrowernumber} } );
246
    is( $number_of_deleted_biblios, 1, 'Biblio 3 deleted by patron 2' );
246
    is( $number_of_deleted_biblios, 1, 'Biblio 3 deleted by patron 2' );
247
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
247
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
248
    is( $number_of_contents, 3, 'Back to three entries' );
248
    is( $number_of_contents, 3, 'Back to three entries' );
Lines 255-265 subtest 'Shelf permissions' => sub { Link Here
255
    plan tests => 40;
255
    plan tests => 40;
256
    my $patron1 = $builder->build( { source => 'Borrower', value => { flags => '2096766' } } ); # 2096766 is everything checked but not superlibrarian
256
    my $patron1 = $builder->build( { source => 'Borrower', value => { flags => '2096766' } } ); # 2096766 is everything checked but not superlibrarian
257
    my $patron2 = $builder->build( { source => 'Borrower', value => { flags => '1048190' } } ); # 1048190 is everything checked but not superlibrarian and delete_public_lists
257
    my $patron2 = $builder->build( { source => 'Borrower', value => { flags => '1048190' } } ); # 1048190 is everything checked but not superlibrarian and delete_public_lists
258
    my $biblio1 = $builder->build( { source => 'Biblio', } );
258
    my $biblio1 = $builder->build_sample_biblio;
259
    my $biblio2 = $builder->build( { source => 'Biblio', } );
259
    my $biblio2 = $builder->build_sample_biblio;
260
    my $biblio3 = $builder->build( { source => 'Biblio', } );
260
    my $biblio3 = $builder->build_sample_biblio;
261
    my $biblio4 = $builder->build( { source => 'Biblio', } );
261
    my $biblio4 = $builder->build_sample_biblio;
262
263
262
264
    my $public_shelf = Koha::Virtualshelf->new(
263
    my $public_shelf = Koha::Virtualshelf->new(
265
        {   shelfname    => "my first shelf",
264
        {   shelfname    => "my first shelf",
Lines 412-421 subtest 'Get shelves containing biblios' => sub { Link Here
412
    plan tests => 9;
411
    plan tests => 9;
413
    my $patron1 = $builder->build( { source => 'Borrower', } );
412
    my $patron1 = $builder->build( { source => 'Borrower', } );
414
    my $patron2 = $builder->build( { source => 'Borrower', } );
413
    my $patron2 = $builder->build( { source => 'Borrower', } );
415
    my $biblio1 = $builder->build( { source => 'Biblio', } );
414
    my $biblio1 = $builder->build_sample_biblio;
416
    my $biblio2 = $builder->build( { source => 'Biblio', } );
415
    my $biblio2 = $builder->build_sample_biblio;
417
    my $biblio3 = $builder->build( { source => 'Biblio', } );
416
    my $biblio3 = $builder->build_sample_biblio;
418
    my $biblio4 = $builder->build( { source => 'Biblio', } );
417
    my $biblio4 = $builder->build_sample_biblio;
419
418
420
    my $shelf1 = Koha::Virtualshelf->new(
419
    my $shelf1 = Koha::Virtualshelf->new(
421
        {   shelfname    => "my first shelf",
420
        {   shelfname    => "my first shelf",
Lines 436-458 subtest 'Get shelves containing biblios' => sub { Link Here
436
        }
435
        }
437
    )->store;
436
    )->store;
438
437
439
    my $content1 = $shelf1->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
438
    my $content1 = $shelf1->add_biblio( $biblio1->biblionumber, $patron1->{borrowernumber} );
440
    my $content2 = $shelf1->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
439
    my $content2 = $shelf1->add_biblio( $biblio2->biblionumber, $patron1->{borrowernumber} );
441
    my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} );
440
    my $content3 = $shelf2->add_biblio( $biblio2->biblionumber, $patron2->{borrowernumber} );
442
    my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
441
    my $content4 = $shelf2->add_biblio( $biblio3->biblionumber, $patron2->{borrowernumber} );
443
    my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
442
    my $content5 = $shelf2->add_biblio( $biblio4->biblionumber, $patron2->{borrowernumber} );
444
    my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron1->{borrowernumber} );
443
    my $content6 = $shelf3->add_biblio( $biblio4->biblionumber, $patron1->{borrowernumber} );
445
444
446
    my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
445
    my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
447
        {
446
        {
448
            biblionumber => $biblio1->{biblionumber},
447
            biblionumber => $biblio1->biblionumber,
449
        }
448
        }
450
    );
449
    );
451
    is ( $shelves_with_biblio1_for_any_patrons->count, 0, 'shelf1 is private and should not be displayed if patron is not logged in' );
450
    is ( $shelves_with_biblio1_for_any_patrons->count, 0, 'shelf1 is private and should not be displayed if patron is not logged in' );
452
451
453
    my $shelves_with_biblio4_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
452
    my $shelves_with_biblio4_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
454
        {
453
        {
455
            biblionumber => $biblio4->{biblionumber},
454
            biblionumber => $biblio4->biblionumber,
456
        }
455
        }
457
    );
456
    );
458
    is ( $shelves_with_biblio4_for_any_patrons->count, 1, 'shelf3 is public and should be displayed for any patrons' );
457
    is ( $shelves_with_biblio4_for_any_patrons->count, 1, 'shelf3 is public and should be displayed for any patrons' );
Lines 460-466 subtest 'Get shelves containing biblios' => sub { Link Here
460
459
461
    my $shelves_with_biblio1_for_other_patrons = Koha::Virtualshelves->get_shelves_containing_record(
460
    my $shelves_with_biblio1_for_other_patrons = Koha::Virtualshelves->get_shelves_containing_record(
462
        {
461
        {
463
            biblionumber => $biblio1->{biblionumber},
462
            biblionumber => $biblio1->biblionumber,
464
            borrowernumber => $patron2->{borrowernumber},
463
            borrowernumber => $patron2->{borrowernumber},
465
        }
464
        }
466
    );
465
    );
Lines 468-474 subtest 'Get shelves containing biblios' => sub { Link Here
468
467
469
    my $shelves_with_biblio1_for_owner = Koha::Virtualshelves->get_shelves_containing_record(
468
    my $shelves_with_biblio1_for_owner = Koha::Virtualshelves->get_shelves_containing_record(
470
        {
469
        {
471
            biblionumber => $biblio1->{biblionumber},
470
            biblionumber => $biblio1->biblionumber,
472
            borrowernumber => $patron1->{borrowernumber},
471
            borrowernumber => $patron1->{borrowernumber},
473
        }
472
        }
474
    );
473
    );
Lines 476-482 subtest 'Get shelves containing biblios' => sub { Link Here
476
475
477
    my $shelves_with_biblio2_for_patron1 = Koha::Virtualshelves->get_shelves_containing_record(
476
    my $shelves_with_biblio2_for_patron1 = Koha::Virtualshelves->get_shelves_containing_record(
478
        {
477
        {
479
            biblionumber => $biblio2->{biblionumber},
478
            biblionumber => $biblio2->biblionumber,
480
            borrowernumber => $patron1->{borrowernumber},
479
            borrowernumber => $patron1->{borrowernumber},
481
        }
480
        }
482
    );
481
    );
Lines 485-491 subtest 'Get shelves containing biblios' => sub { Link Here
485
484
486
    my $shelves_with_biblio4_for_patron2 = Koha::Virtualshelves->get_shelves_containing_record(
485
    my $shelves_with_biblio4_for_patron2 = Koha::Virtualshelves->get_shelves_containing_record(
487
        {
486
        {
488
            biblionumber => $biblio4->{biblionumber},
487
            biblionumber => $biblio4->biblionumber,
489
            borrowernumber => $patron2->{borrowernumber},
488
            borrowernumber => $patron2->{borrowernumber},
490
        }
489
        }
491
    );
490
    );
(-)a/t/db_dependent/api/v1/items.t (-3 / +3 lines)
Lines 43-49 subtest 'list() tests' => sub { Link Here
43
43
44
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
45
45
46
    my $item   = $builder->build_object( { class => 'Koha::Items' } );
46
    my $item   = $builder->build_sample_item;
47
    my $patron = $builder->build_object(
47
    my $patron = $builder->build_object(
48
        {
48
        {
49
            class => 'Koha::Patrons',
49
            class => 'Koha::Patrons',
Lines 53-59 subtest 'list() tests' => sub { Link Here
53
53
54
    # Make sure we have at least 10 items
54
    # Make sure we have at least 10 items
55
    for ( 1..10 ) {
55
    for ( 1..10 ) {
56
        $builder->build_object({ class => 'Koha::Items' });
56
        $builder->build_sample_item;
57
    }
57
    }
58
58
59
    my $nonprivilegedpatron = $builder->build_object(
59
    my $nonprivilegedpatron = $builder->build_object(
Lines 105-111 subtest 'get() tests' => sub { Link Here
105
105
106
    $schema->storage->txn_begin;
106
    $schema->storage->txn_begin;
107
107
108
    my $item = $builder->build_object( { class => 'Koha::Items' } );
108
    my $item = $builder->build_sample_item;
109
    my $patron = $builder->build_object({
109
    my $patron = $builder->build_object({
110
        class => 'Koha::Patrons',
110
        class => 'Koha::Patrons',
111
        value => { flags => 4 }
111
        value => { flags => 4 }
(-)a/t/db_dependent/cronjobs/advance_notices_digest.t (-21 / +6 lines)
Lines 117-140 DELETESQL Link Here
117
        }
117
        }
118
    });
118
    });
119
119
120
    my $biblio = $builder->build({
120
    my $item1 = $builder->build_sample_item;
121
        source => 'Biblio',
121
    my $item2 = $builder->build_sample_item;
122
    });
122
    my $item3 = $builder->build_sample_item;
123
    my $biblioitem = $builder->build({
124
        source => 'Biblioitem',
125
        value => {
126
            biblionumber => $biblio->{biblionumber}
127
        }
128
    });
129
    my $item1 = $builder->build({
130
        source => 'Item'
131
    });
132
    my $item2 = $builder->build({
133
        source => 'Item'
134
    });
135
    my $item3 = $builder->build({
136
        source => 'Item'
137
    });
138
    my $now = dt_from_string();
123
    my $now = dt_from_string();
139
    my $tomorrow = $now->add(days => 1)->strftime('%F');
124
    my $tomorrow = $now->add(days => 1)->strftime('%F');
140
125
Lines 142-148 DELETESQL Link Here
142
        source => 'Issue',
127
        source => 'Issue',
143
        value => {
128
        value => {
144
            date_due => $tomorrow,
129
            date_due => $tomorrow,
145
            itemnumber => $item1->{itemnumber},
130
            itemnumber => $item1->itemnumber,
146
            branchcode => $library2->{branchcode},
131
            branchcode => $library2->{branchcode},
147
            borrowernumber => $borrower->{borrowernumber},
132
            borrowernumber => $borrower->{borrowernumber},
148
            returndate => undef
133
            returndate => undef
Lines 153-159 DELETESQL Link Here
153
        source => 'Issue',
138
        source => 'Issue',
154
        value => {
139
        value => {
155
            date_due => $tomorrow,
140
            date_due => $tomorrow,
156
            itemnumber => $item2->{itemnumber},
141
            itemnumber => $item2->itemnumber,
157
            branchcode => $library3->{branchcode},
142
            branchcode => $library3->{branchcode},
158
            borrowernumber => $borrower->{borrowernumber},
143
            borrowernumber => $borrower->{borrowernumber},
159
            returndate => undef
144
            returndate => undef
Lines 163-169 DELETESQL Link Here
163
        source => 'Issue',
148
        source => 'Issue',
164
        value => {
149
        value => {
165
            date_due => $tomorrow,
150
            date_due => $tomorrow,
166
            itemnumber => $item3->{itemnumber},
151
            itemnumber => $item3->itemnumber,
167
            branchcode => $library3->{branchcode},
152
            branchcode => $library3->{branchcode},
168
            borrowernumber => $borrower->{borrowernumber},
153
            borrowernumber => $borrower->{borrowernumber},
169
            returndate => undef
154
            returndate => undef
(-)a/t/db_dependent/rollingloans.t (-15 / +9 lines)
Lines 29-55 my $test_item_24 = '502326000404'; Link Here
29
my $test_item_48 = '502326000403';
29
my $test_item_48 = '502326000403';
30
30
31
my $borrower1 = $builder->build_object({ class => 'Koha::Patrons', value => { cardnumber => $test_patron } });
31
my $borrower1 = $builder->build_object({ class => 'Koha::Patrons', value => { cardnumber => $test_patron } });
32
my $item1 = $builder->build_object({
32
my $item1 = $builder->build_sample_item(
33
    class => 'Koha::Items',
33
    {
34
    value => {
35
        barcode => $test_item_fic,
34
        barcode => $test_item_fic,
36
        biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber},
37
    }
35
    }
38
});
36
);
39
my $item2 = $builder->build_object({
37
my $item2 = $builder->build_sample_item(
40
    class => 'Koha::Items',
38
    {
41
    value => {
42
        barcode => $test_item_24,
39
        barcode => $test_item_24,
43
        biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber},
44
    }
40
    }
45
});
41
);
46
my $item3 = $builder->build_object({
42
my $item3 = $builder->build_sample_item(
47
    class => 'Koha::Items',
43
    {
48
    value => {
49
        barcode => $test_item_48,
44
        barcode => $test_item_48,
50
        biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber},
51
    }
45
    }
52
});
46
);
53
47
54
SKIP: {
48
SKIP: {
55
    skip 'Missing test borrower or item, skipping tests', 8
49
    skip 'Missing test borrower or item, skipping tests', 8
(-)a/t/db_dependent/selenium/regressions.t (-11 / +3 lines)
Lines 139-155 subtest 'Display circulation table correctly' => sub { Link Here
139
    );
139
    );
140
140
141
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
141
    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
142
    my $item = $builder->build_object(
142
    my $item = $builder->build_sample_item(
143
        {
143
        {
144
            class => 'Koha::Items',
144
            biblionumber => $biblionumber,
145
            value => {
145
            library      => $library->branchcode,
146
                biblionumber  => $biblionumber,
147
                homebranch    => $library->branchcode,
148
                holdingbranch => $library->branchcode,
149
                notforloan    => 0,
150
                itemlost      => 0,
151
                withdrawn     => 0,
152
            }
153
        }
146
        }
154
    );
147
    );
155
    my $context = Test::MockModule->new('C4::Context');
148
    my $context = Test::MockModule->new('C4::Context');
156
- 

Return to bug 26250