|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use DateTime::Duration; |
20 |
use DateTime::Duration; |
| 21 |
use Test::More tests => 103; |
21 |
use Test::More tests => 106; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
|
23 |
|
| 24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
|
Lines 74-81
my $member = {
Link Here
|
| 74 |
surname => 'my surname', |
74 |
surname => 'my surname', |
| 75 |
categorycode => $patron_category->{categorycode}, |
75 |
categorycode => $patron_category->{categorycode}, |
| 76 |
branchcode => 'CPL', |
76 |
branchcode => 'CPL', |
|
|
77 |
smsalertnumber => 12345, |
| 77 |
}; |
78 |
}; |
|
|
79 |
|
| 80 |
my $member2 = { |
| 81 |
firstname => 'my firstname', |
| 82 |
surname => 'my surname', |
| 83 |
categorycode => $patron_category->{categorycode}, |
| 84 |
branchcode => 'CPL', |
| 85 |
email => 'to@example.com', |
| 86 |
}; |
| 87 |
|
| 78 |
my $borrowernumber = Koha::Patron->new($member)->store->borrowernumber; |
88 |
my $borrowernumber = Koha::Patron->new($member)->store->borrowernumber; |
|
|
89 |
my $borrowernumber2 = Koha::Patron->new($member2)->store->borrowernumber; |
| 79 |
|
90 |
|
| 80 |
my $biblionumber1 = 1; |
91 |
my $biblionumber1 = 1; |
| 81 |
my $my_suggestion = { |
92 |
my $my_suggestion = { |
|
Lines 116-122
my $my_suggestion_with_budget = {
Link Here
|
| 116 |
note => 'my note', |
127 |
note => 'my note', |
| 117 |
budgetid => $budget_id, |
128 |
budgetid => $budget_id, |
| 118 |
}; |
129 |
}; |
| 119 |
|
130 |
my $my_suggestion_with_budget2 = { |
|
|
131 |
title => 'my title 3', |
| 132 |
author => 'my author 3', |
| 133 |
publishercode => 'my publishercode 3', |
| 134 |
suggestedby => $borrowernumber2, |
| 135 |
biblionumber => $biblionumber1, |
| 136 |
managedby => '', |
| 137 |
manageddate => '', |
| 138 |
accepteddate => dt_from_string, |
| 139 |
note => 'my note', |
| 140 |
budgetid => $budget_id, |
| 141 |
}; |
| 120 |
|
142 |
|
| 121 |
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' ); |
143 |
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' ); |
| 122 |
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
144 |
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
|
Lines 184-191
my $mod_suggestion3 = {
Link Here
|
| 184 |
STATUS => 'CHECKED', |
206 |
STATUS => 'CHECKED', |
| 185 |
suggestionid => $my_suggestionid, |
207 |
suggestionid => $my_suggestionid, |
| 186 |
}; |
208 |
}; |
| 187 |
$status = ModSuggestion($mod_suggestion3); |
|
|
| 188 |
|
209 |
|
|
|
210 |
#Test the message_transport_type of suggestion notices |
| 211 |
|
| 212 |
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is disabled |
| 213 |
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 ); |
| 214 |
$status = ModSuggestion($mod_suggestion3); |
| 189 |
is( $status, 1, 'ModSuggestion modifies one entry' ); |
215 |
is( $status, 1, 'ModSuggestion modifies one entry' ); |
| 190 |
$suggestion = GetSuggestion($my_suggestionid); |
216 |
$suggestion = GetSuggestion($my_suggestionid); |
| 191 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); |
217 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); |
|
Lines 193-201
$messages = C4::Letters::GetQueuedMessages({
Link Here
|
| 193 |
borrowernumber => $borrowernumber, |
219 |
borrowernumber => $borrowernumber, |
| 194 |
}); |
220 |
}); |
| 195 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
221 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
| 196 |
|
222 |
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email'); |
| 197 |
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
223 |
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
| 198 |
|
224 |
|
|
|
225 |
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a smsalertnumber and no email |
| 226 |
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 ); |
| 227 |
ModSuggestion($mod_suggestion3); |
| 228 |
$messages = C4::Letters::GetQueuedMessages({ |
| 229 |
borrowernumber => $borrowernumber, |
| 230 |
}); |
| 231 |
is ($messages->[1]->{message_transport_type}, 'sms', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is sms if the borrower has no email'); |
| 232 |
|
| 233 |
#Make a new suggestion for a borrower with defined email and no smsalertnumber |
| 234 |
my $my_suggestion_2_id = NewSuggestion($my_suggestion_with_budget2); |
| 235 |
|
| 236 |
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a defined email and no smsalertnumber |
| 237 |
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 ); |
| 238 |
my $mod_suggestion4 = { |
| 239 |
STATUS => 'CHECKED', |
| 240 |
suggestionid => $my_suggestion_2_id, |
| 241 |
}; |
| 242 |
ModSuggestion($mod_suggestion4); |
| 243 |
$messages = C4::Letters::GetQueuedMessages({ |
| 244 |
borrowernumber => $borrowernumber2, |
| 245 |
}); |
| 246 |
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is email if the borrower has an email'); |
| 199 |
|
247 |
|
| 200 |
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); |
248 |
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); |
| 201 |
$suggestion = GetSuggestionInfo($my_suggestionid); |
249 |
$suggestion = GetSuggestionInfo($my_suggestionid); |
|
Lines 234-240
is( $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSugges
Link Here
|
| 234 |
my $suggestions = GetSuggestionByStatus(); |
282 |
my $suggestions = GetSuggestionByStatus(); |
| 235 |
is( @$suggestions, 0, 'GetSuggestionByStatus without the status returns an empty array' ); |
283 |
is( @$suggestions, 0, 'GetSuggestionByStatus without the status returns an empty array' ); |
| 236 |
$suggestions = GetSuggestionByStatus('CHECKED'); |
284 |
$suggestions = GetSuggestionByStatus('CHECKED'); |
| 237 |
is( @$suggestions, 1, 'GetSuggestionByStatus returns the correct number of suggestions' ); |
285 |
is( @$suggestions, 2, 'GetSuggestionByStatus returns the correct number of suggestions' ); |
| 238 |
is( $suggestions->[0]->{suggestionid}, $my_suggestionid, 'GetSuggestionByStatus returns the suggestion id correctly' ); |
286 |
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' ); |
287 |
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' ); |
288 |
is( $suggestions->[0]->{author}, $mod_suggestion1->{author}, 'GetSuggestionByStatus returns the author correctly' ); |
|
Lines 257-263
$suggestion = GetSuggestion($my_suggestionid);
Link Here
|
| 257 |
is( $suggestion->{biblionumber}, $biblionumber2, 'ConnectSuggestionAndBiblio updates the biblio number correctly' ); |
305 |
is( $suggestion->{biblionumber}, $biblionumber2, 'ConnectSuggestionAndBiblio updates the biblio number correctly' ); |
| 258 |
|
306 |
|
| 259 |
my $search_suggestion = SearchSuggestion(); |
307 |
my $search_suggestion = SearchSuggestion(); |
| 260 |
is( @$search_suggestion, 2, 'SearchSuggestion without arguments returns all suggestions' ); |
308 |
is( @$search_suggestion, 3, 'SearchSuggestion without arguments returns all suggestions' ); |
| 261 |
|
309 |
|
| 262 |
$search_suggestion = SearchSuggestion({ |
310 |
$search_suggestion = SearchSuggestion({ |
| 263 |
title => $mod_suggestion1->{title}, |
311 |
title => $mod_suggestion1->{title}, |
|
Lines 289-295
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of sugg
Link Here
|
| 289 |
$search_suggestion = SearchSuggestion({ |
337 |
$search_suggestion = SearchSuggestion({ |
| 290 |
STATUS => $mod_suggestion3->{STATUS}, |
338 |
STATUS => $mod_suggestion3->{STATUS}, |
| 291 |
}); |
339 |
}); |
| 292 |
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' ); |
340 |
is( @$search_suggestion, 2, 'SearchSuggestion returns the correct number of suggestions' ); |
| 293 |
|
341 |
|
| 294 |
$search_suggestion = SearchSuggestion({ |
342 |
$search_suggestion = SearchSuggestion({ |
| 295 |
STATUS => q|| |
343 |
STATUS => q|| |
|
Lines 303-313
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of sugg
Link Here
|
| 303 |
$search_suggestion = SearchSuggestion({ |
351 |
$search_suggestion = SearchSuggestion({ |
| 304 |
budgetid => '', |
352 |
budgetid => '', |
| 305 |
}); |
353 |
}); |
| 306 |
is( @$search_suggestion, 2, 'SearchSuggestion (budgetid = "") returns the correct number of suggestions' ); |
354 |
is( @$search_suggestion, 3, 'SearchSuggestion (budgetid = "") returns the correct number of suggestions' ); |
| 307 |
$search_suggestion = SearchSuggestion({ |
355 |
$search_suggestion = SearchSuggestion({ |
| 308 |
budgetid => $budget_id, |
356 |
budgetid => $budget_id, |
| 309 |
}); |
357 |
}); |
| 310 |
is( @$search_suggestion, 1, 'SearchSuggestion (budgetid = $budgetid) returns the correct number of suggestions' ); |
358 |
is( @$search_suggestion, 2, 'SearchSuggestion (budgetid = $budgetid) returns the correct number of suggestions' ); |
| 311 |
$search_suggestion = SearchSuggestion({ |
359 |
$search_suggestion = SearchSuggestion({ |
| 312 |
budgetid => '__NONE__', |
360 |
budgetid => '__NONE__', |
| 313 |
}); |
361 |
}); |
|
Lines 315-321
is( @$search_suggestion, 1, 'SearchSuggestion (budgetid = "__NONE__") returns th
Link Here
|
| 315 |
$search_suggestion = SearchSuggestion({ |
363 |
$search_suggestion = SearchSuggestion({ |
| 316 |
budgetid => '__ANY__', |
364 |
budgetid => '__ANY__', |
| 317 |
}); |
365 |
}); |
| 318 |
is( @$search_suggestion, 2, 'SearchSuggestion (budgetid = "__ANY__") returns the correct number of suggestions' ); |
366 |
is( @$search_suggestion, 3, 'SearchSuggestion (budgetid = "__ANY__") returns the correct number of suggestions' ); |
| 319 |
|
367 |
|
| 320 |
my $del_suggestion = { |
368 |
my $del_suggestion = { |
| 321 |
title => 'my deleted title', |
369 |
title => 'my deleted title', |
|
Lines 324-330
my $del_suggestion = {
Link Here
|
| 324 |
}; |
372 |
}; |
| 325 |
my $del_suggestionid = NewSuggestion($del_suggestion); |
373 |
my $del_suggestionid = NewSuggestion($del_suggestion); |
| 326 |
|
374 |
|
| 327 |
is( CountSuggestion('CHECKED'), 2, 'CountSuggestion returns the correct number of suggestions' ); |
375 |
is( CountSuggestion('CHECKED'), 3, 'CountSuggestion returns the correct number of suggestions' ); |
| 328 |
|
376 |
|
| 329 |
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' ); |
377 |
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' ); |
| 330 |
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' ); |
378 |
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' ); |
|
Lines 333-340
$suggestion = DelSuggestion($borrowernumber, $my_suggestionid);
Link Here
|
| 333 |
is( $suggestion, 1, 'DelSuggestion deletes one suggestion' ); |
381 |
is( $suggestion, 1, 'DelSuggestion deletes one suggestion' ); |
| 334 |
|
382 |
|
| 335 |
$suggestions = GetSuggestionByStatus('CHECKED'); |
383 |
$suggestions = GetSuggestionByStatus('CHECKED'); |
| 336 |
is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' ); |
384 |
is( @$suggestions, 2, 'DelSuggestion deletes one suggestion' ); |
| 337 |
is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' ); |
385 |
is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' ); |
| 338 |
|
386 |
|
| 339 |
# Test budgetid fk |
387 |
# Test budgetid fk |
| 340 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
388 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
| 341 |
- |
|
|