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

(-)a/C4/Letters.pm (-8 / +3 lines)
Lines 1058-1067 sub GetPrintMessages { Link Here
1058
1058
1059
  my $messages = GetQueuedMessage( { borrowernumber => '123', limit => 20 } );
1059
  my $messages = GetQueuedMessage( { borrowernumber => '123', limit => 20 } );
1060
1060
1061
fetches messages out of the message queue.
1061
Fetches a list of messages from the message queue optionally filtered by borrowernumber
1062
and limited to specified limit.
1062
1063
1063
returns:
1064
Return is an arrayref of hashes, each has represents a message in the message queue.
1064
list of hashes, each has represents a message in the message queue.
1065
1065
1066
=cut
1066
=cut
1067
1067
Lines 1081-1091 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
1089
    if ( @whereclauses ) {
1084
    if ( @whereclauses ) {
1090
        $statement .= ' WHERE ' . join( 'AND', @whereclauses );
1085
        $statement .= ' WHERE ' . join( 'AND', @whereclauses );
1091
    }
1086
    }
(-)a/t/db_dependent/Suggestions.t (-17 / +10 lines)
Lines 42-47 $schema->storage->txn_begin; Link Here
42
my $dbh = C4::Context->dbh;
42
my $dbh = C4::Context->dbh;
43
my $builder = t::lib::TestBuilder->new;
43
my $builder = t::lib::TestBuilder->new;
44
44
45
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0");
46
45
# Reset item types to only the default ones
47
# Reset item types to only the default ones
46
$dbh->do(q|DELETE FROM itemtypes;|);
48
$dbh->do(q|DELETE FROM itemtypes;|);
47
my $sql = qq|
49
my $sql = qq|
Lines 191-198 isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non g Link Here
191
is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
193
is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
192
194
193
my $messages = C4::Letters::GetQueuedMessages({
195
my $messages = C4::Letters::GetQueuedMessages({
194
    borrowernumber => $borrowernumber,
196
    borrowernumber => $borrowernumber
195
    letter_code => 'CHECKED',
196
});
197
});
197
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
198
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
198
199
Lines 219-226 is( $status, 1, 'ModSuggestion modifies one entry' ); Link Here
219
$suggestion = GetSuggestion($my_suggestionid);
220
$suggestion = GetSuggestion($my_suggestionid);
220
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
221
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
221
$messages = C4::Letters::GetQueuedMessages({
222
$messages = C4::Letters::GetQueuedMessages({
222
    borrowernumber => $borrowernumber,
223
    borrowernumber => $borrowernumber
223
    letter_code => 'CHECKED',
224
});
224
});
225
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' );
226
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 230-237 is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number o Link Here
230
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
230
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
231
ModSuggestion($mod_suggestion3);
231
ModSuggestion($mod_suggestion3);
232
$messages = C4::Letters::GetQueuedMessages({
232
$messages = C4::Letters::GetQueuedMessages({
233
    borrowernumber => $borrowernumber,
233
    borrowernumber => $borrowernumber
234
    letter_code => 'CHECKED',
235
});
234
});
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');
235
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');
237
236
Lines 246-253 my $mod_suggestion4 = { Link Here
246
};
245
};
247
ModSuggestion($mod_suggestion4);
246
ModSuggestion($mod_suggestion4);
248
$messages = C4::Letters::GetQueuedMessages({
247
$messages = C4::Letters::GetQueuedMessages({
249
    borrowernumber => $borrowernumber2,
248
    borrowernumber => $borrowernumber2
250
    letter_code => 'CHECKED',
251
});
249
});
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');
250
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');
253
251
Lines 489-496 subtest 'EmailPurchaseSuggestions' => sub { Link Here
489
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress");
487
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress");
490
    NewSuggestion($my_suggestion);
488
    NewSuggestion($my_suggestion);
491
    my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
489
    my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
492
            borrowernumber => $borrowernumber,
490
            borrowernumber => $borrowernumber
493
            letter_code => 'NEW_SUGGESTION',
494
        });
491
        });
495
492
496
    is( @$newsuggestions_messages, 1, 'NewSuggestions sends an email' );
493
    is( @$newsuggestions_messages, 1, 'NewSuggestions sends an email' );
Lines 500-507 subtest 'EmailPurchaseSuggestions' => sub { Link Here
500
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "EmailAddressForSuggestions");
497
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "EmailAddressForSuggestions");
501
    NewSuggestion($my_suggestion);
498
    NewSuggestion($my_suggestion);
502
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
499
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
503
            borrowernumber => $borrowernumber,
500
            borrowernumber => $borrowernumber
504
            letter_code => 'NEW_SUGGESTION',
505
        });
501
        });
506
    my $message2 = C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id});
502
    my $message2 = C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id});
507
    is ($message2->{to_address}, 'a@b.c', 'to_address is EmailAddressForSuggestions');
503
    is ($message2->{to_address}, 'a@b.c', 'to_address is EmailAddressForSuggestions');
Lines 509-516 subtest 'EmailPurchaseSuggestions' => sub { Link Here
509
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "BranchEmailAddress");
505
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "BranchEmailAddress");
510
    NewSuggestion($my_suggestion);
506
    NewSuggestion($my_suggestion);
511
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
507
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
512
            borrowernumber => $borrowernumber,
508
            borrowernumber => $borrowernumber
513
            letter_code => 'NEW_SUGGESTION',
514
        });
509
        });
515
    my $message3 = C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id});
510
    my $message3 = C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id});
516
    is ($message3->{to_address}, 'branchemail@b.c', 'to_address is BranchEmailAddress');
511
    is ($message3->{to_address}, 'branchemail@b.c', 'to_address is BranchEmailAddress');
Lines 518-525 subtest 'EmailPurchaseSuggestions' => sub { Link Here
518
    Koha::Libraries->find('CPL')->update({ branchemail => undef });
513
    Koha::Libraries->find('CPL')->update({ branchemail => undef });
519
    NewSuggestion($my_suggestion);
514
    NewSuggestion($my_suggestion);
520
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
515
    $newsuggestions_messages = C4::Letters::GetQueuedMessages({
521
            borrowernumber => $borrowernumber,
516
            borrowernumber => $borrowernumber
522
            letter_code => 'NEW_SUGGESTION',
523
        });
517
        });
524
    my $message4 = C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id});
518
    my $message4 = C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id});
525
    isnt ($message4->{to_address}, 'branchemail@b.c', 'to_address is KohaAdminEmailAddress. Because branchemail is undef');
519
    isnt ($message4->{to_address}, 'branchemail@b.c', 'to_address is KohaAdminEmailAddress. Because branchemail is undef');
526
- 

Return to bug 5770