From 8029c883debbcfe9e5048c6f81cbb8cf586f9365 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Wed, 12 May 2021 12:37:14 +0200 Subject: [PATCH] Bug 28327: Add unit tests for Koha::Template::Plugin::Koha::CSVDelimiter Run prove t/Koha_Template_Plugin_Koha.t --- t/Koha_Template_Plugin_Koha.t | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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.30.2