From b0ea497106a22227eca4069a8483feccc060f3f5 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 19 Aug 2021 11:42:36 +0000 Subject: [PATCH] Bug 27461: Add tests for biblio_008 Test plan: Run t/db_dependent/FrameworkPlugin.t Signed-off-by: Marcel de Rooy Signed-off-by: Phil Ringnalda Signed-off-by: Martin Renvoize --- t/db_dependent/FrameworkPlugin.t | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/FrameworkPlugin.t b/t/db_dependent/FrameworkPlugin.t index f05c8105faa..81afb48fe86 100755 --- a/t/db_dependent/FrameworkPlugin.t +++ b/t/db_dependent/FrameworkPlugin.t @@ -4,14 +4,16 @@ use CGI; use File::Temp qw/tempfile/; use Getopt::Long; use Test::MockModule; -use Test::More tests => 5; +use Test::More tests => 6; +use t::lib::Mocks; use t::lib::TestBuilder; use C4::Auth qw( checkauth ); use C4::Output qw( output_html_with_http_headers ); use Koha::Database; use Koha::FrameworkPlugin; +use Koha::Util::FrameworkPlugin qw( biblio_008 ); our @includes; GetOptions( 'include=s{,}' => \@includes ); #not used by default ! @@ -39,6 +41,23 @@ subtest 'Test04 -- tests with new style plugin' => sub { subtest 'Test05 -- tests with build and launch for default plugins' => sub { test05( \@includes ); }; + +subtest 'Test06 -- test biblio_008' => sub { + plan tests => 5; + t::lib::Mocks::mock_preference('DefaultCountryField008', 'nl' ); # deliberately shorter than 3 pos + t::lib::Mocks::mock_preference('DefaultLanguageField008', 'dutch' ); # deliberately too long + my $field = biblio_008(); + is( length($field), 40, 'Check length' ); + is( substr($field, 15, 3), 'nl ', 'Check country right padded' ); + is( substr($field, 35, 3), 'dut', 'Check language' ); + t::lib::Mocks::mock_preference('DefaultCountryField008', '' ); + $field = biblio_008(); + is( substr($field, 15, 3), '|||', 'Check country fallback for empty string' ); + t::lib::Mocks::mock_preference('DefaultCountryField008', undef ); + $field = biblio_008(); + is( substr($field, 15, 3), '|||', 'Check country fallback for undefined' ); +}; + $schema->storage->txn_rollback; sub test01 { -- 2.20.1