Bug 31051: DBRev 22.12.00.005
[koha-ffzg.git] / t / Koha_Template_Plugin_Koha.t
old mode 100644 (file)
new mode 100755 (executable)
index 50c198f..a8d66fe
@@ -17,8 +17,9 @@
 
 use Modern::Perl;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 use Test::MockModule;
+use t::lib::Mocks;
 
 use String::Random;
 
@@ -26,7 +27,7 @@ use String::Random;
 use_ok( 'Koha::Template::Plugin::Koha' );
 ok( my $cache = Koha::Template::Plugin::Koha->new() );
 
-subtest "Koha::Template::Plugin::Koha::version tests" => sub {
+subtest "Koha::Template::Plugin::Koha::Version tests" => sub {
 
     plan tests => 2;
 
@@ -37,21 +38,22 @@ subtest "Koha::Template::Plugin::Koha::version tests" => sub {
     my $development;
 
     # Mock Koha::version()
-    my $koha = new Test::MockModule('Koha');
-    $koha->mock( 'Version', sub {
+    my $koha = Test::MockModule->new('Koha');
+    $koha->mock( 'version', sub {
         return "$major.$minor.$maintenance.$development";
     });
 
-    my $rnd = new String::Random;
+    my $rnd = String::Random->new;
     # development version test
     $major       = $rnd->randregex('\d');
     $minor       = $rnd->randregex('\d\d');
     $maintenance = $rnd->randregex('\d\d');
     $development = $rnd->randregex('\d\d\d');
     my $version = "$major.$minor.$maintenance.$development";
-    my $res = Koha::Template::Plugin::Koha::version( $version );
+    my $res = Koha::Template::Plugin::Koha::Version( $version );
     is_deeply( $res, {
         major       => $major,
+        minor       => $minor,
         release     => $major . "." . $minor,
         maintenance => $major . "." . $minor . "." . $maintenance,
         development => $development
@@ -64,9 +66,10 @@ subtest "Koha::Template::Plugin::Koha::version tests" => sub {
     $maintenance = $rnd->randregex('\d\d');
     $development = "000";
     $version = "$major.$minor.$maintenance.$development";
-    $res = Koha::Template::Plugin::Koha::version( $version );
+    $res = Koha::Template::Plugin::Koha::Version( $version );
     is_deeply( $res, {
         major       => $major,
+        minor       => $minor,
         release     => $major . "." . $minor,
         maintenance => $major . "." . $minor . "." . $maintenance,
         development => undef
@@ -74,4 +77,27 @@ subtest "Koha::Template::Plugin::Koha::version tests" => sub {
 
 };
 
-1;
+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");
+};