Bug 17501: Introduce Koha::Object[s] classes for UploadedFile(s)
[koha.git] / t / Letters.t
bloba0720448b0877157c28bee21b068c2213ba3cf45
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 Test::MockModule;
21 use Test::More;
23 use Module::Load::Conditional qw/check_install/;
25 BEGIN {
26 if ( check_install( module => 'Test::DBIx::Class' ) ) {
27 plan tests => 6;
28 } else {
29 plan skip_all => "Need Test::DBIx::Class"
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;
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' ]
47 ], 'add fixtures';
49 my $db = Test::MockModule->new('Koha::Database');
50 $db->mock( _new_schema => sub { return Schema(); } );
52 use_ok('C4::Letters');
54 t::lib::Mocks::mock_preference('dateformat', 'metric');
56 my $letters = C4::Letters::GetLetters();
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' );
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');