Bug 13799: (QA followup) make tests use random data
[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 => 6;
23
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;
31
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' ]
37     ],
38 ], 'add fixtures';
39
40 my $db = Test::MockModule->new('Koha::Database');
41 $db->mock( _new_schema => sub { return Schema(); } );
42
43 use_ok('C4::Letters');
44
45 t::lib::Mocks::mock_preference('dateformat', 'metric');
46
47 my $letters = C4::Letters::GetLetters();
48
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' );
52
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');
62
63 1;