Bug 15150: Make t/ tests skip if Test::DBIx::Class absent
[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     schema_class => 'Koha::Schema',
35     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
36     connect_opts => { name_sep => '.', quote_char => '`', },
37     fixture_class => '::Populate',
38 }, 'Letter' ;
39 use t::lib::Mocks;
40
41 fixtures_ok [
42     Letter => [
43         [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content' ],
44         [ 'blah',   'ISBN', 'NBSI',       'book', 1,         'green', 'blahblah' ],
45         [ 'bleh',   'ISSN', 'NSSI',       'page', 0,         'blue',  'blehbleh' ]
46     ],
47 ], 'add fixtures';
48
49 my $db = Test::MockModule->new('Koha::Database');
50 $db->mock( _new_schema => sub { return Schema(); } );
51
52 use_ok('C4::Letters');
53
54 t::lib::Mocks::mock_preference('dateformat', 'metric');
55
56 my $letters = C4::Letters::GetLetters();
57
58 my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters;
59 is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
60 is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' );
61
62 # Regression test for bug 10843
63 # $dt->add takes a scalar, not undef
64 my $letter;
65 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', undef);
66 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
67 is( ref($letter), 'HASH');
68 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1);
69 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
70 is( ref($letter), 'HASH');
71
72 1;