Lines 21-31
use C4::Context;
Link Here
|
21 |
use C4::Members; |
21 |
use C4::Members; |
22 |
use C4::Letters; |
22 |
use C4::Letters; |
23 |
use C4::Branch; |
23 |
use C4::Branch; |
24 |
use C4::Budgets; |
24 |
use C4::Budgets qw( AddBudgetPeriod AddBudget ); |
25 |
|
25 |
|
26 |
use Koha::DateUtils qw( dt_from_string ); |
26 |
use Koha::DateUtils qw( dt_from_string ); |
27 |
|
27 |
|
28 |
use Test::More tests => 104; |
28 |
use DateTime::Duration; |
|
|
29 |
use Test::More tests => 105; |
29 |
use Test::Warn; |
30 |
use Test::Warn; |
30 |
|
31 |
|
31 |
BEGIN { |
32 |
BEGIN { |
Lines 362-364
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
Link Here
|
362 |
ModSuggestion( $my_suggestion ); |
363 |
ModSuggestion( $my_suggestion ); |
363 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
364 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
364 |
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' ); |
365 |
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' ); |
365 |
- |
366 |
|
|
|
367 |
subtest 'GetUnprocessedSuggestions' => sub { |
368 |
plan tests => 9; |
369 |
$dbh->do(q|DELETE FROM suggestions|); |
370 |
my $my_suggestionid = NewSuggestion($my_suggestion); |
371 |
my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
372 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' ); |
373 |
my $status = ModSuggestion($mod_suggestion1); |
374 |
my $suggestion = GetSuggestion($my_suggestionid); |
375 |
is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); |
376 |
ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } ); |
377 |
$suggestion = GetSuggestion($my_suggestionid); |
378 |
is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); |
379 |
|
380 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
381 |
is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); |
382 |
|
383 |
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ); |
384 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
385 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); |
386 |
|
387 |
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) ) } ); |
388 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
389 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' ); |
390 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4); |
391 |
is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' ); |
392 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3); |
393 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' ); |
394 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5); |
395 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' ); |
396 |
}; |