Bug 17600: Standardize our EXPORT_OK
[koha.git] / t / Letters.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
20 use Test::MockModule;
21 use Test::More;
22
23 use Module::Load::Conditional qw/check_install/;
24
25 BEGIN {
26     if ( check_install( module => 'Test::DBIx::Class' ) ) {
27         plan tests => 6;
28     } else {
29         plan skip_all => "Need Test::DBIx::Class"
30     }
31 }
32
33 use Test::DBIx::Class;
34 use t::lib::Mocks;
35
36 fixtures_ok [
37     Letter => [
38         [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content', 'lang' ],
39         [ 'blah',   'ISBN', 'NBSI',       'book', 1,         'green', 'blahblah', 'french' ],
40         [ 'bleh',   'ISSN', 'NSSI',       'page', 0,         'blue',  'blehbleh', 'american' ]
41     ],
42 ], 'add fixtures';
43
44 my $db = Test::MockModule->new('Koha::Database');
45 $db->mock( _new_schema => sub { return Schema(); } );
46
47 use_ok('C4::Letters', qw( GetLetters ));
48
49 t::lib::Mocks::mock_preference('dateformat', 'metric');
50
51 my $letters = C4::Letters::GetLetters();
52
53 my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters;
54 is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
55 is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' );
56
57 # Regression test for bug 10843
58 # $dt->add takes a scalar, not undef
59 my $letter;
60 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', undef);
61 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
62 is( ref($letter), 'HASH');
63 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1);
64 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
65 is( ref($letter), 'HASH');
66