|
Lines 19-28
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 9; |
22 |
use Test::More tests => 11; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
|
24 |
|
| 25 |
use Koha::Suggestion; |
|
|
| 26 |
use Koha::Suggestions; |
25 |
use Koha::Suggestions; |
| 27 |
use Koha::Database; |
26 |
use Koha::Database; |
| 28 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
27 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
|
Lines 329-331
subtest 'search_limited() tests' => sub {
Link Here
|
| 329 |
|
328 |
|
| 330 |
$schema->storage->txn_rollback; |
329 |
$schema->storage->txn_rollback; |
| 331 |
}; |
330 |
}; |
| 332 |
- |
331 |
|
|
|
332 |
subtest 'filter_by_pending() tests' => sub { |
| 333 |
|
| 334 |
plan tests => 3; |
| 335 |
|
| 336 |
$schema->storage->txn_begin; |
| 337 |
|
| 338 |
my $suggestion_1 = $builder->build_object( { class => 'Koha::Suggestions', value => { STATUS => 'ASKED' } } ); |
| 339 |
my $suggestion_2 = $builder->build_object( { class => 'Koha::Suggestions', value => { STATUS => 'ACCEPTED' } } ); |
| 340 |
my $suggestion_3 = $builder->build_object( { class => 'Koha::Suggestions', value => { STATUS => 'ASKED' } } ); |
| 341 |
|
| 342 |
my $suggestions = |
| 343 |
Koha::Suggestions->search( { suggestionid => [ $suggestion_1->id, $suggestion_2->id, $suggestion_3->id ] }, |
| 344 |
{ order_by => ['suggestionid'] } ); |
| 345 |
|
| 346 |
is( $suggestions->count, 3 ); |
| 347 |
|
| 348 |
my $pending = $suggestions->filter_by_pending; |
| 349 |
my @pending_ids = $pending->get_column('suggestionid'); |
| 350 |
|
| 351 |
is( $pending->count, 2 ); |
| 352 |
is_deeply( \@pending_ids, [ $suggestion_1->id, $suggestion_3->id ] ); |
| 353 |
|
| 354 |
$schema->storage->txn_rollback; |
| 355 |
}; |
| 356 |
|
| 357 |
subtest 'filter_by_suggested_days_range() tests' => sub { |
| 358 |
|
| 359 |
plan tests => 4; |
| 360 |
|
| 361 |
$schema->storage->txn_begin; |
| 362 |
|
| 363 |
my $today = dt_from_string; |
| 364 |
my $today_minus_two = dt_from_string->subtract( days => 2 ); |
| 365 |
my $today_minus_three = dt_from_string->subtract( days => 3 ); |
| 366 |
|
| 367 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 368 |
|
| 369 |
my $suggestion_1 = $builder->build_object( |
| 370 |
{ class => 'Koha::Suggestions', value => { suggesteddate => $dtf->format_date($today) } } ); |
| 371 |
my $suggestion_2 = $builder->build_object( |
| 372 |
{ class => 'Koha::Suggestions', value => { suggesteddate => $dtf->format_date($today_minus_two) } } ); |
| 373 |
my $suggestion_3 = $builder->build_object( |
| 374 |
{ class => 'Koha::Suggestions', value => { suggesteddate => $dtf->format_date($today_minus_three) } } ); |
| 375 |
|
| 376 |
my $suggestions = |
| 377 |
Koha::Suggestions->search( { suggestionid => [ $suggestion_1->id, $suggestion_2->id, $suggestion_3->id ] }, |
| 378 |
{ order_by => ['suggestionid'] } ); |
| 379 |
|
| 380 |
is( $suggestions->count, 3 ); |
| 381 |
|
| 382 |
my $three_days = $suggestions->filter_by_suggested_days_range(3); |
| 383 |
is( $three_days->count, 3 ); |
| 384 |
|
| 385 |
my $two_days = $suggestions->filter_by_suggested_days_range(2); |
| 386 |
is( $two_days->count, 2 ); |
| 387 |
|
| 388 |
my $one_days = $suggestions->filter_by_suggested_days_range(1); |
| 389 |
is( $one_days->count, 1 ); |
| 390 |
|
| 391 |
$schema->storage->txn_rollback; |
| 392 |
}; |