From 22fa650217d5c2aca57b233ac1c850170b0e0e59 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatetsolutions.com>
Date: Mon, 12 Feb 2018 11:15:47 -0500
Subject: [PATCH] Bug 20181 - Unit Tests

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
---
 t/Koha/Plugin/Test.pm                | 10 +++++++++
 t/Koha_Template_Plugin_KohaPlugins.t | 41 ++++++++++++++++++++++++++++++++++++
 t/db_dependent/Plugins.t             |  4 +++-
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100755 t/Koha_Template_Plugin_KohaPlugins.t

diff --git a/t/Koha/Plugin/Test.pm b/t/Koha/Plugin/Test.pm
index 636554d..9244714 100644
--- a/t/Koha/Plugin/Test.pm
+++ b/t/Koha/Plugin/Test.pm
@@ -58,6 +58,16 @@ sub opac_online_payment_end {
     return "Koha::Plugin::Test::opac_online_payment_end";
 }
 
+sub opac_head {
+    my ( $self, $args ) = @_;
+    return "Koha::Plugin::Test::opac_head";
+}
+
+sub opac_js {
+    my ( $self, $args ) = @_;
+    return "Koha::Plugin::Test::opac_js";
+}
+
 sub configure {
     my ( $self, $args ) = @_;
     return "Koha::Plugin::Test::configure";;
diff --git a/t/Koha_Template_Plugin_KohaPlugins.t b/t/Koha_Template_Plugin_KohaPlugins.t
new file mode 100755
index 0000000..8100a63
--- /dev/null
+++ b/t/Koha_Template_Plugin_KohaPlugins.t
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use Modern::Perl;
+
+use Test::More tests => 8;
+use CGI;
+use File::Basename;
+use File::Spec;
+use File::Temp qw( tempdir tempfile );
+use FindBin qw($Bin);
+use Archive::Extract;
+use Module::Load::Conditional qw(can_load);
+use Test::MockModule;
+
+use C4::Context;
+use t::lib::Mocks;
+
+BEGIN {
+    push( @INC, dirname(__FILE__) );
+
+    use_ok('Koha::Plugins');
+    use_ok('Koha::Plugins::Handler');
+    use_ok('Koha::Plugins::Base');
+    use_ok('Koha::Plugin::Test');
+}
+
+my $mock_plugin = Test::MockModule->new( 'Koha::Plugin::Test' );
+$mock_plugin->mock( 'test_template', sub {
+    my ( $self, $file ) = @_;
+    my $template = $self->get_template({ file => $file });
+    $template->param( filename => $file );
+    return $template->output;
+});
+
+use_ok( 'Koha::Template::Plugin::KohaPlugins', 'Can use Koha::Template::Plugin::KohaPlugins' );
+
+ok( my $plugin = Koha::Template::Plugin::KohaPlugins->new(), 'Able to instantiate template plugin' );
+
+ok( index( $plugin->get_plugins_opac_js, 'Koha::Plugin::Test::opac_js' ) != -1, 'Test plugin opac_js return value is part of code returned by get_plugins_opac_js' );
+
+ok( index( $plugin->get_plugins_opac_head, 'Koha::Plugin::Test::opac_head' ) != -1, 'Test plugin opac_head return value is part of code returned by get_plugins_opac_head' );
diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t
index 4fa327f..107742d 100755
--- a/t/db_dependent/Plugins.t
+++ b/t/db_dependent/Plugins.t
@@ -2,7 +2,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 32;
+use Test::More tests => 34;
 use CGI;
 use File::Basename;
 use File::Spec;
@@ -45,6 +45,8 @@ ok( $plugin->can('to_marc'), 'Test plugin can to_marc' );
 ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' );
 ok( $plugin->can('opac_online_payment_begin'), 'Test plugin can opac_online_payment_begin' );
 ok( $plugin->can('opac_online_payment_end'), 'Test plugin can opac_online_payment_end' );
+ok( $plugin->can('opac_head'), 'Test plugin can opac_head' );
+ok( $plugin->can('opac_js'), 'Test plugin can opac_js' );
 ok( $plugin->can('configure'), 'Test plugin can configure' );
 ok( $plugin->can('install'), 'Test plugin can install' );
 ok( $plugin->can('uninstall'), 'Test plugin can install' );
-- 
2.1.4