From 920b11b72e6898c9ab1895f716450551d0bd99f7 Mon Sep 17 00:00:00 2001
From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Date: Tue, 19 Sep 2023 07:09:54 +0000
Subject: [PATCH] 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>
---
t/Letters.t | 72 ----------------------------------------
t/db_dependent/Letters.t | 27 ++++++++++++++-
2 files changed, 26 insertions(+), 73 deletions(-)
delete mode 100755 t/Letters.t
diff --git a/t/Letters.t b/t/Letters.t
deleted file mode 100755
index 4846de56a8b..00000000000
--- a/t/Letters.t
+++ /dev/null
@@ -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;
diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t
index 94b5f606335..3f1a5516165 100755
--- a/t/db_dependent/Letters.t
+++ b/t/db_dependent/Letters.t
@@ -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;
--
2.25.1