Bug 11876 [Unit test] Add a diff view to staged MARC Records
[koha.git] / t / db_dependent / Plugins.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 20;
7 use File::Basename;
8 use FindBin qw($Bin);
9 use Archive::Extract;
10 use Module::Load::Conditional qw(can_load);
11
12 use C4::Context;
13
14 BEGIN {
15     push( @INC, dirname(__FILE__) . '/..' );
16
17     use_ok('Koha::Plugins');
18     use_ok('Koha::Plugins::Handler');
19     use_ok('Koha::Plugins::Base');
20     use_ok('Koha::Plugin::Test');
21 }
22
23 ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' );
24
25 my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1});
26
27 isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' );
28 isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' );
29
30 ok( $plugin->can('report'), 'Test plugin can report' );
31 ok( $plugin->can('tool'), 'Test plugin can tool' );
32 ok( $plugin->can('configure'), 'Test plugin can configure' );
33 ok( $plugin->can('install'), 'Test plugin can install' );
34 ok( $plugin->can('uninstall'), 'Test plugin can install' );
35
36 ok( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }) eq "Koha::Plugin::Test::report", 'Test run plugin report method' );
37
38 my $metadata = $plugin->get_metadata();
39 ok( $metadata->{'name'} eq 'Test Plugin', 'Test $plugin->get_metadata()' );
40
41 ok( $plugin->get_qualified_table_name('mytable') eq 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
42 ok( $plugin->get_plugin_http_path() eq '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
43
44 my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins( 'report' );
45 ok( $plugins[0]->get_metadata()->{'name'} eq 'Test Plugin', "Koha::Plugins::GetPlugins functions correctly" );
46
47 SKIP: {
48     my $plugins_dir = C4::Context->config("pluginsdir");
49     skip "plugindir not set", 3 unless defined $plugins_dir;
50     skip "plugindir not writable", 3 unless -w $plugins_dir;
51     skip "KitchenSink plugin already installed", 3 if (-f "$plugins_dir/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm");
52
53     my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' );
54     unless ( $ae->extract( to => $plugins_dir ) ) {
55         warn "ERROR: " . $ae->error;
56     }
57     use_ok('Koha::Plugin::Com::ByWaterSolutions::KitchenSink');
58     $plugin = Koha::Plugin::Com::ByWaterSolutions::KitchenSink->new({ enable_plugins => 1});
59
60     ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" );
61     Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink" });
62     ok( !( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm" ), "Koha::Plugins::Handler::delete works correctly." );
63 }
64