3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Test::More tests => 5;
23 use t::lib::TestBuilder;
26 use C4::Letters qw( GetPreparedLetter );
29 my $schema = Koha::Database->schema;
30 $schema->storage->txn_begin();
32 my $builder = t::lib::TestBuilder->new();
33 my $dbh = C4::Context->dbh;
34 $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('test', 'TEST_MESSAGE','Test', '[% biblio.title %]', "
39 my $biblio_1 = $builder->build_sample_biblio({ title => "heÄllo" });
40 my $biblio_2 = $builder->build_sample_biblio({ title => "hell❤️" });
41 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
42 my $letter = C4::Letters::GetPreparedLetter(
45 letter_code => 'TEST_MESSAGE',
47 biblio => $biblio_1->biblionumber,
53 t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
54 C4::Message->enqueue($letter, $patron, 'email');
55 my $message = C4::Message->find_last_message($patron->unblessed, 'TEST_MESSAGE', 'email');
56 like( $message->{metadata}, qr{heÄllo} );
57 is ($message->{to_address}, $patron->email, "To address set correctly for EmailFieldPrimary 'off'");
59 $letter = C4::Letters::GetPreparedLetter(
62 letter_code => 'TEST_MESSAGE',
64 biblio => $biblio_2->biblionumber,
68 $message->append($letter);
69 like( $message->{metadata}, qr{heÄllo} );
70 like( $message->{metadata}, qr{hell❤️} );
72 t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' );
73 C4::Message->enqueue($letter, $patron, 'email');
74 $message = C4::Message->find_last_message($patron->unblessed, 'TEST_MESSAGE', 'email');
75 is ($patron->notice_email_address, $patron->emailpro, "To address set correctly for EmailFieldPrimary 'emailpro'");