Bug 26076: (QA Follow up) Prevent error by using a fresh resultset
[koha.git] / t / Letters.t
blob35a4b74a2a510566a943ad8f5bf543682d42096a
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 use t::lib::Mocks;
36 fixtures_ok [
37 Letter => [
38 [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content', 'lang' ],
39 [ 'blah', 'ISBN', 'NBSI', 'book', 1, 'green', 'blahblah', 'french' ],
40 [ 'bleh', 'ISSN', 'NSSI', 'page', 0, 'blue', 'blehbleh', 'american' ]
42 ], 'add fixtures';
44 my $db = Test::MockModule->new('Koha::Database');
45 $db->mock( _new_schema => sub { return Schema(); } );
47 use_ok('C4::Letters');
49 t::lib::Mocks::mock_preference('dateformat', 'metric');
51 my $letters = C4::Letters::GetLetters();
53 my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters;
54 is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
55 is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' );
57 # Regression test for bug 10843
58 # $dt->add takes a scalar, not undef
59 my $letter;
60 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', undef);
61 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
62 is( ref($letter), 'HASH');
63 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1);
64 $letter = C4::Letters::_parseletter( undef, 'reserves', {waitingdate => "2013-01-01"} );
65 is( ref($letter), 'HASH');