6 use Test
::More tests
=> 22;
10 use Module::Load::Conditional qw(can_load);
15 push( @INC, dirname
(__FILE__
) . '/..' );
17 use_ok
('Koha::Plugins');
18 use_ok
('Koha::Plugins::Handler');
19 use_ok
('Koha::Plugins::Base');
20 use_ok
('Koha::Plugin::Test');
23 ok
( can_load
( modules
=> { "Koha::Plugin::Test" => undef } ), 'Test can_load' );
25 my $plugin = Koha
::Plugin
::Test
->new({ enable_plugins
=> 1});
27 isa_ok
( $plugin, "Koha::Plugin::Test", 'Test plugin class' );
28 isa_ok
( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' );
30 ok
( $plugin->can('report'), 'Test plugin can report' );
31 ok
( $plugin->can('tool'), 'Test plugin can tool' );
32 ok
( $plugin->can('to_marc'), 'Test plugin can to_marc' );
33 ok
( $plugin->can('configure'), 'Test plugin can configure' );
34 ok
( $plugin->can('install'), 'Test plugin can install' );
35 ok
( $plugin->can('uninstall'), 'Test plugin can install' );
37 ok
( Koha
::Plugins
::Handler
->run({ class => "Koha::Plugin::Test", method
=> 'report', enable_plugins
=> 1 }) eq "Koha::Plugin::Test::report", 'Test run plugin report method' );
39 my $metadata = $plugin->get_metadata();
40 ok
( $metadata->{'name'} eq 'Test Plugin', 'Test $plugin->get_metadata()' );
42 ok
( $plugin->get_qualified_table_name('mytable') eq 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
43 ok
( $plugin->get_plugin_http_path() eq '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
45 my @plugins = Koha
::Plugins
->new({ enable_plugins
=> 1 })->GetPlugins( 'report' );
46 ok
( $plugins[0]->get_metadata()->{'name'} eq 'Test Plugin', "Koha::Plugins::GetPlugins functions correctly" );
49 my $plugins_dir = C4
::Context
->config("pluginsdir");
50 skip
"plugindir not set", 4 unless defined $plugins_dir;
51 skip
"plugindir not writable", 4 unless -w
$plugins_dir;
52 # no need to skip further tests if KitchenSink would already exist
54 my $ae = Archive
::Extract
->new( archive
=> "$Bin/KitchenSinkPlugin.kpz", type
=> 'zip' );
55 unless ( $ae->extract( to
=> $plugins_dir ) ) {
56 warn "ERROR: " . $ae->error;
58 use_ok
('Koha::Plugin::Com::ByWaterSolutions::KitchenSink');
59 $plugin = Koha
::Plugin
::Com
::ByWaterSolutions
::KitchenSink
->new({ enable_plugins
=> 1});
60 my $table = $plugin->get_qualified_table_name( 'mytable' );
62 ok
( -f
$plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" );
63 Koha
::Plugins
::Handler
->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink", enable_plugins
=> 1 });
64 my $sth = C4
::Context
->dbh->table_info( undef, undef, $table, 'TABLE' );
65 my $info = $sth->fetchall_arrayref;
66 is
( @
$info, 0, "Table $table does no longer exist" );
67 ok
( !( -f
$plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm" ), "Koha::Plugins::Handler::delete works correctly." );