Bug 11714: A fund is a top-level fund if it does not have any parent
[koha.git] / t / Letters.t
blob18ae12970eb89fcd5763c3eae64e80c27916c639
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
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;
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' ]
39 use_ok('C4::Letters');
41 my $dbh = C4::Context->dbh();
43 $dbh->{mock_add_resultset} = $mock_letters;
45 my $letters = C4::Letters::GetLetters();
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' );
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');