View | Details | Raw Unified | Return to bug 5770
Collapse All | Expand All

(-)a/C4/Letters.pm (+5 lines)
Lines 1081-1086 ENDSQL Link Here
1081
        push @query_params, $params->{'borrowernumber'};
1081
        push @query_params, $params->{'borrowernumber'};
1082
    }
1082
    }
1083
1083
1084
    if ( exists $params->{'letter_code'} ) {
1085
        push @whereclauses, ' letter_code = ? ';
1086
        push @query_params, $params->{'letter_code'};
1087
    }
1088
1084
    if ( @whereclauses ) {
1089
    if ( @whereclauses ) {
1085
        $statement .= ' WHERE ' . join( 'AND', @whereclauses );
1090
        $statement .= ' WHERE ' . join( 'AND', @whereclauses );
1086
    }
1091
    }
(-)a/t/db_dependent/Suggestions.t (-2 / +56 lines)
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 => 106;
21
use Test::More tests => 107;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
use t::lib::Mocks;
24
use t::lib::Mocks;
Lines 61-66 $dbh->do(q|DELETE FROM borrowers|); Link Here
61
$dbh->do(q|DELETE FROM letter|);
61
$dbh->do(q|DELETE FROM letter|);
62
$dbh->do(q|DELETE FROM message_queue|);
62
$dbh->do(q|DELETE FROM message_queue|);
63
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|);
63
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|);
64
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'NEW_SUGGESTION', 'Content for new suggestion')|);
64
65
65
# Add CPL if missing.
66
# Add CPL if missing.
66
if (not defined Koha::Libraries->find('CPL')) {
67
if (not defined Koha::Libraries->find('CPL')) {
Lines 95-100 my $my_suggestion = { Link Here
95
    publishercode => 'my publishercode',
96
    publishercode => 'my publishercode',
96
    suggestedby   => $borrowernumber,
97
    suggestedby   => $borrowernumber,
97
    biblionumber  => $biblionumber1,
98
    biblionumber  => $biblionumber1,
99
    branchcode    => 'CPL',
98
    managedby     => '',
100
    managedby     => '',
99
    manageddate   => '',
101
    manageddate   => '',
100
    accepteddate  => dt_from_string,
102
    accepteddate  => dt_from_string,
Lines 190-195 is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not Link Here
190
192
191
my $messages = C4::Letters::GetQueuedMessages({
193
my $messages = C4::Letters::GetQueuedMessages({
192
    borrowernumber => $borrowernumber,
194
    borrowernumber => $borrowernumber,
195
    letter_code => 'CHECKED',
193
});
196
});
194
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
197
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
195
198
Lines 217-222 $suggestion = GetSuggestion($my_suggestionid); Link Here
217
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
220
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
218
$messages = C4::Letters::GetQueuedMessages({
221
$messages = C4::Letters::GetQueuedMessages({
219
    borrowernumber => $borrowernumber,
222
    borrowernumber => $borrowernumber,
223
    letter_code => 'CHECKED',
220
});
224
});
221
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
225
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
222
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email');
226
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email');
Lines 227-232 t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 ); Link Here
227
ModSuggestion($mod_suggestion3);
231
ModSuggestion($mod_suggestion3);
228
$messages = C4::Letters::GetQueuedMessages({
232
$messages = C4::Letters::GetQueuedMessages({
229
    borrowernumber => $borrowernumber,
233
    borrowernumber => $borrowernumber,
234
    letter_code => 'CHECKED',
230
});
235
});
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');
236
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
237
Lines 242-247 my $mod_suggestion4 = { Link Here
242
ModSuggestion($mod_suggestion4);
247
ModSuggestion($mod_suggestion4);
243
$messages = C4::Letters::GetQueuedMessages({
248
$messages = C4::Letters::GetQueuedMessages({
244
    borrowernumber => $borrowernumber2,
249
    borrowernumber => $borrowernumber2,
250
    letter_code => 'CHECKED',
245
});
251
});
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');
252
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');
247
253
Lines 462-465 subtest 'DelSuggestionsOlderThan' => sub { Link Here
462
    is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' );
468
    is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' );
463
};
469
};
464
470
471
subtest 'EmailPurchaseSuggestions' => sub {
472
    plan tests => 5;
473
474
    $dbh->do(q|DELETE FROM message_queue|);
475
476
    Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' });
477
    t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost');
478
    t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c');
479
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress
480
481
    NewSuggestion($my_suggestion);
482
    my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
483
            borrowernumber => $borrowernumber,
484
            letter_code => 'NEW_SUGGESTION',
485
        });
486
487
    is( @$newsuggestions_messages, 1, 'NewSuggestions sends an email' );
488
    my $message1 = C4::Letters::GetMessage( $newsuggestions_messages->[0]->{message_id});
489
    is ($message1->{to_address}, 'root@localhost', 'to_address is KohaAdminEmailAddress');
490
491
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "EmailAddressForSuggestions");
492
    NewSuggestion($my_suggestion);
493
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
494
            borrowernumber => $borrowernumber,
495
            letter_code => 'NEW_SUGGESTION',
496
        });
497
    my $message2 = C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id});
498
    is ($message2->{to_address}, 'a@b.c', 'to_address is EmailAddressForSuggestions');
499
500
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "BranchEmailAddress");
501
    NewSuggestion($my_suggestion);
502
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
503
            borrowernumber => $borrowernumber,
504
            letter_code => 'NEW_SUGGESTION',
505
        });
506
    my $message3 = C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id});
507
    is ($message3->{to_address}, 'branchemail@b.c', 'to_address is BranchEmailAddress');
508
509
    Koha::Libraries->find('CPL')->update({ branchemail => undef });
510
    NewSuggestion($my_suggestion);
511
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
512
            borrowernumber => $borrowernumber,
513
            letter_code => 'NEW_SUGGESTION',
514
        });
515
    my $message4 = C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id});
516
    isnt ($message4->{to_address}, 'branchemail@b.c', 'to_address is KohaAdminEmailAddress. Because branchemail is undef');
517
518
};
519
465
$schema->storage->txn_rollback;
520
$schema->storage->txn_rollback;
466
- 

Return to bug 5770