From 73f11b699bc0ed1fd6b49362b0d75486c207a494 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 12 Feb 2018 11:15:47 -0500 Subject: [PATCH] Bug 20181: Unit tests Signed-off-by: Mark Tompsett Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit 98164dc43209af9964b84e83f2ee8f0ff7491a35) Signed-off-by: Fridolin Somers --- 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 a3969bf06d..944ca4153b 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 0000000000..8100a63d09 --- /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 8a1c26e8fd..d8999b3a0d 100755 --- a/t/db_dependent/Plugins.t +++ b/t/db_dependent/Plugins.t @@ -10,7 +10,7 @@ use File::Temp qw( tempdir tempfile ); use FindBin qw($Bin); use Module::Load::Conditional qw(can_load); use Test::MockModule; -use Test::More tests => 35; +use Test::More tests => 37; use C4::Context; use t::lib::Mocks; @@ -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('upgrade'), 'Test plugin can upgrade' ); -- 2.39.5