Bug 34825: Merge Letters.t into t/db/Letters.t

Test plan:
Run t/db_dependent/Letters.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2023-09-19 07:09:54 +00:00 committed by Tomas Cohen Arazi
parent 22aee4db67
commit 5fd8317552
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 26 additions and 73 deletions

View File

@ -1,72 +0,0 @@
#!/usr/bin/perl
# Copyright Koha development team 2007
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::MockModule;
use Test::More tests => 3;
use t::lib::Mocks;
use t::lib::TestBuilder;
use Koha::Database;
use_ok('C4::Letters', qw( GetLetters ));
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
our $builder = t::lib::TestBuilder->new;
subtest 'GetLetters' => sub {
plan tests => 2;
t::lib::Mocks::mock_preference( 'dateformat', 'metric' );
my $data_1 = {
module => 'blah', code => 'ISBN', branchcode => 'NBSI', name => 'book', is_html => 1, title => 'green',
content => 'blahblah', lang => 'french'
};
my $data_2 = {
module => 'blah', code => 'ISSN', branchcode => 'NSSI', name => 'page', is_html => 0, title => 'blue',
content => 'bleble', lang => 'american'
};
$builder->build_object( { class => 'Koha::Notice::Templates', value => $data_1 } );
$builder->build_object( { class => 'Koha::Notice::Templates', value => $data_2 } );
my $letters = GetLetters( { module => 'blah' } );
is( scalar(@$letters), 2, 'GetLetters returns the 2 inserted letters' );
my ($ISBN_letter) = grep { $_->{code} eq 'ISBN' } @$letters;
is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
};
subtest '_parseletter' => sub {
plan tests => 2;
# Regression test for bug 10843
# $dt->add takes a scalar, not undef
my $letter;
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', undef );
$letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
is( ref($letter), 'HASH' );
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 1 );
$letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
is( ref($letter), 'HASH' );
};
$schema->storage->txn_begin;

View File

@ -18,7 +18,7 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 90;
use Test::More tests => 93;
use Test::MockModule;
use Test::Warn;
use Test::Exception;
@ -233,6 +233,17 @@ is( $letters->[0]->{module}, 'my module', 'GetLetters gets the module correctly'
is( $letters->[0]->{code}, 'my code', 'GetLetters gets the code correctly' );
is( $letters->[0]->{name}, 'my name', 'GetLetters gets the name correctly' );
my $data_1 = { module => 'blah', code => 'ISBN', name => 'book' };
my $data_2 = { module => 'blah', code => 'ISSN' };
$builder->build_object( { class => 'Koha::Notice::Templates', value => $data_1 } );
$builder->build_object( { class => 'Koha::Notice::Templates', value => $data_2 } );
$letters = GetLetters( { module => 'blah' } );
is( scalar(@$letters), 2, 'GetLetters returns the 2 inserted letters' );
my ($ISBN_letter) = grep { $_->{code} eq 'ISBN' } @$letters;
is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
# GetPreparedLetter
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
@ -630,6 +641,20 @@ is($err->{error}, 'something went wrong', "Send exception, error message returne
}
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
subtest '_parseletter' => sub {
plan tests => 2;
# Regression test for bug 10843
# $dt->add takes a scalar, not undef
my $letter;
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', undef );
$letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
is( ref($letter), 'HASH' );
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 1 );
$letter = C4::Letters::_parseletter( undef, 'reserves', { waitingdate => "2013-01-01" } );
is( ref($letter), 'HASH' );
};
subtest 'SendAlerts - claimissue' => sub {
plan tests => 13;