Lines 19-25
use Modern::Perl;
Link Here
|
19 |
|
19 |
|
20 |
use DateTime::Duration; |
20 |
use DateTime::Duration; |
21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
22 |
use Test::More tests => 51; |
22 |
use Test::More tests => 50; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
Lines 38-44
use Koha::Suggestions;
Link Here
|
38 |
BEGIN { |
38 |
BEGIN { |
39 |
use_ok( |
39 |
use_ok( |
40 |
'C4::Suggestions', |
40 |
'C4::Suggestions', |
41 |
qw( ModSuggestion DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions ) |
41 |
qw( ModSuggestion DelSuggestion MarcRecordFromNewSuggestion ) |
42 |
); |
42 |
); |
43 |
} |
43 |
} |
44 |
|
44 |
|
Lines 369-434
is(
Link Here
|
369 |
"Record from suggestion author should be 'Catherine'" |
369 |
"Record from suggestion author should be 'Catherine'" |
370 |
); |
370 |
); |
371 |
|
371 |
|
372 |
subtest 'GetUnprocessedSuggestions' => sub { |
|
|
373 |
plan tests => 11; |
374 |
$dbh->do(q|DELETE FROM suggestions|); |
375 |
my $my_suggestionid = Koha::Suggestion->new($my_suggestion)->store->id; |
376 |
my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
377 |
is( |
378 |
scalar(@$unprocessed_suggestions), 0, |
379 |
'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' |
380 |
); |
381 |
my $status = ModSuggestion($mod_suggestion1); |
382 |
my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
383 |
is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); |
384 |
ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } ); |
385 |
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
386 |
is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); |
387 |
|
388 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
389 |
is( |
390 |
scalar(@$unprocessed_suggestions), 1, |
391 |
'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' |
392 |
); |
393 |
|
394 |
warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ) } |
395 |
'No suggestions REJECTED letter transported by email', |
396 |
'Warning raised if no REJECTED letter by email'; |
397 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
398 |
is( |
399 |
scalar(@$unprocessed_suggestions), 0, |
400 |
'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' |
401 |
); |
402 |
|
403 |
warning_is { |
404 |
ModSuggestion( |
405 |
{ |
406 |
suggestionid => $my_suggestionid, STATUS => 'ASKED', |
407 |
suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) ) |
408 |
} |
409 |
); |
410 |
} |
411 |
'No suggestions ASKED letter transported by email', |
412 |
'Warning raised if no ASKED letter by email'; |
413 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
414 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' ); |
415 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4); |
416 |
is( |
417 |
scalar(@$unprocessed_suggestions), 1, |
418 |
'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' |
419 |
); |
420 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3); |
421 |
is( |
422 |
scalar(@$unprocessed_suggestions), 0, |
423 |
'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' |
424 |
); |
425 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5); |
426 |
is( |
427 |
scalar(@$unprocessed_suggestions), 0, |
428 |
'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' |
429 |
); |
430 |
}; |
431 |
|
432 |
subtest 'EmailPurchaseSuggestions' => sub { |
372 |
subtest 'EmailPurchaseSuggestions' => sub { |
433 |
plan tests => 11; |
373 |
plan tests => 11; |
434 |
|
374 |
|
435 |
- |
|
|