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

(-)a/t/db_dependent/Koha/Recalls.t (-10 / +49 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 20;
20
use Test::More tests => 23;
21
use t::lib::Dates;
21
use t::lib::Dates;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 45-50 my $biblio1 = $item1->biblio; Link Here
45
my $branch1 = $item1->holdingbranch;
45
my $branch1 = $item1->holdingbranch;
46
my $itemtype1 = $item1->effective_itemtype;
46
my $itemtype1 = $item1->effective_itemtype;
47
my $item2 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
47
my $item2 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
48
my $item3 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
48
my $biblio2 = $item1->biblio;
49
my $biblio2 = $item1->biblio;
49
my $branch2 = $item1->holdingbranch;
50
my $branch2 = $item1->holdingbranch;
50
my $itemtype2 = $item1->effective_itemtype;
51
my $itemtype2 = $item1->effective_itemtype;
Lines 53-72 my $category1 = $builder->build({ source => 'Category' })->{ categorycode }; Link Here
53
my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category1, branchcode => $branch1 } });
54
my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category1, branchcode => $branch1 } });
54
my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category1, branchcode => $branch2 } });
55
my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category1, branchcode => $branch2 } });
55
my $patron3 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category1, branchcode => $branch1 } });
56
my $patron3 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category1, branchcode => $branch1 } });
57
my $patron4 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category1, branchcode => $branch2 } });
56
t::lib::Mocks::mock_userenv({ patron => $patron1 });
58
t::lib::Mocks::mock_userenv({ patron => $patron1 });
57
59
58
Koha::CirculationRules->set_rules({
60
Koha::CirculationRules->set_rules(
59
    branchcode => undef,
61
    {
60
    categorycode => undef,
62
        branchcode   => undef,
61
    itemtype => undef,
63
        categorycode => undef,
62
    rules => {
64
        itemtype     => undef,
63
        'recall_due_date_interval' => undef,
65
        rules        => {
64
        'recalls_allowed' => 10,
66
            'issuelength'              => 7,
67
            'recall_due_date_interval' => undef,
68
            'recalls_allowed'          => 10,
69
        }
65
    }
70
    }
66
});
71
);
67
72
68
C4::Circulation::AddIssue( $patron3, $item1->barcode );
73
C4::Circulation::AddIssue( $patron3, $item1->barcode );
69
C4::Circulation::AddIssue( $patron3, $item2->barcode );
74
C4::Circulation::AddIssue( $patron3, $item2->barcode );
75
C4::Circulation::AddIssue( $patron4, $item3->barcode );
70
76
71
my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
77
my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
72
    patron => undef,
78
    patron => undef,
Lines 98-103 ok( !defined $recall, "Can't add a recall without specifying a biblio" ); Link Here
98
});
104
});
99
ok( !defined $recall, "Can't add a recall without specifying a biblio" );
105
ok( !defined $recall, "Can't add a recall without specifying a biblio" );
100
106
107
my $initial_checkout_due_date = Koha::Checkouts->find( $item2->checkout->issue_id )->date_due;
101
( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
108
( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
102
    patron => $patron2,
109
    patron => $patron2,
103
    biblio => $biblio1,
110
    biblio => $biblio1,
Lines 106-113 ok( !defined $recall, "Can't add a recall without specifying a biblio" ); Link Here
106
    expirationdate => undef,
113
    expirationdate => undef,
107
    interface => 'COMMANDLINE',
114
    interface => 'COMMANDLINE',
108
});
115
});
116
my $checkout_due_date_after_recall = Koha::Checkouts->find( $item2->checkout->issue_id )->date_due;
109
is( $recall->pickup_library_id, $branch2, "No pickup branch specified so patron branch used" );
117
is( $recall->pickup_library_id, $branch2, "No pickup branch specified so patron branch used" );
110
is( $due_interval, 5, "Recall due date interval defaults to 5 if not specified" );
118
is( $due_interval, 5, "Recall due date interval defaults to 5 if not specified" );
119
ok(
120
    $checkout_due_date_after_recall lt $initial_checkout_due_date,
121
    "Checkout due date has been moved backwards"
122
);
111
123
112
Koha::CirculationRules->set_rule({
124
Koha::CirculationRules->set_rule({
113
    branchcode => undef,
125
    branchcode => undef,
Lines 146-151 is( Link Here
146
);
158
);
147
is( t::lib::Dates::compare( $due_date, $expected_due_date ), 0, "Due date correctly returned" );
159
is( t::lib::Dates::compare( $due_date, $expected_due_date ), 0, "Due date correctly returned" );
148
160
161
Koha::CirculationRules->set_rule(
162
    {
163
        branchcode   => undef,
164
        categorycode => undef,
165
        itemtype     => undef,
166
        rule_name    => 'recall_due_date_interval',
167
        rule_value   => 10,
168
    }
169
);
170
$initial_checkout_due_date = Koha::Checkouts->find( $item3->checkout->issue_id )->date_due;
171
my $recall2;
172
( $recall2, $due_interval, $due_date ) = Koha::Recalls->add_recall(
173
    {
174
        patron         => $patron2,
175
        biblio         => $biblio1,
176
        branchcode     => $branch1,
177
        item           => $item3,
178
        expirationdate => undef,
179
        interface      => 'COMMANDLINE',
180
    }
181
);
182
$checkout_due_date_after_recall = Koha::Checkouts->find( $item3->checkout->issue_id )->date_due;
183
is( $due_interval, 10, "Recall due date interval increased above checkout due" );
184
ok(
185
    $checkout_due_date_after_recall eq $initial_checkout_due_date,
186
    "Checkout due date has not been moved forward"
187
);
188
149
my $messages_count = Koha::Notice::Messages->search({ borrowernumber => $patron3->borrowernumber, letter_code => 'RETURN_RECALLED_ITEM' })->count;
189
my $messages_count = Koha::Notice::Messages->search({ borrowernumber => $patron3->borrowernumber, letter_code => 'RETURN_RECALLED_ITEM' })->count;
150
is( $messages_count, 3, "RETURN_RECALLED_ITEM notice successfully sent to checkout borrower" );
190
is( $messages_count, 3, "RETURN_RECALLED_ITEM notice successfully sent to checkout borrower" );
151
191
152
- 

Return to bug 32696