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 => 96; |
22 |
use Test::More tests => 95; |
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( GetSuggestion ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan ) |
41 |
qw( ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan ) |
42 |
); |
42 |
); |
43 |
} |
43 |
} |
44 |
|
44 |
|
Lines 177-184
isnt( $my_suggestionid, 0, 'Suggestion is correctly saved' );
Link Here
|
177 |
my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store; |
177 |
my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store; |
178 |
my $my_suggestionid_with_budget = $my_suggestion_with_budget_object->id; |
178 |
my $my_suggestionid_with_budget = $my_suggestion_with_budget_object->id; |
179 |
|
179 |
|
180 |
is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' ); |
180 |
my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
181 |
my $suggestion = GetSuggestion($my_suggestionid); |
|
|
182 |
is( $suggestion->{title}, $my_suggestion->{title}, 'Suggestion stores the title correctly' ); |
181 |
is( $suggestion->{title}, $my_suggestion->{title}, 'Suggestion stores the title correctly' ); |
183 |
is( $suggestion->{author}, $my_suggestion->{author}, 'Suggestion stores the author correctly' ); |
182 |
is( $suggestion->{author}, $my_suggestion->{author}, 'Suggestion stores the author correctly' ); |
184 |
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' ); |
183 |
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' ); |
Lines 203-209
is( $status, undef, 'ModSuggestion without the suggestion id returns undef' );
Link Here
|
203 |
$mod_suggestion1->{suggestionid} = $my_suggestionid; |
202 |
$mod_suggestion1->{suggestionid} = $my_suggestionid; |
204 |
$status = ModSuggestion($mod_suggestion1); |
203 |
$status = ModSuggestion($mod_suggestion1); |
205 |
is( $status, 1, 'ModSuggestion modifies one entry' ); |
204 |
is( $status, 1, 'ModSuggestion modifies one entry' ); |
206 |
$suggestion = GetSuggestion($my_suggestionid); |
205 |
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
207 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); |
206 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); |
208 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); |
207 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); |
209 |
is( |
208 |
is( |
Lines 247-253
my $mod_suggestion3 = {
Link Here
|
247 |
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 ); |
246 |
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 ); |
248 |
$status = ModSuggestion($mod_suggestion3); |
247 |
$status = ModSuggestion($mod_suggestion3); |
249 |
is( $status, 1, 'ModSuggestion modifies one entry' ); |
248 |
is( $status, 1, 'ModSuggestion modifies one entry' ); |
250 |
$suggestion = GetSuggestion($my_suggestionid); |
249 |
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
251 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); |
250 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); |
252 |
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } ); |
251 |
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } ); |
253 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
252 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
Lines 438-444
is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arg
Link Here
|
438 |
my $biblio_2 = $builder->build_object( { class => 'Koha::Biblios' } ); |
437 |
my $biblio_2 = $builder->build_object( { class => 'Koha::Biblios' } ); |
439 |
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber ); |
438 |
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber ); |
440 |
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' ); |
439 |
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' ); |
441 |
$suggestion = GetSuggestion($my_suggestionid); |
440 |
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
442 |
is( |
441 |
is( |
443 |
$suggestion->{biblionumber}, $biblio_2->biblionumber, |
442 |
$suggestion->{biblionumber}, $biblio_2->biblionumber, |
444 |
'ConnectSuggestionAndBiblio updates the biblio number correctly' |
443 |
'ConnectSuggestionAndBiblio updates the biblio number correctly' |
Lines 469-480
is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes
Link Here
|
469 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
468 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
470 |
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store; |
469 |
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store; |
471 |
my $my_suggestionid_test_budgetid = $my_suggestionid_test_budget_object->id; |
470 |
my $my_suggestionid_test_budgetid = $my_suggestionid_test_budget_object->id; |
472 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
471 |
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed(); |
473 |
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); |
472 |
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); |
474 |
|
473 |
|
475 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
474 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
476 |
ModSuggestion($my_suggestion); |
475 |
ModSuggestion($my_suggestion); |
477 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
476 |
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed(); |
478 |
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); |
477 |
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); |
479 |
|
478 |
|
480 |
my $suggestion2 = { |
479 |
my $suggestion2 = { |
Lines 511-520
subtest 'GetUnprocessedSuggestions' => sub {
Link Here
|
511 |
'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' |
510 |
'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' |
512 |
); |
511 |
); |
513 |
my $status = ModSuggestion($mod_suggestion1); |
512 |
my $status = ModSuggestion($mod_suggestion1); |
514 |
my $suggestion = GetSuggestion($my_suggestionid); |
513 |
my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
515 |
is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); |
514 |
is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); |
516 |
ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } ); |
515 |
ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } ); |
517 |
$suggestion = GetSuggestion($my_suggestionid); |
516 |
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
518 |
is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); |
517 |
is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); |
519 |
|
518 |
|
520 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
519 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
Lines 734-740
subtest 'ModSuggestion should work on suggestions without a suggester' => sub {
Link Here
|
734 |
|
733 |
|
735 |
$dbh->do(q|DELETE FROM suggestions|); |
734 |
$dbh->do(q|DELETE FROM suggestions|); |
736 |
my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id; |
735 |
my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id; |
737 |
$suggestion = GetSuggestion($my_suggestionid); |
736 |
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
738 |
is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" ); |
737 |
is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" ); |
739 |
|
738 |
|
740 |
ModSuggestion( |
739 |
ModSuggestion( |
Lines 744-750
subtest 'ModSuggestion should work on suggestions without a suggester' => sub {
Link Here
|
744 |
note => "Test note" |
743 |
note => "Test note" |
745 |
} |
744 |
} |
746 |
); |
745 |
); |
747 |
$suggestion = GetSuggestion($my_suggestionid); |
746 |
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed(); |
748 |
|
747 |
|
749 |
is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" ); |
748 |
is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" ); |
750 |
}; |
749 |
}; |
751 |
- |
|
|