Bug 12470: (followup) License statement missing
[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 DBI;
21 use Test::MockModule;
22 use Test::More tests => 5;
23 use t::lib::Mocks;
24 my $module = new Test::MockModule('C4::Context');
25 $module->mock(
26     '_new_dbh',
27     sub {
28         my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
29           || die "Cannot create handle: $DBI::errstr\n";
30         return $dbh;
31     }
32 );
33 my $mock_letters = [
34     [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content' ],
35     [ 'blah',   'ISBN', 'NBSI',       'book', 1,         'green', 'blahblah' ],
36     [ 'bleh',   'ISSN', 'NSSI',       'page', 0,         'blue',  'blehbleh' ]
37 ];
38
39 use_ok('C4::Letters');
40
41 my $dbh = C4::Context->dbh();
42
43 $dbh->{mock_add_resultset} = $mock_letters;
44
45 my $letters = C4::Letters::GetLetters();
46
47 my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters;
48 is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
49 is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' );
50
51 # Regression test for bug 10843
52 # $dt->add takes a scalar, not undef
53 my $letter;
54 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', undef);
55 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
56 is( ref($letter), 'HASH');
57 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1);
58 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
59 is( ref($letter), 'HASH');
60
61 1;