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

(-)a/t/Letters.t (-72 lines)
Lines 1-72 Link Here
1
#!/usr/bin/perl
2
3
# Copyright Koha development team 2007
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::MockModule;
23
use Test::More tests => 3;
24
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
27
28
use Koha::Database;
29
30
use_ok('C4::Letters', qw( GetLetters ));
31
32
my $schema  = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
our $builder = t::lib::TestBuilder->new;
35
36
subtest 'GetLetters' => sub {
37
    plan tests => 2;
38
    t::lib::Mocks::mock_preference( 'dateformat', 'metric' );
39
40
    my $data_1 = {
41
        module  => 'blah',     code => 'ISBN', branchcode => 'NBSI', name => 'book', is_html => 1, title => 'green',
42
        content => 'blahblah', lang => 'french'
43
    };
44
    my $data_2 = {
45
        module  => 'blah',   code => 'ISSN', branchcode => 'NSSI', name => 'page', is_html => 0, title => 'blue',
46
        content => 'bleble', lang => 'american'
47
    };
48
    $builder->build_object( { class => 'Koha::Notice::Templates', value => $data_1 } );
49
    $builder->build_object( { class => 'Koha::Notice::Templates', value => $data_2 } );
50
51
    my $letters = GetLetters( { module => 'blah' } );
52
    is( scalar(@$letters), 2, 'GetLetters returns the 2 inserted letters' );
53
54
    my ($ISBN_letter) = grep { $_->{code} eq 'ISBN' } @$letters;
55
    is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
56
};
57
58
subtest '_parseletter' => sub {
59
    plan tests => 2;
60
61
    # Regression test for bug 10843
62
    # $dt->add takes a scalar, not undef
63
    my $letter;
64
    t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', undef );
65
    $letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
66
    is( ref($letter), 'HASH' );
67
    t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 1 );
68
    $letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
69
    is( ref($letter), 'HASH' );
70
};
71
72
$schema->storage->txn_begin;
(-)a/t/db_dependent/Letters.t (-2 / +26 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 90;
21
use Test::More tests => 93;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
Lines 233-238 is( $letters->[0]->{module}, 'my module', 'GetLetters gets the module correctly' Link Here
233
is( $letters->[0]->{code}, 'my code', 'GetLetters gets the code correctly' );
233
is( $letters->[0]->{code}, 'my code', 'GetLetters gets the code correctly' );
234
is( $letters->[0]->{name}, 'my name', 'GetLetters gets the name correctly' );
234
is( $letters->[0]->{name}, 'my name', 'GetLetters gets the name correctly' );
235
235
236
my $data_1 = { module => 'blah', code => 'ISBN', name => 'book' };
237
my $data_2 = { module => 'blah', code => 'ISSN' };
238
$builder->build_object( { class => 'Koha::Notice::Templates', value => $data_1 } );
239
$builder->build_object( { class => 'Koha::Notice::Templates', value => $data_2 } );
240
241
$letters = GetLetters( { module => 'blah' } );
242
is( scalar(@$letters), 2, 'GetLetters returns the 2 inserted letters' );
243
244
my ($ISBN_letter) = grep { $_->{code} eq 'ISBN' } @$letters;
245
is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
246
236
# GetPreparedLetter
247
# GetPreparedLetter
237
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
248
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
238
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
249
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
Lines 630-635 is($err->{error}, 'something went wrong', "Send exception, error message returne Link Here
630
}
641
}
631
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
642
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
632
643
644
subtest '_parseletter' => sub {
645
    plan tests => 2;
646
647
    # Regression test for bug 10843
648
    # $dt->add takes a scalar, not undef
649
    my $letter;
650
    t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', undef );
651
    $letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
652
    is( ref($letter), 'HASH' );
653
    t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 1 );
654
    $letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
655
    is( ref($letter), 'HASH' );
656
};
657
633
subtest 'SendAlerts - claimissue' => sub {
658
subtest 'SendAlerts - claimissue' => sub {
634
    plan tests => 13;
659
    plan tests => 13;
635
660
636
- 

Return to bug 34825