From dbafbb43d974315c27f7c3931ec6b8ed7c7b1dfb Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Mon, 21 Mar 2022 21:48:50 -1000 Subject: [PATCH] Bug 28327: Add unit tests --- t/Context.t | 19 ++++++++++++++++++- t/Koha_Template_Plugin_Koha.t | 27 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/t/Context.t b/t/Context.t index 156ae778bb..8d353e35f6 100755 --- a/t/Context.t +++ b/t/Context.t @@ -18,7 +18,7 @@ use Modern::Perl; use DBI; -use Test::More tests => 31; +use Test::More tests => 32; use Test::MockModule; use Test::Warn; use YAML::XS; @@ -63,6 +63,23 @@ subtest 'needs_install() tests' => sub { is( C4::Context->needs_install, 1, "->preference(Version) is not defined, need to install" ); }; +subtest 'csv_delimiter() tests' => sub { + + plan tests => 4; + + t::lib::Mocks::mock_preference( 'CSVDelimiter', undef ); + is( C4::Context->csv_delimiter, ';', "csv_delimiter returns semicolon if system preference CSVDelimiter is undefined" ); + + t::lib::Mocks::mock_preference( 'CSVDelimiter', '' ); + is( C4::Context->csv_delimiter, ';', "csv_delimiter returns semicolon if system preference CSVDelimiter is empty string" ); + + t::lib::Mocks::mock_preference( 'CSVDelimiter', ',' ); + is( C4::Context->csv_delimiter, ',', "csv_delimiter returns comma if system preference CSVDelimiter is comma" ); + + t::lib::Mocks::mock_preference( 'CSVDelimiter', 'tabulation' ); + is( C4::Context->csv_delimiter, "\t", "csv_delimiter returns '\t' if system preference CSVDelimiter is tabulation" ); +}; + my $context = Test::MockModule->new('C4::Context'); my $userenv = {}; diff --git a/t/Koha_Template_Plugin_Koha.t b/t/Koha_Template_Plugin_Koha.t index 13079a9753..812f5f96cc 100755 --- a/t/Koha_Template_Plugin_Koha.t +++ b/t/Koha_Template_Plugin_Koha.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::MockModule; use t::lib::Mocks; @@ -88,3 +88,28 @@ subtest "Koha::Template::Plugin::Koha::ArePluginsEnabled tests" => sub { is(Koha::Template::Plugin::Koha::ArePluginsEnabled(), 0, "Correct ArePluginsEnabled is no"); }; + +subtest "Koha::Template::Plugin::Koha::CSVDelimiter tests" => sub { + + plan tests => 8; + + my $plugin = Koha::Template::Plugin::Koha->new(); + + t::lib::Mocks::mock_preference('CSVDelimiter', ''); + is($plugin->CSVDelimiter(), ',', "CSVDelimiter() returns comma when preference is empty string"); + + t::lib::Mocks::mock_preference('CSVDelimiter', undef); + is($plugin->CSVDelimiter(), ',', "CSVDelimiter() returns comma when preference is undefined"); + + t::lib::Mocks::mock_preference('CSVDelimiter', ';'); + is($plugin->CSVDelimiter(), ';', "CSVDelimiter() returns preference value when preference is not tabulation"); + + t::lib::Mocks::mock_preference('CSVDelimiter', 'tabulation'); + is($plugin->CSVDelimiter(), "\t", "CSVDelimiter() returns \\t when preference is tabulation"); + + t::lib::Mocks::mock_preference('CSVDelimiter', '#'); + is($plugin->CSVDelimiter(undef), '#', "CSVDelimiter(arg) returns preference value when arg is undefined"); + is($plugin->CSVDelimiter(''), '#', "CSVDelimiter(arg) returns preference value when arg is empty string"); + is($plugin->CSVDelimiter(','), ',', "CSVDelimiter(arg) returns arg value when arg is not tabulation"); + is($plugin->CSVDelimiter('tabulation'), "\t", "CSVDelimiter(arg) returns \\t value when arg is tabulation"); +}; -- 2.35.1