5 use Test
::More tests
=> 28;
7 use File
::Temp
qw( tempdir );
10 use Module::Load::Conditional qw(can_load);
16 push( @INC, dirname
(__FILE__
) . '/..' );
18 use_ok
('Koha::Plugins');
19 use_ok
('Koha::Plugins::Handler');
20 use_ok
('Koha::Plugins::Base');
21 use_ok
('Koha::Plugin::Test');
24 ok
( can_load
( modules
=> { "Koha::Plugin::Test" => undef } ), 'Test can_load' );
26 my $plugin = Koha
::Plugin
::Test
->new({ enable_plugins
=> 1});
28 isa_ok
( $plugin, "Koha::Plugin::Test", 'Test plugin class' );
29 isa_ok
( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' );
31 ok
( $plugin->can('report'), 'Test plugin can report' );
32 ok
( $plugin->can('tool'), 'Test plugin can tool' );
33 ok
( $plugin->can('to_marc'), 'Test plugin can to_marc' );
34 ok
( $plugin->can('configure'), 'Test plugin can configure' );
35 ok
( $plugin->can('install'), 'Test plugin can install' );
36 ok
( $plugin->can('uninstall'), 'Test plugin can install' );
38 is
( Koha
::Plugins
::Handler
->run({ class => "Koha::Plugin::Test", method
=> 'report', enable_plugins
=> 1 }), "Koha::Plugin::Test::report", 'Test run plugin report method' );
40 my $metadata = $plugin->get_metadata();
41 is
( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' );
43 is
( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
44 is
( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
47 my @plugins = Koha
::Plugins
->new({ enable_plugins
=> 1 })->GetPlugins({
50 my @names = map { $_->get_metadata()->{'name'} } @plugins;
51 is
( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" );
52 @plugins = Koha
::Plugins
->new({ enable_plugins
=> 1 })->GetPlugins({
53 metadata
=> { my_example_tag
=> 'find_me' },
55 @names = map { $_->get_metadata()->{'name'} } @plugins;
56 is
( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" );
57 # Test two metadata conditions; one does not exist for Test.pm
58 # Since it is a required key, we should not find the same results
59 my @plugins2 = Koha
::Plugins
->new({ enable_plugins
=> 1 })->GetPlugins({
60 metadata
=> { my_example_tag
=> 'find_me', not_there
=> '1' },
62 isnt
( scalar @plugins2, scalar @plugins, 'GetPlugins with two metadata conditions' );
64 for my $pass ( 1 .. 2 ) {
66 my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink';
67 my $pm_path = 'Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm';
69 my $plugins_dir1 = tempdir
( CLEANUP
=> 1 );
70 t
::lib
::Mocks
::mock_config
('pluginsdir', $plugins_dir1);
71 $plugins_dir = $plugins_dir1;
72 push @INC, $plugins_dir1;
74 my $plugins_dir1 = tempdir
( CLEANUP
=> 1 );
75 my $plugins_dir2 = tempdir
( CLEANUP
=> 1 );
76 t
::lib
::Mocks
::mock_config
('pluginsdir', [ $plugins_dir2, $plugins_dir1 ]);
77 $plugins_dir = $plugins_dir2;
79 push @INC, $plugins_dir2;
80 push @INC, $plugins_dir1;
82 my $full_pm_path = $plugins_dir . '/' . $pm_path;
84 my $ae = Archive
::Extract
->new( archive
=> "$Bin/KitchenSinkPlugin.kpz", type
=> 'zip' );
85 unless ( $ae->extract( to
=> $plugins_dir ) ) {
86 warn "ERROR: " . $ae->error;
88 use_ok
('Koha::Plugin::Com::ByWaterSolutions::KitchenSink');
89 $plugin = Koha
::Plugin
::Com
::ByWaterSolutions
::KitchenSink
->new({ enable_plugins
=> 1});
90 my $table = $plugin->get_qualified_table_name( 'mytable' );
92 ok
( -f
$plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" );
93 $INC{$pm_path} = $full_pm_path; # FIXME I do not really know why, but if this is moved before the $plugin constructor, it will fail with Can't locate object method "new" via package "Koha::Plugin::Com::ByWaterSolutions::KitchenSink"
94 Koha
::Plugins
::Handler
->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink", enable_plugins
=> 1 });
95 my $sth = C4
::Context
->dbh->table_info( undef, undef, $table, 'TABLE' );
96 my $info = $sth->fetchall_arrayref;
97 is
( @
$info, 0, "Table $table does no longer exist" );
98 ok
( !( -f
$full_pm_path ), "Koha::Plugins::Handler::delete works correctly." );