|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
| 23 |
|
23 |
|
| 24 |
use Koha::Bookings; |
24 |
use Koha::Bookings; |
| 25 |
use Koha::Database; |
25 |
use Koha::Database; |
|
Lines 37-45
subtest 'filter_by_future' => sub {
Link Here
|
| 37 |
|
37 |
|
| 38 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
| 39 |
|
39 |
|
| 40 |
my $biblio = $builder->build_sample_biblio; |
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( |
41 |
$builder->build_object( |
| 44 |
{ |
42 |
{ |
| 45 |
class => 'Koha::Bookings', |
43 |
class => 'Koha::Bookings', |
|
Lines 90-92
subtest 'filter_by_future' => sub {
Link Here
|
| 90 |
|
88 |
|
| 91 |
$schema->storage->txn_rollback; |
89 |
$schema->storage->txn_rollback; |
| 92 |
}; |
90 |
}; |
| 93 |
- |
91 |
|
|
|
92 |
subtest 'filter_by_active' => sub { |
| 93 |
|
| 94 |
plan tests => 5; |
| 95 |
|
| 96 |
$schema->storage->txn_begin; |
| 97 |
|
| 98 |
my $biblio = $builder->build_sample_biblio; |
| 99 |
my $start_ago = dt_from_string->subtract( hours => 1 ); |
| 100 |
my $start_hour = dt_from_string->add( hours => 1 ); |
| 101 |
my $start_day = dt_from_string->add( days => 1 ); |
| 102 |
my $end_ago = dt_from_string->subtract( minutes => 1 ); |
| 103 |
my $end_hour = dt_from_string->add( hours => 1 ); |
| 104 |
my $end_day = dt_from_string->add( days => 1 ); |
| 105 |
$builder->build_object( |
| 106 |
{ |
| 107 |
class => 'Koha::Bookings', |
| 108 |
value => { |
| 109 |
biblio_id => $biblio->biblionumber, |
| 110 |
start_date => $start_ago, |
| 111 |
end_date => $end_hour |
| 112 |
} |
| 113 |
} |
| 114 |
); |
| 115 |
is( $biblio->bookings->filter_by_active->count, 1, 'Booking started in past, ending in future is counted' ); |
| 116 |
|
| 117 |
$builder->build_object( |
| 118 |
{ |
| 119 |
class => 'Koha::Bookings', |
| 120 |
value => { |
| 121 |
biblio_id => $biblio->biblionumber, |
| 122 |
start_date => $start_ago, |
| 123 |
end_date => $end_ago |
| 124 |
} |
| 125 |
} |
| 126 |
); |
| 127 |
is( $biblio->bookings->filter_by_active->count, 1, 'Booking started in past, ended now is not counted' ); |
| 128 |
|
| 129 |
$builder->build_object( |
| 130 |
{ |
| 131 |
class => 'Koha::Bookings', |
| 132 |
value => { |
| 133 |
biblio_id => $biblio->biblionumber, |
| 134 |
start_date => $start_hour, |
| 135 |
end_date => $end_hour |
| 136 |
} |
| 137 |
} |
| 138 |
); |
| 139 |
is( $biblio->bookings->filter_by_active->count, 2, 'Booking starting soon, ending soon is still counted' ); |
| 140 |
|
| 141 |
$builder->build_object( |
| 142 |
{ |
| 143 |
class => 'Koha::Bookings', |
| 144 |
value => { |
| 145 |
biblio_id => $biblio->biblionumber, |
| 146 |
start_date => $start_day, |
| 147 |
end_date => $end_day |
| 148 |
} |
| 149 |
} |
| 150 |
); |
| 151 |
is( $biblio->bookings->filter_by_active->count, 3, 'Booking starting tomorrow, ending tomorrow is counted' ); |
| 152 |
|
| 153 |
$builder->build_object( |
| 154 |
{ |
| 155 |
class => 'Koha::Bookings', |
| 156 |
value => { |
| 157 |
biblio_id => $biblio->biblionumber, |
| 158 |
start_date => $start_day, |
| 159 |
end_date => $end_ago |
| 160 |
} |
| 161 |
} |
| 162 |
); |
| 163 |
is( |
| 164 |
$biblio->bookings->filter_by_active->count, 3, |
| 165 |
'EDGE CASE: Booking starting in future, already ended is not counted - should be impossible, but good check' |
| 166 |
); |
| 167 |
|
| 168 |
$schema->storage->txn_rollback; |
| 169 |
}; |