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

(-)a/C4/Letters.pm (+2 lines)
Lines 712-717 sub GetPreparedLetter { Link Here
712
712
713
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
713
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
714
714
715
    Koha::Plugins->call( 'transform_prepared_letter', { letter => $letter, params => \%params } );
716
715
    return $letter;
717
    return $letter;
716
}
718
}
717
719
(-)a/t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t (+110 lines)
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::More tests => 4;
20
use Test::MockModule;
21
use Test::Warn;
22
23
use File::Basename;
24
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
27
28
use Koha::DateUtils qw( dt_from_string output_pref );
29
use C4::Letters qw( GetPreparedLetter );
30
31
BEGIN {
32
    # Mock pluginsdir before loading Plugins module
33
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
34
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
35
36
    use_ok('Koha::Plugins');
37
    use_ok('Koha::Plugins::Handler');
38
    use_ok('Koha::Plugin::Test');
39
}
40
41
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
42
43
my $schema = Koha::Database->schema;
44
45
my $builder = t::lib::TestBuilder->new();
46
47
my $dbh = C4::Context->dbh;
48
49
subtest 'Test transform_prepared_letter' => sub {
50
    plan tests => 4;
51
52
    $schema->storage->txn_begin();
53
54
    $dbh->do(q|DELETE FROM letter|);
55
56
    my $now_value       = dt_from_string();
57
    my $mocked_datetime = Test::MockModule->new('DateTime');
58
    $mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
59
60
    my $library = $builder->build( { source => 'Branch' } );
61
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
62
63
    my $plugins = Koha::Plugins->new;
64
65
    warning_is { $plugins->InstallPlugins; } undef;
66
67
    my $prepared_letter;
68
69
    my $sth = $dbh->prepare(
70
        q{
71
        INSERT INTO letter (module, code, name, title, content)
72
        VALUES ('test',?,'Test',?,?)}
73
    );
74
75
    $sth->execute(
76
        "TEST_PATRON",
77
        "[% borrower.firstname %]",
78
        "[% borrower.id %]"
79
    );
80
81
    warning_like {
82
        $prepared_letter = GetPreparedLetter(
83
            (
84
                module      => 'test',
85
                letter_code => 'TEST_PATRON',
86
                tables      => {
87
                    borrowers => $patron->borrowernumber,
88
                },
89
            )
90
        )
91
92
    }
93
    qr/transform_prepared_letter called with letter content/,
94
        'GetPreparedLetter calls the transform_prepared_letter hook';
95
96
    is(
97
        $prepared_letter->{content},
98
        $patron->borrowernumber . "\nThank you for using your local library!",
99
        'Patron object used correctly with scalar for content'
100
    );
101
    is(
102
        $prepared_letter->{title},
103
        $patron->firstname . "!",
104
        'Patron object used correctly with scalar for title'
105
    );
106
107
    $schema->storage->txn_rollback;
108
    Koha::Plugins::Methods->delete;
109
110
};
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +9 lines)
Lines 377-382 sub template_include_paths { Link Here
377
    ];
377
    ];
378
}
378
}
379
379
380
sub transform_prepared_letter {
381
    my ( $self, $params ) = @_;
382
383
    $params->{letter}->{title}   .= '!';
384
    $params->{letter}->{content} .= "\nThank you for using your local library!";
385
386
    Koha::Exception->throw("transform_prepared_letter called with letter content $params->{letter}->{content}");
387
}
388
380
sub _private_sub {
389
sub _private_sub {
381
    return "";
390
    return "";
382
}
391
}
383
- 

Return to bug 35568