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

(-)a/t/db_dependent/Letters.t (-2 / +69 lines)
Lines 869-875 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
869
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
869
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
870
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
870
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
871
871
872
    t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
873
    my $patron = Koha::Patrons->find($borrowernumber);
872
    my $patron = Koha::Patrons->find($borrowernumber);
874
    $dbh->do(q|
873
    $dbh->do(q|
875
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
874
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
Lines 953-958 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
953
    })->next()->to_address();
952
    })->next()->to_address();
954
    is( $sms_message_address, '5555555555', 'SendQueuedMessages populates the to address correctly for SMS by SMS::Send driver to smsalertnumber when to_address is set incorrectly' );
953
    is( $sms_message_address, '5555555555', 'SendQueuedMessages populates the to address correctly for SMS by SMS::Send driver to smsalertnumber when to_address is set incorrectly' );
955
954
955
    $schema->resultset('MessageQueue')->search({borrowernumber => $borrowernumber, status => 'sent'})->delete(); #clear borrower queue
956
};
957
958
subtest 'Test guarantor handling in SendQueuedMessages' => sub {
959
960
    plan tests => 14;
961
962
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' );
963
964
    my $patron     = Koha::Patrons->find($borrowernumber);
965
    my $guarantor1 = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'g1@email.com' } } );
966
    my $guarantor2 = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'g2@email.com' } } );
967
    $patron->add_guarantor( { guarantor_id => $guarantor1->borrowernumber, relationship => 'test' } );
968
    $patron->add_guarantor( { guarantor_id => $guarantor2->borrowernumber, relationship => 'test' } );
969
970
    $my_message = {
971
        'letter' => {
972
            'content'      => 'a message',
973
            'metadata'     => 'metadata',
974
            'code'         => 'TEST_MESSAGE',
975
            'content_type' => 'text/plain',
976
            'title'        => 'message title'
977
        },
978
        'borrowernumber'         => $borrowernumber,
979
        'to_address'             => undef,
980
        'message_transport_type' => 'email',
981
        'from_address'           => 'from@example.com'
982
    };
983
    $message_id = C4::Letters::EnqueueLetter($my_message);
984
985
    t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
986
987
    # reset message
988
    $schema->resultset('MessageQueue')->search( { borrowernumber => $borrowernumber, status => 'sent' } )
989
        ->update( { status => 'pending', failure_code => undef } );
990
991
    warning_like { C4::Letters::SendQueuedMessages(); }
992
    qr|Fake send_or_die|,
993
        "SendQueuedMessages is using the mocked send_or_die routine";
994
995
    $message = $schema->resultset('MessageQueue')->search(
996
        {
997
            borrowernumber => $borrowernumber,
998
            status         => 'sent'
999
        }
1000
    )->next();
1001
1002
    is(
1003
        $message->to_address(),
1004
        $guarantor1->email,
1005
        'SendQueuedMessages uses first guarantor email for "to" when patron has no email'
1006
    );
1007
1008
    is(
1009
        $message->cc_address(),
1010
        $guarantor2->email,
1011
        'SendQueuedMessages sets cc address to second guarantor email when "to" takes first guarantor email'
1012
    );
1013
1014
    is( $email_object->email->header('To'), $guarantor1->email, "mailto correctly uses first guarantor" );
1015
    is( $email_object->email->header('Cc'), $guarantor2->email, "cc correctly uses second guarantor" );
1016
1017
    t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
1018
    warning_like { C4::Letters::SendQueuedMessages(); }
1019
    qr|No 'to_address', email address or guarantors email address for borrowernumber|,
1020
        "SendQueuedMessages fails when no to_address, patron notice email and RedirectGuaranteeEmail is not set";
1021
1022
    $schema->resultset('MessageQueue')->search( { borrowernumber => $borrowernumber, status => 'sent' } )->delete()
1023
        ;    #clear borrower queue
956
};
1024
};
957
1025
958
subtest 'get_item_content' => sub {
1026
subtest 'get_item_content' => sub {
959
- 

Return to bug 12532