Bug 20287: Replace occurrences of AddMember with Koha::Patron->new->store->borrowernumber
[koha.git] / t / db_dependent / Suggestions.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use DateTime::Duration;
21 use Test::More tests => 103;
22 use Test::Warn;
23
24 use t::lib::Mocks;
25 use t::lib::TestBuilder;
26
27 use C4::Context;
28 use C4::Letters;
29 use C4::Budgets qw( AddBudgetPeriod AddBudget );
30 use Koha::Database;
31 use Koha::DateUtils qw( dt_from_string output_pref );
32 use Koha::Libraries;
33 use Koha::Patrons;
34 use Koha::Suggestions;
35
36 BEGIN {
37     use_ok('C4::Suggestions');
38 }
39
40 my $schema  = Koha::Database->new->schema;
41 $schema->storage->txn_begin;
42 my $dbh = C4::Context->dbh;
43 my $builder = t::lib::TestBuilder->new;
44
45 # Reset item types to only the default ones
46 $dbh->do(q|DELETE FROM itemtypes;|);
47 my $sql = qq|
48 INSERT INTO itemtypes (itemtype, description, rentalcharge, notforloan, imageurl, summary) VALUES
49 ('BK', 'Books',5,0,'bridge/book.gif',''),
50 ('MX', 'Mixed Materials',5,0,'bridge/kit.gif',''),
51 ('CF', 'Computer Files',5,0,'bridge/computer_file.gif',''),
52 ('MP', 'Maps',5,0,'bridge/map.gif',''),
53 ('VM', 'Visual Materials',5,1,'bridge/dvd.gif',''),
54 ('MU', 'Music',5,0,'bridge/sound.gif',''),
55 ('CR', 'Continuing Resources',5,0,'bridge/periodical.gif',''),
56 ('REF', 'Reference',0,1,'bridge/reference.gif','');|;
57 $dbh->do($sql);
58 $dbh->do(q|DELETE FROM suggestions|);
59 $dbh->do(q|DELETE FROM issues|);
60 $dbh->do(q|DELETE FROM borrowers|);
61 $dbh->do(q|DELETE FROM letter|);
62 $dbh->do(q|DELETE FROM message_queue|);
63 $dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|);
64
65 # Add CPL if missing.
66 if (not defined Koha::Libraries->find('CPL')) {
67     Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
68 }
69
70 my $patron_category = $builder->build({ source => 'Category' });
71
72 my $member = {
73     firstname => 'my firstname',
74     surname => 'my surname',
75     categorycode => $patron_category->{categorycode},
76     branchcode => 'CPL',
77 };
78 my $borrowernumber = Koha::Patron->new($member)->store->borrowernumber;
79
80 my $biblionumber1 = 1;
81 my $my_suggestion = {
82     title         => 'my title',
83     author        => 'my author',
84     publishercode => 'my publishercode',
85     suggestedby   => $borrowernumber,
86     biblionumber  => $biblionumber1,
87     managedby     => '',
88     manageddate   => '',
89     accepteddate  => dt_from_string,
90     note          => 'my note',
91 };
92
93 my $budgetperiod_id = AddBudgetPeriod({
94     budget_period_startdate   => '2008-01-01',
95     budget_period_enddate     => '2008-12-31',
96     budget_period_description => 'MAPERI',
97     budget_period_active      => 1,
98 });
99
100 my $budget_id = AddBudget({
101     budget_code      => 'ABCD',
102     budget_amount    => '123.132000',
103     budget_name      => 'ABCD',
104     budget_notes     => 'This is a note',
105     budget_period_id => $budgetperiod_id,
106 });
107 my $my_suggestion_with_budget = {
108     title         => 'my title 2',
109     author        => 'my author 2',
110     publishercode => 'my publishercode 2',
111     suggestedby   => $borrowernumber,
112     biblionumber  => $biblionumber1,
113     managedby     => '',
114     manageddate   => '',
115     accepteddate  => dt_from_string,
116     note          => 'my note',
117     budgetid      => $budget_id,
118 };
119
120
121 is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' );
122 is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
123 is( CountSuggestion('CHECKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
124 is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
125 is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
126
127 my $my_suggestionid = NewSuggestion($my_suggestion);
128 isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
129 my $my_suggestionid_with_budget = NewSuggestion($my_suggestion_with_budget);
130
131 is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' );
132 my $suggestion = GetSuggestion($my_suggestionid);
133 is( $suggestion->{title}, $my_suggestion->{title}, 'NewSuggestion stores the title correctly' );
134 is( $suggestion->{author}, $my_suggestion->{author}, 'NewSuggestion stores the author correctly' );
135 is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestion stores the publishercode correctly' );
136 is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' );
137 is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' );
138 is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
139 is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef for non existent foreign key (integer)' );
140 is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
141 is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' );
142
143 is( CountSuggestion('ASKED'), 2, 'CountSuggestion returns the correct number of suggestions' );
144
145
146 is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
147 my $mod_suggestion1 = {
148     title         => 'my modified title',
149     author        => 'my modified author',
150     publishercode => 'my modified publishercode',
151     managedby     => '',
152     manageddate   => '',
153 };
154 my $status = ModSuggestion($mod_suggestion1);
155 is( $status, undef, 'ModSuggestion without the suggestion id returns undef' );
156
157 $mod_suggestion1->{suggestionid} = $my_suggestionid;
158 $status = ModSuggestion($mod_suggestion1);
159 is( $status, 1, 'ModSuggestion modifies one entry' );
160 $suggestion = GetSuggestion($my_suggestionid);
161 is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title  correctly' );
162 is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
163 is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' );
164 is( $suggestion->{managedby}, undef, 'ModSuggestion stores empty string as undef for non existent foreign key (integer)' );
165 is( $suggestion->{manageddate}, undef, 'ModSuggestion stores empty string as undef for date' );
166 isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non given date value' );
167 is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
168
169 my $messages = C4::Letters::GetQueuedMessages({
170     borrowernumber => $borrowernumber,
171 });
172 is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
173
174 my $mod_suggestion2 = {
175     STATUS       => 'STALLED',
176     suggestionid => $my_suggestionid,
177 };
178 warning_is { $status = ModSuggestion($mod_suggestion2) }
179            "No suggestions STALLED letter transported by email",
180            "ModSuggestion status warning is correct";
181 is( $status, 1, "ModSuggestion Status OK");
182
183 my $mod_suggestion3 = {
184     STATUS       => 'CHECKED',
185     suggestionid => $my_suggestionid,
186 };
187 $status = ModSuggestion($mod_suggestion3);
188
189 is( $status, 1, 'ModSuggestion modifies one entry' );
190 $suggestion = GetSuggestion($my_suggestionid);
191 is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
192 $messages = C4::Letters::GetQueuedMessages({
193     borrowernumber => $borrowernumber,
194 });
195 is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
196
197 is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
198
199
200 is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
201 $suggestion = GetSuggestionInfo($my_suggestionid);
202 is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' );
203 is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfo returns the title correctly' );
204 is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfo returns the author correctly' );
205 is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfo returns the publisher code correctly' );
206 is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfo returns the borrower number correctly' );
207 is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfo returns the biblio number correctly' );
208 is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionInfo returns the status correctly' );
209 is( $suggestion->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionInfo returns the surname correctly' );
210 is( $suggestion->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionInfo returns the firstname correctly' );
211 is( $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfo returns the borrower number correctly' );
212
213
214 is( GetSuggestionFromBiblionumber(), undef, 'GetSuggestionFromBiblionumber without the biblio number returns undef' );
215 is( GetSuggestionFromBiblionumber(2), undef, 'GetSuggestionFromBiblionumber with an invalid biblio number returns undef' );
216 is( GetSuggestionFromBiblionumber($biblionumber1), $my_suggestionid, 'GetSuggestionFromBiblionumber functions correctly' );
217
218
219 is( GetSuggestionInfoFromBiblionumber(), undef, 'GetSuggestionInfoFromBiblionumber without the biblio number returns undef' );
220 is( GetSuggestionInfoFromBiblionumber(2), undef, 'GetSuggestionInfoFromBiblionumber with an invalid biblio number returns undef' );
221 $suggestion = GetSuggestionInfoFromBiblionumber($biblionumber1);
222 is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfoFromBiblionumber returns the suggestion id correctly' );
223 is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfoFromBiblionumber returns the title correctly' );
224 is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfoFromBiblionumber returns the author correctly' );
225 is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfoFromBiblionumber returns the publisher code correctly' );
226 is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumber returns the borrower number correctly' );
227 is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfoFromBiblionumber returns the biblio number correctly' );
228 is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionInfoFromBiblionumber returns the status correctly' );
229 is( $suggestion->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionInfoFromBiblionumber returns the surname correctly' );
230 is( $suggestion->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionInfoFromBiblionumber returns the firstname correctly' );
231 is( $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumeber returns the borrower number correctly' );
232
233
234 my $suggestions = GetSuggestionByStatus();
235 is( @$suggestions, 0, 'GetSuggestionByStatus without the status returns an empty array' );
236 $suggestions = GetSuggestionByStatus('CHECKED');
237 is( @$suggestions, 1, 'GetSuggestionByStatus returns the correct number of suggestions' );
238 is( $suggestions->[0]->{suggestionid}, $my_suggestionid, 'GetSuggestionByStatus returns the suggestion id correctly' );
239 is( $suggestions->[0]->{title}, $mod_suggestion1->{title}, 'GetSuggestionByStatus returns the title correctly' );
240 is( $suggestions->[0]->{author}, $mod_suggestion1->{author}, 'GetSuggestionByStatus returns the author correctly' );
241 is( $suggestions->[0]->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionByStatus returns the publisher code correctly' );
242 is( $suggestions->[0]->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionByStatus returns the borrower number correctly' );
243 is( $suggestions->[0]->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionByStatus returns the biblio number correctly' );
244 is( $suggestions->[0]->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionByStatus returns the status correctly' );
245 is( $suggestions->[0]->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionByStatus returns the surname correctly' );
246 is( $suggestions->[0]->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionByStatus returns the firstname correctly' );
247 is( $suggestions->[0]->{branchcodesuggestedby}, $member->{branchcode}, 'GetSuggestionByStatus returns the branch code correctly' );
248 is( $suggestions->[0]->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionByStatus returns the borrower number correctly' );
249 is( $suggestions->[0]->{categorycodesuggestedby}, $member->{categorycode}, 'GetSuggestionByStatus returns the category code correctly' );
250
251
252 is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arguments returns 0E0' );
253 my $biblionumber2 = 2;
254 my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio($my_suggestionid, $biblionumber2);
255 is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' );
256 $suggestion = GetSuggestion($my_suggestionid);
257 is( $suggestion->{biblionumber}, $biblionumber2, 'ConnectSuggestionAndBiblio updates the biblio number correctly' );
258
259 my $search_suggestion = SearchSuggestion();
260 is( @$search_suggestion, 2, 'SearchSuggestion without arguments returns all suggestions' );
261
262 $search_suggestion = SearchSuggestion({
263     title => $mod_suggestion1->{title},
264 });
265 is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
266 $search_suggestion = SearchSuggestion({
267     title => 'another title',
268 });
269 is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
270
271 $search_suggestion = SearchSuggestion({
272     author => $mod_suggestion1->{author},
273 });
274 is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
275 $search_suggestion = SearchSuggestion({
276     author => 'another author',
277 });
278 is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
279
280 $search_suggestion = SearchSuggestion({
281     publishercode => $mod_suggestion1->{publishercode},
282 });
283 is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
284 $search_suggestion = SearchSuggestion({
285     publishercode => 'another publishercode',
286 });
287 is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
288
289 $search_suggestion = SearchSuggestion({
290     STATUS => $mod_suggestion3->{STATUS},
291 });
292 is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
293
294 $search_suggestion = SearchSuggestion({
295     STATUS => q||
296 });
297 is( @$search_suggestion, 0, 'SearchSuggestion should not return all suggestions if we want the suggestions with a STATUS=""' );
298 $search_suggestion = SearchSuggestion({
299     STATUS => 'REJECTED',
300 });
301 is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
302
303 $search_suggestion = SearchSuggestion({
304     budgetid => '',
305 });
306 is( @$search_suggestion, 2, 'SearchSuggestion (budgetid = "") returns the correct number of suggestions' );
307 $search_suggestion = SearchSuggestion({
308     budgetid => $budget_id,
309 });
310 is( @$search_suggestion, 1, 'SearchSuggestion (budgetid = $budgetid) returns the correct number of suggestions' );
311 $search_suggestion = SearchSuggestion({
312     budgetid => '__NONE__',
313 });
314 is( @$search_suggestion, 1, 'SearchSuggestion (budgetid = "__NONE__") returns the correct number of suggestions' );
315 $search_suggestion = SearchSuggestion({
316     budgetid => '__ANY__',
317 });
318 is( @$search_suggestion, 2, 'SearchSuggestion (budgetid = "__ANY__") returns the correct number of suggestions' );
319
320 my $del_suggestion = {
321     title => 'my deleted title',
322     STATUS => 'CHECKED',
323     suggestedby => $borrowernumber,
324 };
325 my $del_suggestionid = NewSuggestion($del_suggestion);
326
327 is( CountSuggestion('CHECKED'), 2, 'CountSuggestion returns the correct number of suggestions' );
328
329 is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' );
330 is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' );
331 is( DelSuggestion(undef, $my_suggestionid), '', 'DelSuggestion with an invalid borrower number returns an empty string' );
332 $suggestion = DelSuggestion($borrowernumber, $my_suggestionid);
333 is( $suggestion, 1, 'DelSuggestion deletes one suggestion' );
334
335 $suggestions = GetSuggestionByStatus('CHECKED');
336 is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' );
337 is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
338
339 # Test budgetid fk
340 $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
341 my $my_suggestionid_test_budgetid = NewSuggestion($my_suggestion);
342 $suggestion = GetSuggestion($my_suggestionid_test_budgetid);
343 is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
344
345 $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
346 ModSuggestion( $my_suggestion );
347 $suggestion = GetSuggestion($my_suggestionid_test_budgetid);
348 is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
349
350 subtest 'GetUnprocessedSuggestions' => sub {
351     plan tests => 11;
352     $dbh->do(q|DELETE FROM suggestions|);
353     my $my_suggestionid         = NewSuggestion($my_suggestion);
354     my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
355     is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' );
356     my $status     = ModSuggestion($mod_suggestion1);
357     my $suggestion = GetSuggestion($my_suggestionid);
358     is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
359     ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
360     $suggestion = GetSuggestion($my_suggestionid);
361     is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
362
363     $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
364     is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
365
366     warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ) }
367                 'No suggestions REJECTED letter transported by email',
368                 'Warning raised if no REJECTED letter by email';
369     $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
370     is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
371
372     warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) ) } ); }
373                 'No suggestions ASKED letter transported by email',
374                 'Warning raised if no ASKED letter by email';
375     $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
376     is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' );
377     $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4);
378     is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' );
379     $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3);
380     is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' );
381     $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5);
382     is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
383 };
384
385 subtest 'DelSuggestionsOlderThan' => sub {
386     plan tests => 6;
387
388     Koha::Suggestions->delete;
389
390     # Add four suggestions; note that STATUS needs uppercase (FIXME)
391     my $d1 = output_pref({ dt => dt_from_string->add(days => -2), dateformat => 'sql' });
392     my $d2 = output_pref({ dt => dt_from_string->add(days => -4), dateformat => 'sql' });
393     my $sugg01 = $builder->build({ source => 'Suggestion', value => { date => $d1, STATUS => 'ASKED' }});
394     my $sugg02 = $builder->build({ source => 'Suggestion', value => { date => $d1, STATUS => 'CHECKED' }});
395     my $sugg03 = $builder->build({ source => 'Suggestion', value => { date => $d2, STATUS => 'ASKED' }});
396     my $sugg04 = $builder->build({ source => 'Suggestion', value => { date => $d2, STATUS => 'ACCEPTED' }});
397
398     # Test no parameter: should do nothing
399     C4::Suggestions::DelSuggestionsOlderThan();
400     is( Koha::Suggestions->count, 4, 'No suggestions deleted' );
401     # Test zero: should do nothing too
402     C4::Suggestions::DelSuggestionsOlderThan(0);
403     is( Koha::Suggestions->count, 4, 'No suggestions deleted again' );
404     # Test negative value
405     C4::Suggestions::DelSuggestionsOlderThan(-1);
406     is( Koha::Suggestions->count, 4, 'No suggestions deleted for -1' );
407
408     # Test positive values
409     C4::Suggestions::DelSuggestionsOlderThan(5);
410     is( Koha::Suggestions->count, 4, 'No suggestions>5d deleted' );
411     C4::Suggestions::DelSuggestionsOlderThan(3);
412     is( Koha::Suggestions->count, 3, '1 suggestions>3d deleted' );
413     C4::Suggestions::DelSuggestionsOlderThan(1);
414     is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' );
415 };
416
417 $schema->storage->txn_rollback;