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 under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
|
17 |
use Modern::Perl; |
18 |
|
19 |
use Test::NoWarnings; |
20 |
use Test::More tests => 5; |
21 |
use Test::Warn; |
22 |
|
23 |
use File::Basename; |
24 |
|
25 |
use t::lib::Mocks; |
26 |
use t::lib::TestBuilder; |
27 |
|
28 |
use C4::Letters qw( GetPreparedLetter ); |
29 |
|
30 |
BEGIN { |
31 |
# Mock pluginsdir before loading Plugins module |
32 |
my $path = dirname(__FILE__) . '/../../../lib/plugins'; |
33 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
34 |
|
35 |
use_ok('Koha::Plugins'); |
36 |
use_ok('Koha::Plugins::Handler'); |
37 |
use_ok('Koha::Plugin::Test'); |
38 |
} |
39 |
|
40 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
41 |
|
42 |
my $schema = Koha::Database->schema; |
43 |
my $builder = t::lib::TestBuilder->new(); |
44 |
|
45 |
subtest 'notices_content() tests' => sub { |
46 |
|
47 |
plan tests => 4; |
48 |
|
49 |
$schema->storage->txn_begin(); |
50 |
|
51 |
my $dbh = C4::Context->dbh; |
52 |
|
53 |
# just to be sure |
54 |
$dbh->do(q|DELETE FROM letter WHERE module='test'|); |
55 |
|
56 |
my $plugins = Koha::Plugins->new; |
57 |
warning_is { $plugins->InstallPlugins; } undef; |
58 |
|
59 |
my $prepared_letter; |
60 |
|
61 |
my $sth = $dbh->prepare( |
62 |
q{ |
63 |
INSERT INTO letter (module, code, name, title, content) |
64 |
VALUES ('test',?,'Test',?,?)} |
65 |
); |
66 |
|
67 |
$sth->execute( |
68 |
"TEST_HOLD", |
69 |
"[% hold.id %]", |
70 |
"[% plugin_content.test.custom_attribute.message %]. " |
71 |
. "We identified this is the '[% plugin_content.test.custom_attribute.module %]' module" |
72 |
); |
73 |
|
74 |
my $hold = $builder->build_object( { class => 'Koha::Holds' } ); |
75 |
warning_like { |
76 |
$prepared_letter = GetPreparedLetter( |
77 |
( |
78 |
module => 'test', |
79 |
letter_code => 'TEST_HOLD', |
80 |
tables => { |
81 |
reserves => $hold->unblessed, |
82 |
} |
83 |
) |
84 |
) |
85 |
} |
86 |
qr/transform_prepared_letter called with letter content/, |
87 |
'GetPreparedLetter calls the transform_prepared_letter hook'; |
88 |
|
89 |
is( |
90 |
$prepared_letter->{content}, |
91 |
"notices_content() called. We identified this is the 'test' module" |
92 |
. "\nThank you for using your local library!", |
93 |
'Patron object used correctly with scalar for content' |
94 |
); |
95 |
is( |
96 |
$prepared_letter->{title}, |
97 |
$hold->id . "!", |
98 |
'Hold object used correctly with scalar for title' |
99 |
); |
100 |
|
101 |
$schema->storage->txn_rollback; |
102 |
Koha::Plugins::Methods->delete; |
103 |
|
104 |
}; |