From 8b096eda6166c27feed1f33a7c7d0f8e5d1bc160 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy 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 Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 5fd831755205fc3b3b7481103fbe2145b421a5ea) Signed-off-by: Fridolin Somers (cherry picked from commit f938f90795d5c57e59d4fc38de5b8fd0991f354f) Signed-off-by: Matt Blenkinsop --- 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 4846de56a8..0000000000 --- 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 . - -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 3113aeafef..4c01696286 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 86; +use Test::More tests => 89; use Test::MockModule; use Test::Warn; use Test::Exception; @@ -212,6 +212,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', '' ); @@ -609,6 +620,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.39.5