Lines 34-40
use Koha::Patrons;
Link Here
|
34 |
use Koha::Suggestions; |
34 |
use Koha::Suggestions; |
35 |
|
35 |
|
36 |
BEGIN { |
36 |
BEGIN { |
37 |
use_ok('C4::Suggestions', qw( NewSuggestion GetSuggestion ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan )); |
37 |
use_ok('C4::Suggestions', qw( GetSuggestion ModSuggestion GetSuggestionInfo GetSuggestionFromBiblionumber GetSuggestionInfoFromBiblionumber GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan )); |
38 |
} |
38 |
} |
39 |
|
39 |
|
40 |
my $schema = Koha::Database->new->schema; |
40 |
my $schema = Koha::Database->new->schema; |
Lines 159-179
my $my_suggestion_without_suggestedby = {
Link Here
|
159 |
quantity => '', # Insert an empty string into int to catch strict SQL modes errors |
159 |
quantity => '', # Insert an empty string into int to catch strict SQL modes errors |
160 |
}; |
160 |
}; |
161 |
|
161 |
|
162 |
my $my_suggestionid = NewSuggestion($my_suggestion); |
162 |
my $my_suggestion_object = Koha::Suggestion->new($my_suggestion)->store; |
163 |
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' ); |
163 |
my $my_suggestionid = $my_suggestion_object->id; |
164 |
my $my_suggestionid_with_budget = NewSuggestion($my_suggestion_with_budget); |
164 |
isnt( $my_suggestionid, 0, 'Suggestion is correctly saved' ); |
|
|
165 |
my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store; |
166 |
my $my_suggestionid_with_budget = $my_suggestion_with_budget_object->id; |
165 |
|
167 |
|
166 |
is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' ); |
168 |
is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' ); |
167 |
my $suggestion = GetSuggestion($my_suggestionid); |
169 |
my $suggestion = GetSuggestion($my_suggestionid); |
168 |
is( $suggestion->{title}, $my_suggestion->{title}, 'NewSuggestion stores the title correctly' ); |
170 |
is( $suggestion->{title}, $my_suggestion->{title}, 'Suggestion stores the title correctly' ); |
169 |
is( $suggestion->{author}, $my_suggestion->{author}, 'NewSuggestion stores the author correctly' ); |
171 |
is( $suggestion->{author}, $my_suggestion->{author}, 'Suggestion stores the author correctly' ); |
170 |
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestion stores the publishercode correctly' ); |
172 |
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' ); |
171 |
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' ); |
173 |
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'Suggestion stores the borrower number correctly' ); |
172 |
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' ); |
174 |
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'Suggestion stores the biblio number correctly' ); |
173 |
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' ); |
175 |
is( $suggestion->{STATUS}, 'ASKED', 'Suggestion stores a suggestion with the status ASKED by default' ); |
174 |
is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef for non existent foreign key (integer)' ); |
176 |
is( $suggestion->{managedby}, undef, 'Suggestion stores empty string as undef for non existent foreign key (integer)' ); |
175 |
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' ); |
177 |
is( $suggestion->{manageddate}, undef, 'Suggestion stores empty string as undef for date' ); |
176 |
is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' ); |
178 |
is( $suggestion->{budgetid}, undef, 'Suggestion should set budgetid to NULL if not given' ); |
177 |
|
179 |
|
178 |
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); |
180 |
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); |
179 |
my $mod_suggestion1 = { |
181 |
my $mod_suggestion1 = { |
Lines 240-246
$messages = C4::Letters::GetQueuedMessages({
Link Here
|
240 |
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'); |
242 |
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'); |
241 |
|
243 |
|
242 |
#Make a new suggestion for a borrower with defined email and no smsalertnumber |
244 |
#Make a new suggestion for a borrower with defined email and no smsalertnumber |
243 |
my $my_suggestion_2_id = NewSuggestion($my_suggestion_with_budget2); |
245 |
my $my_suggestion_2_object = Koha::Suggestion->new($my_suggestion_with_budget2)->store(); |
|
|
246 |
my $my_suggestion_2_id = $my_suggestion_2_object->id; |
244 |
|
247 |
|
245 |
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a defined email and no smsalertnumber |
248 |
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a defined email and no smsalertnumber |
246 |
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 ); |
249 |
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 ); |
Lines 334-340
my $del_suggestion = {
Link Here
|
334 |
STATUS => 'CHECKED', |
337 |
STATUS => 'CHECKED', |
335 |
suggestedby => $borrowernumber, |
338 |
suggestedby => $borrowernumber, |
336 |
}; |
339 |
}; |
337 |
my $del_suggestionid = NewSuggestion($del_suggestion); |
340 |
my $del_suggestion_object = Koha::Suggestion->new($del_suggestion)->store(); |
|
|
341 |
my $del_suggestionid = $del_suggestion_object->id; |
338 |
|
342 |
|
339 |
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' ); |
343 |
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' ); |
340 |
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' ); |
344 |
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' ); |
Lines 348-361
is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes
Link Here
|
348 |
|
352 |
|
349 |
# Test budgetid fk |
353 |
# Test budgetid fk |
350 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
354 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
351 |
my $my_suggestionid_test_budgetid = NewSuggestion($my_suggestion); |
355 |
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store; |
|
|
356 |
my $my_suggestionid_test_budgetid = $my_suggestionid_test_budget_object->id; |
352 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
357 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
353 |
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' ); |
358 |
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); |
354 |
|
359 |
|
355 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
360 |
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB |
356 |
ModSuggestion( $my_suggestion ); |
361 |
ModSuggestion( $my_suggestion ); |
357 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
362 |
$suggestion = GetSuggestion($my_suggestionid_test_budgetid); |
358 |
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' ); |
363 |
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' ); |
359 |
|
364 |
|
360 |
my $suggestion2 = { |
365 |
my $suggestion2 = { |
361 |
title => "Cuisine d'automne", |
366 |
title => "Cuisine d'automne", |
Lines 378-384
is($record->field( $author_tag )->subfield( $author_subfield ), "Catherine", "Re
Link Here
|
378 |
subtest 'GetUnprocessedSuggestions' => sub { |
383 |
subtest 'GetUnprocessedSuggestions' => sub { |
379 |
plan tests => 11; |
384 |
plan tests => 11; |
380 |
$dbh->do(q|DELETE FROM suggestions|); |
385 |
$dbh->do(q|DELETE FROM suggestions|); |
381 |
my $my_suggestionid = NewSuggestion($my_suggestion); |
386 |
my $my_suggestionid = Koha::Suggestion->new($my_suggestion)->store->id; |
382 |
my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
387 |
my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; |
383 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' ); |
388 |
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' ); |
384 |
my $status = ModSuggestion($mod_suggestion1); |
389 |
my $status = ModSuggestion($mod_suggestion1); |
Lines 452-486
subtest 'EmailPurchaseSuggestions' => sub {
Link Here
|
452 |
|
457 |
|
453 |
# EmailPurchaseSuggestions set to disabled |
458 |
# EmailPurchaseSuggestions set to disabled |
454 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0" ); |
459 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0" ); |
455 |
NewSuggestion($my_suggestion); |
460 |
Koha::Suggestion->new($my_suggestion)->store; |
456 |
my $newsuggestions_messages = C4::Letters::GetQueuedMessages( |
461 |
my $newsuggestions_messages = C4::Letters::GetQueuedMessages( |
457 |
{ |
462 |
{ |
458 |
borrowernumber => $borrowernumber |
463 |
borrowernumber => $borrowernumber |
459 |
} |
464 |
} |
460 |
); |
465 |
); |
461 |
is( @$newsuggestions_messages, 0, |
466 |
is( @$newsuggestions_messages, 0, |
462 |
'NewSuggestions does not send an email when disabled' ); |
467 |
'New suggestion does not send an email when EmailPurchaseSuggestions disabled' ); |
463 |
|
468 |
|
464 |
# EmailPurchaseSuggestions set to BranchEmailAddress |
469 |
# EmailPurchaseSuggestions set to BranchEmailAddress |
465 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", |
470 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", |
466 |
"BranchEmailAddress" ); |
471 |
"BranchEmailAddress" ); |
467 |
NewSuggestion($my_suggestion); |
472 |
Koha::Suggestion->new($my_suggestion)->store; |
468 |
|
473 |
|
469 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
474 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
470 |
NewSuggestion($my_suggestion); |
475 |
Koha::Suggestion->new($my_suggestion)->store; |
471 |
|
476 |
|
472 |
Koha::Libraries->find('CPL')->update( { branchemail => 'branchemail@hosting.com' } ); |
477 |
Koha::Libraries->find('CPL')->update( { branchemail => 'branchemail@hosting.com' } ); |
473 |
NewSuggestion($my_suggestion); |
478 |
Koha::Suggestion->new($my_suggestion)->store; |
474 |
|
479 |
|
475 |
Koha::Libraries->find('CPL')->update( { branchreplyto => 'branchemail@b.c' } ); |
480 |
Koha::Libraries->find('CPL')->update( { branchreplyto => 'branchemail@b.c' } ); |
476 |
NewSuggestion($my_suggestion); |
481 |
Koha::Suggestion->new($my_suggestion)->store; |
477 |
|
482 |
|
478 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
483 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
479 |
{ |
484 |
{ |
480 |
borrowernumber => $borrowernumber |
485 |
borrowernumber => $borrowernumber |
481 |
} |
486 |
} |
482 |
); |
487 |
); |
483 |
isnt( @$newsuggestions_messages, 0, 'NewSuggestions sends an email' ); |
488 |
isnt( @$newsuggestions_messages, 0, 'New suggestions sends an email wne EmailPurchaseSuggestions enabled' ); |
484 |
my $message1 = |
489 |
my $message1 = |
485 |
C4::Letters::GetMessage( $newsuggestions_messages->[0]->{message_id} ); |
490 |
C4::Letters::GetMessage( $newsuggestions_messages->[0]->{message_id} ); |
486 |
is( $message1->{to_address}, 'noreply@hosting.com', |
491 |
is( $message1->{to_address}, 'noreply@hosting.com', |
Lines 507-516
subtest 'EmailPurchaseSuggestions' => sub {
Link Here
|
507 |
"KohaAdminEmailAddress" ); |
512 |
"KohaAdminEmailAddress" ); |
508 |
|
513 |
|
509 |
t::lib::Mocks::mock_preference( "ReplytoDefault", undef ); |
514 |
t::lib::Mocks::mock_preference( "ReplytoDefault", undef ); |
510 |
NewSuggestion($my_suggestion); |
515 |
Koha::Suggestion->new($my_suggestion)->store; |
511 |
|
516 |
|
512 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
517 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
513 |
NewSuggestion($my_suggestion); |
518 |
Koha::Suggestion->new($my_suggestion)->store; |
514 |
|
519 |
|
515 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
520 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
516 |
{ |
521 |
{ |
Lines 531-544
subtest 'EmailPurchaseSuggestions' => sub {
Link Here
|
531 |
"EmailAddressForSuggestions" ); |
536 |
"EmailAddressForSuggestions" ); |
532 |
|
537 |
|
533 |
t::lib::Mocks::mock_preference( "ReplytoDefault", undef ); |
538 |
t::lib::Mocks::mock_preference( "ReplytoDefault", undef ); |
534 |
NewSuggestion($my_suggestion); |
539 |
Koha::Suggestion->new($my_suggestion)->store; |
535 |
|
540 |
|
536 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
541 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
537 |
NewSuggestion($my_suggestion); |
542 |
Koha::Suggestion->new($my_suggestion)->store; |
538 |
|
543 |
|
539 |
t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", |
544 |
t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", |
540 |
'suggestions@b.c' ); |
545 |
'suggestions@b.c' ); |
541 |
NewSuggestion($my_suggestion); |
546 |
Koha::Suggestion->new($my_suggestion)->store; |
542 |
|
547 |
|
543 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
548 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
544 |
{ |
549 |
{ |
Lines 565-571
subtest 'ModSuggestion should work on suggestions without a suggester' => sub {
Link Here
|
565 |
plan tests => 2; |
570 |
plan tests => 2; |
566 |
|
571 |
|
567 |
$dbh->do(q|DELETE FROM suggestions|); |
572 |
$dbh->do(q|DELETE FROM suggestions|); |
568 |
my $my_suggestionid = NewSuggestion($my_suggestion_without_suggestedby); |
573 |
my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id; |
569 |
$suggestion = GetSuggestion($my_suggestionid); |
574 |
$suggestion = GetSuggestion($my_suggestionid); |
570 |
is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" ); |
575 |
is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" ); |
571 |
|
576 |
|
572 |
- |
|
|