Lines 18-27
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use C4::Context; |
20 |
use C4::Context; |
|
|
21 |
use C4::Budgets qw( AddBudgetPeriod AddBudget ); |
21 |
use C4::Members; |
22 |
use C4::Members; |
22 |
use C4::Letters; |
23 |
use C4::Letters; |
23 |
|
24 |
|
24 |
use Test::More tests => 91; |
25 |
use Koha::DateUtils qw( dt_from_string ); |
|
|
26 |
|
27 |
use DateTime::Duration; |
28 |
use Test::More tests => 101; |
25 |
use Test::Warn; |
29 |
use Test::Warn; |
26 |
|
30 |
|
27 |
BEGIN { |
31 |
BEGIN { |
Lines 59-64
my $my_suggestion = {
Link Here
|
59 |
biblionumber => $biblionumber1, |
63 |
biblionumber => $biblionumber1, |
60 |
}; |
64 |
}; |
61 |
|
65 |
|
|
|
66 |
# Create a fund for the budgetid value |
67 |
my $bpid = C4::Budgets::AddBudgetPeriod({ |
68 |
budget_period_startdate => '2008-01-01', |
69 |
}); |
70 |
my $my_budget = { |
71 |
budget_code => 'ABCD', |
72 |
budget_amount => '123.132000', |
73 |
budget_name => 'Periodiques', |
74 |
budget_notes => 'This is a note', |
75 |
budget_period_id => $bpid, |
76 |
}; |
77 |
my $budget_id = C4::Budgets::AddBudget($my_budget); |
78 |
|
79 |
my $unprocessed_suggestions; |
62 |
|
80 |
|
63 |
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' ); |
81 |
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' ); |
64 |
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
82 |
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
Lines 81-88
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the
Link Here
|
81 |
|
99 |
|
82 |
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
100 |
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
83 |
|
101 |
|
|
|
102 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
103 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' ); |
104 |
|
84 |
|
105 |
|
85 |
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); |
106 |
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); |
|
|
107 |
|
86 |
my $mod_suggestion1 = { |
108 |
my $mod_suggestion1 = { |
87 |
title => 'my modified title', |
109 |
title => 'my modified title', |
88 |
author => 'my modified author', |
110 |
author => 'my modified author', |
Lines 98-103
$suggestion = GetSuggestion($my_suggestionid);
Link Here
|
98 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); |
120 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); |
99 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); |
121 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); |
100 |
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' ); |
122 |
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' ); |
|
|
123 |
is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); |
124 |
|
125 |
ModSuggestion({ suggestionid => $my_suggestionid, budgetid => $budget_id }); |
126 |
$suggestion = GetSuggestion($my_suggestionid); |
127 |
is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); |
128 |
|
129 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
130 |
is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); |
131 |
|
132 |
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ); |
133 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
134 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); |
135 |
|
136 |
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration(DateTime::Duration->new(days => -4) ) } ); |
137 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
138 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' ); |
139 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4); |
140 |
is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' ); |
141 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3); |
142 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' ); |
143 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5); |
144 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' ); |
145 |
|
101 |
my $messages = C4::Letters::GetQueuedMessages({ |
146 |
my $messages = C4::Letters::GetQueuedMessages({ |
102 |
borrowernumber => $borrowernumber, |
147 |
borrowernumber => $borrowernumber, |
103 |
}); |
148 |
}); |
Lines 106-111
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not u
Link Here
|
106 |
my $mod_suggestion2 = { |
151 |
my $mod_suggestion2 = { |
107 |
STATUS => 'STALLED', |
152 |
STATUS => 'STALLED', |
108 |
suggestionid => $my_suggestionid, |
153 |
suggestionid => $my_suggestionid, |
|
|
154 |
|
109 |
}; |
155 |
}; |
110 |
warning_is { $status = ModSuggestion($mod_suggestion2) } |
156 |
warning_is { $status = ModSuggestion($mod_suggestion2) } |
111 |
"No suggestions STALLED letter transported by email", |
157 |
"No suggestions STALLED letter transported by email", |
Lines 128-134
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
Link Here
|
128 |
|
174 |
|
129 |
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
175 |
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
130 |
|
176 |
|
131 |
|
|
|
132 |
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); |
177 |
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); |
133 |
$suggestion = GetSuggestionInfo($my_suggestionid); |
178 |
$suggestion = GetSuggestionInfo($my_suggestionid); |
134 |
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' ); |
179 |
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' ); |
135 |
- |
|
|