Bug 13799: Rename t/.../v1/borrowers.t to t/.../v1/patrons.t
[koha.git] / t / Letters.t
blobad700266ba615179a9b707ebe947785fc6414b42
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 => 6;
24 use Test::DBIx::Class {
25 schema_class => 'Koha::Schema',
26 connect_info => ['dbi:SQLite:dbname=:memory:','',''],
27 connect_opts => { name_sep => '.', quote_char => '`', },
28 fixture_class => '::Populate',
29 }, 'Letter' ;
30 use t::lib::Mocks;
32 fixtures_ok [
33 Letter => [
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' ]
38 ], 'add fixtures';
40 my $db = Test::MockModule->new('Koha::Database');
41 $db->mock( _new_schema => sub { return Schema(); } );
43 use_ok('C4::Letters');
45 t::lib::Mocks::mock_preference('dateformat', 'metric');
47 my $letters = C4::Letters::GetLetters();
49 my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters;
50 is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
51 is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' );
53 # Regression test for bug 10843
54 # $dt->add takes a scalar, not undef
55 my $letter;
56 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', undef);
57 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
58 is( ref($letter), 'HASH');
59 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1);
60 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
61 is( ref($letter), 'HASH');