Line 0
Link Here
|
|
|
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 |
|
20 |
use Test::More tests => 2; |
21 |
|
22 |
use t::lib::Mocks; |
23 |
|
24 |
use_ok('Koha::Email'); |
25 |
|
26 |
subtest 'create() tests' => sub { |
27 |
|
28 |
plan tests => 21; |
29 |
|
30 |
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', undef ); |
31 |
|
32 |
my $html_body = '<h1>Title</h1><p>Message</p>'; |
33 |
my $text_body = "#Title: Message"; |
34 |
|
35 |
my $email = Koha::Email->create( |
36 |
{ |
37 |
from => 'from@example.com', |
38 |
charset => 'iso-8859-1', |
39 |
to => 'to@example.com', |
40 |
cc => 'cc@example.com', |
41 |
bcc => 'bcc@example.com', |
42 |
replyto => 'replyto@example.com', |
43 |
sender => 'sender@example.com', |
44 |
subject => 'Some subject', |
45 |
html_body => $html_body, |
46 |
} |
47 |
); |
48 |
|
49 |
is( $email->email->header('From'), 'from@example.com', 'Value set correctly' ); |
50 |
is( $email->email->header('charset'), 'iso-8859-1', 'Value set correctly' ); |
51 |
is( $email->email->header('To'), 'to@example.com', 'Value set correctly' ); |
52 |
is( $email->email->header('Cc'), 'cc@example.com', 'Value set correctly' ); |
53 |
is( $email->email->header('Bcc'), 'bcc@example.com', 'Value set correctly' ); |
54 |
is( $email->email->header('ReplyTo'), 'replyto@example.com', 'Value set correctly' ); |
55 |
is( $email->email->header('Sender'), 'sender@example.com', 'Value set correctly' ); |
56 |
is( $email->email->header('Subject'), 'Some subject', 'Value set correctly' ); |
57 |
is( $email->email->header('X-Mailer'), 'Koha', 'Value set correctly' ); |
58 |
is( $email->email->body, $html_body, "Body set correctly" ); |
59 |
is( $email->email->content_type, 'text/html; charset="utf-8"', "Content type set correctly"); |
60 |
like( $email->email->header('Message-ID'), qr/\<.*@.*\>/, 'Value set correctly' ); |
61 |
|
62 |
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', 'catchall@example.com' ); |
63 |
t::lib::Mocks::mock_preference( 'ReplytoDefault', 'replytodefault@example.com' ); |
64 |
t::lib::Mocks::mock_preference( 'ReturnpathDefault', 'returnpathdefault@example.com' ); |
65 |
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'kohaadminemailaddress@example.com' ); |
66 |
|
67 |
$email = Koha::Email->create( |
68 |
{ |
69 |
to => 'to@example.com', |
70 |
cc => 'cc@example.com', |
71 |
bcc => 'bcc@example.com', |
72 |
text_body => $text_body, |
73 |
} |
74 |
); |
75 |
|
76 |
is( $email->email->header('From'), 'kohaadminemailaddress@example.com', 'KohaAdminEmailAddress is picked when no from passed' ); |
77 |
is( $email->email->header('charset'), 'utf8', 'utf8 is the default' ); |
78 |
is( $email->email->header('To'), 'catchall@example.com', 'SendAllEmailsTo overloads any address' ); |
79 |
is( $email->email->header('Cc'), undef, 'SendAllEmailsTo overloads any address' ); |
80 |
is( $email->email->header('Bcc'), undef, 'SendAllEmailsTo overloads any address' ); |
81 |
is( $email->email->header('ReplyTo'), 'replytodefault@example.com', 'ReplytoDefault picked when replyto not passed' ); |
82 |
is( $email->email->header('Sender'), 'returnpathdefault@example.com', 'ReturnpathDefault picked when sender not passed' ); |
83 |
is( $email->email->body, $text_body, "Body set correctly" ); |
84 |
is( $email->email->content_type, 'text/plain; charset="utf-8"; format="flowed"', "Content type set correctly"); |
85 |
}; |