Update release notes for 22.05.22 release
[koha.git] / t / db_dependent / Message.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19 use Test::More tests => 5;
20
21 use utf8;
22
23 use t::lib::TestBuilder;
24 use t::lib::Mocks;
25
26 use C4::Letters qw( GetPreparedLetter );
27 use Koha::Database;
28
29 my $schema = Koha::Database->schema;
30 $schema->storage->txn_begin();
31
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 %]', "
35 ----
36 <<biblio.title>>
37 ----
38 ")});
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(
43     (
44         module      => 'test',
45         letter_code => 'TEST_MESSAGE',
46         tables      => {
47             biblio => $biblio_1->biblionumber,
48         },
49     )
50 );
51
52
53 t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', '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 AutoEmailPrimaryAddress 'off'");
58
59 $letter = C4::Letters::GetPreparedLetter(
60     (
61         module      => 'test',
62         letter_code => 'TEST_MESSAGE',
63         tables      => {
64             biblio => $biblio_2->biblionumber,
65         },
66     )
67 );
68 $message->append($letter);
69 like( $message->{metadata}, qr{heÄllo} );
70 like( $message->{metadata}, qr{hell❤️} );
71
72 t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', '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 AutoEmailPrimaryAddress 'emailpro'");