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 82-89
is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL i
Link Here
|
82 |
|
100 |
|
83 |
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
101 |
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
84 |
|
102 |
|
|
|
103 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
104 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' ); |
105 |
|
85 |
|
106 |
|
86 |
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); |
107 |
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); |
|
|
108 |
|
87 |
my $mod_suggestion1 = { |
109 |
my $mod_suggestion1 = { |
88 |
title => 'my modified title', |
110 |
title => 'my modified title', |
89 |
author => 'my modified author', |
111 |
author => 'my modified author', |
Lines 99-104
$suggestion = GetSuggestion($my_suggestionid);
Link Here
|
99 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); |
121 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); |
100 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); |
122 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); |
101 |
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' ); |
123 |
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' ); |
|
|
124 |
is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); |
125 |
|
126 |
ModSuggestion({ suggestionid => $my_suggestionid, budgetid => $budget_id }); |
127 |
$suggestion = GetSuggestion($my_suggestionid); |
128 |
is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); |
129 |
|
130 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
131 |
is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); |
132 |
|
133 |
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ); |
134 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
135 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); |
136 |
|
137 |
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration(DateTime::Duration->new(days => -4) ) } ); |
138 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
139 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' ); |
140 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4); |
141 |
is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' ); |
142 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3); |
143 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' ); |
144 |
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5); |
145 |
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' ); |
146 |
|
102 |
my $messages = C4::Letters::GetQueuedMessages({ |
147 |
my $messages = C4::Letters::GetQueuedMessages({ |
103 |
borrowernumber => $borrowernumber, |
148 |
borrowernumber => $borrowernumber, |
104 |
}); |
149 |
}); |
Lines 107-112
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not u
Link Here
|
107 |
my $mod_suggestion2 = { |
152 |
my $mod_suggestion2 = { |
108 |
STATUS => 'STALLED', |
153 |
STATUS => 'STALLED', |
109 |
suggestionid => $my_suggestionid, |
154 |
suggestionid => $my_suggestionid, |
|
|
155 |
|
110 |
}; |
156 |
}; |
111 |
warning_is { $status = ModSuggestion($mod_suggestion2) } |
157 |
warning_is { $status = ModSuggestion($mod_suggestion2) } |
112 |
"No suggestions STALLED letter transported by email", |
158 |
"No suggestions STALLED letter transported by email", |
Lines 129-135
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
Link Here
|
129 |
|
175 |
|
130 |
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
176 |
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
131 |
|
177 |
|
132 |
|
|
|
133 |
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); |
178 |
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); |
134 |
$suggestion = GetSuggestionInfo($my_suggestionid); |
179 |
$suggestion = GetSuggestionInfo($my_suggestionid); |
135 |
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' ); |
180 |
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' ); |
136 |
- |
|
|