From 8a2f9ab96d111f8f7b977f8d38cc59209e1b020e Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 19 Sep 2023 06:50:52 +0000 Subject: [PATCH] Bug 34825: Remove Test::DBIx::Class from Letters.t Includes a tidy. Test plan: Run t/Letters.t Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- t/Letters.t | 76 +++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/t/Letters.t b/t/Letters.t index ceec8d776b5..4846de56a8b 100755 --- a/t/Letters.t +++ b/t/Letters.t @@ -1,5 +1,7 @@ #!/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 @@ -18,49 +20,53 @@ use Modern::Perl; use Test::MockModule; -use Test::More; +use Test::More tests => 3; -use Module::Load::Conditional qw/check_install/; +use t::lib::Mocks; +use t::lib::TestBuilder; -BEGIN { - if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 6; - } else { - plan skip_all => "Need Test::DBIx::Class" - } -} +use Koha::Database; -use Test::DBIx::Class; -use t::lib::Mocks; +use_ok('C4::Letters', qw( GetLetters )); -fixtures_ok [ - Letter => [ - [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content', 'lang' ], - [ 'blah', 'ISBN', 'NBSI', 'book', 1, 'green', 'blahblah', 'french' ], - [ 'bleh', 'ISSN', 'NSSI', 'page', 0, 'blue', 'blehbleh', 'american' ] - ], -], 'add fixtures'; +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; +our $builder = t::lib::TestBuilder->new; -my $db = Test::MockModule->new('Koha::Database'); -$db->mock( _new_schema => sub { return Schema(); } ); +subtest 'GetLetters' => sub { + plan tests => 2; + t::lib::Mocks::mock_preference( 'dateformat', 'metric' ); -use_ok('C4::Letters', qw( GetLetters )); + 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 } ); -t::lib::Mocks::mock_preference('dateformat', 'metric'); + my $letters = GetLetters( { module => 'blah' } ); + is( scalar(@$letters), 2, 'GetLetters returns the 2 inserted letters' ); -my $letters = C4::Letters::GetLetters(); + my ($ISBN_letter) = grep { $_->{code} eq 'ISBN' } @$letters; + is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' ); +}; -my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters; -is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' ); -is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' ); +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'); + # 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; -- 2.25.1