Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 9; |
23 |
|
23 |
|
24 |
use C4::Circulation; |
24 |
use C4::Circulation; |
25 |
use Koha::Checkouts; |
25 |
use Koha::Checkouts; |
Lines 27-32
use Koha::Database;
Link Here
|
27 |
use Koha::DateUtils qw( dt_from_string ); |
27 |
use Koha::DateUtils qw( dt_from_string ); |
28 |
|
28 |
|
29 |
use t::lib::TestBuilder; |
29 |
use t::lib::TestBuilder; |
|
|
30 |
use t::lib::Mocks; |
30 |
|
31 |
|
31 |
my $schema = Koha::Database->new->schema; |
32 |
my $schema = Koha::Database->new->schema; |
32 |
$schema->storage->txn_begin; |
33 |
$schema->storage->txn_begin; |
Lines 155-159
subtest 'issuer' => sub {
Link Here
|
155 |
|
156 |
|
156 |
}; |
157 |
}; |
157 |
|
158 |
|
|
|
159 |
subtest 'Koha::Old::Checkouts->filter_by_todays_checkins' => sub { |
160 |
|
161 |
plan tests => 3; |
162 |
|
163 |
# We will create 7 checkins for a given patron |
164 |
# 3 checked in today - 2 days, and 4 checked in today |
165 |
my $librarian = $builder->build_object( |
166 |
{ |
167 |
class => 'Koha::Patrons', |
168 |
value => { branchcode => $library->{branchcode} } |
169 |
} |
170 |
); |
171 |
t::lib::Mocks::mock_userenv( { patron => $librarian } ); |
172 |
my $patron = $builder->build_object( |
173 |
{ |
174 |
class => 'Koha::Patrons', |
175 |
value => { branchcode => $library->{branchcode} } |
176 |
} |
177 |
); |
178 |
|
179 |
my @checkouts; |
180 |
# Create 7 checkouts |
181 |
for ( 0 .. 6 ) { |
182 |
my $item = $builder->build_sample_item; |
183 |
push @checkouts, |
184 |
Koha::Checkout->new( |
185 |
{ |
186 |
borrowernumber => $patron->borrowernumber, |
187 |
itemnumber => $item->itemnumber, |
188 |
branchcode => $library->{branchcode}, |
189 |
} |
190 |
)->store; |
191 |
} |
192 |
|
193 |
# Checkin 3 today - 2 days |
194 |
my $not_today = dt_from_string->add( days => -2 ); |
195 |
for my $i ( 0 .. 2 ) { |
196 |
my $checkout = $checkouts[$i]; |
197 |
C4::Circulation::AddReturn( |
198 |
$checkout->item->barcode, $library->{branchcode}, |
199 |
undef, $not_today->set_hour( int( rand(24) ) ) |
200 |
); |
201 |
} |
202 |
# Checkin 4 today |
203 |
my $today = dt_from_string; |
204 |
for my $i ( 3 .. 6 ) { |
205 |
my $checkout = $checkouts[$i]; |
206 |
C4::Circulation::AddReturn( |
207 |
$checkout->item->barcode, $library->{branchcode}, |
208 |
undef, $today->set_hour( int( rand(24) ) ) |
209 |
); |
210 |
} |
211 |
|
212 |
my $old_checkouts = $patron->old_checkouts; |
213 |
is( $old_checkouts->count, 7, 'There should be 7 old checkouts' ); |
214 |
my $todays_checkins = $old_checkouts->filter_by_todays_checkins; |
215 |
is( $todays_checkins->count, 4, 'There should be 4 checkins today' ); |
216 |
is_deeply( |
217 |
[ $todays_checkins->get_column('itemnumber') ], |
218 |
[ map { $_->itemnumber } @checkouts[ 3 .. 6 ] ], |
219 |
q{Correct list of today's checkins} |
220 |
); |
221 |
}; |
222 |
|
158 |
$schema->storage->txn_rollback; |
223 |
$schema->storage->txn_rollback; |
159 |
|
224 |
|
160 |
- |
|
|