|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2024 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More tests => 1; |
| 23 |
|
| 24 |
use Koha::Bookings; |
| 25 |
use Koha::Database; |
| 26 |
use Koha::DateUtils qw( dt_from_string ); |
| 27 |
|
| 28 |
use t::lib::TestBuilder; |
| 29 |
|
| 30 |
my $schema = Koha::Database->new->schema; |
| 31 |
|
| 32 |
my $builder = t::lib::TestBuilder->new; |
| 33 |
|
| 34 |
subtest 'filter_by_future' => sub { |
| 35 |
|
| 36 |
plan tests => 1; |
| 37 |
|
| 38 |
$schema->storage->txn_begin; |
| 39 |
|
| 40 |
my $biblio = $builder->build_sample_biblio; |
| 41 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
| 42 |
my $end_0 = dt_from_string->add( days => 4 )->truncate( to => 'day' ); |
| 43 |
$builder->build_object( |
| 44 |
{ |
| 45 |
class => 'Koha::Bookings', |
| 46 |
value => { |
| 47 |
biblio_id => $biblio->biblionumber, |
| 48 |
start_date => dt_from_string->subtract( days => 1 )->truncate( to => 'day' ), |
| 49 |
end_date => undef |
| 50 |
} |
| 51 |
} |
| 52 |
); |
| 53 |
|
| 54 |
$builder->build_object( |
| 55 |
{ |
| 56 |
class => 'Koha::Bookings', |
| 57 |
value => { |
| 58 |
biblio_id => $biblio->biblionumber, |
| 59 |
start_date => dt_from_string->add( days => 1 )->truncate( to => 'day' ), |
| 60 |
end_date => undef |
| 61 |
} |
| 62 |
} |
| 63 |
); |
| 64 |
|
| 65 |
$builder->build_object( |
| 66 |
{ |
| 67 |
class => 'Koha::Bookings', |
| 68 |
value => { |
| 69 |
biblio_id => $biblio->biblionumber, |
| 70 |
start_date => dt_from_string->add( days => 2 )->truncate( to => 'day' ), |
| 71 |
end_date => undef |
| 72 |
} |
| 73 |
} |
| 74 |
); |
| 75 |
|
| 76 |
is( $biblio->bookings->filter_by_future->count, 2, 'There should have 2 bookings starting after now' ); |
| 77 |
|
| 78 |
$schema->storage->txn_rollback; |
| 79 |
}; |