View | Details | Raw Unified | Return to bug 35536
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-90 / +95 lines)
Lines 24-30 use File::Temp qw( tempdir tempfile ); Link Here
24
use FindBin qw($Bin);
24
use FindBin qw($Bin);
25
use Module::Load::Conditional qw(can_load);
25
use Module::Load::Conditional qw(can_load);
26
use Test::MockModule;
26
use Test::MockModule;
27
use Test::More tests => 50;
27
use Test::More tests => 16;
28
use Test::Warn;
28
use Test::Warn;
29
29
30
use C4::Context;
30
use C4::Context;
Lines 130-135 subtest 'more call() tests' => sub { Link Here
130
    $schema->storage->txn_rollback;
130
    $schema->storage->txn_rollback;
131
};
131
};
132
132
133
$schema->storage->txn_begin;    # matching rollback at the very end
134
133
subtest 'feature_enabled tests' => sub {
135
subtest 'feature_enabled tests' => sub {
134
    plan tests => 4;
136
    plan tests => 4;
135
137
Lines 230-323 subtest 'is_enabled() tests' => sub { Link Here
230
    $schema->storage->txn_rollback;
232
    $schema->storage->txn_rollback;
231
};
233
};
232
234
233
$schema->storage->txn_begin;
235
subtest 'Koha::Plugin::Test' => sub {
234
Koha::Plugins::Methods->delete;
236
    $schema->storage->txn_begin;
235
$schema->resultset('PluginData')->delete;
237
    Koha::Plugins::Methods->delete;
236
238
    $schema->resultset('PluginData')->delete;
237
warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef;
239
238
240
    warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef;
239
ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' );
241
240
is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' );
242
    ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' );
241
243
    is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' );
242
my $mock_plugin = Test::MockModule->new( 'Koha::Plugin::Test' );
244
243
$mock_plugin->mock( 'test_template', sub {
245
    my $mock_plugin = Test::MockModule->new( 'Koha::Plugin::Test' );
244
    my ( $self, $file ) = @_;
246
    $mock_plugin->mock( 'test_template', sub {
245
    my $template = $self->get_template({ file => $file });
247
        my ( $self, $file ) = @_;
246
    $template->param( filename => $file );
248
        my $template = $self->get_template({ file => $file });
247
    return $template->output;
249
        $template->param( filename => $file );
248
});
250
        return $template->output;
249
251
    });
250
ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' );
252
251
253
    ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' );
252
my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new });
254
253
255
    my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new });
254
isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' );
256
255
isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' );
257
    isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' );
256
258
    isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' );
257
ok( $plugin->can('report'), 'Test plugin can report' );
259
258
ok( $plugin->can('tool'), 'Test plugin can tool' );
260
    ok( $plugin->can('report'), 'Test plugin can report' );
259
ok( $plugin->can('to_marc'), 'Test plugin can to_marc' );
261
    ok( $plugin->can('tool'), 'Test plugin can tool' );
260
ok( $plugin->can('intranet_catalog_biblio_enhancements'), 'Test plugin can intranet_catalog_biblio_enhancements');
262
    ok( $plugin->can('to_marc'), 'Test plugin can to_marc' );
261
ok( $plugin->can('intranet_catalog_biblio_enhancements_toolbar_button'), 'Test plugin can intranet_catalog_biblio_enhancements_toolbar_button' );
263
    ok( $plugin->can('intranet_catalog_biblio_enhancements'), 'Test plugin can intranet_catalog_biblio_enhancements');
262
ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' );
264
    ok( $plugin->can('intranet_catalog_biblio_enhancements_toolbar_button'), 'Test plugin can intranet_catalog_biblio_enhancements_toolbar_button' );
263
ok( $plugin->can('after_hold_create'), 'Test plugin can after_hold_create' );
265
    ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' );
264
ok( $plugin->can('opac_online_payment_begin'), 'Test plugin can opac_online_payment_begin' );
266
    ok( $plugin->can('after_hold_create'), 'Test plugin can after_hold_create' );
265
ok( $plugin->can('opac_online_payment_end'), 'Test plugin can opac_online_payment_end' );
267
    ok( $plugin->can('opac_online_payment_begin'), 'Test plugin can opac_online_payment_begin' );
266
ok( $plugin->can('opac_head'), 'Test plugin can opac_head' );
268
    ok( $plugin->can('opac_online_payment_end'), 'Test plugin can opac_online_payment_end' );
267
ok( $plugin->can('opac_js'), 'Test plugin can opac_js' );
269
    ok( $plugin->can('opac_head'), 'Test plugin can opac_head' );
268
ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' );
270
    ok( $plugin->can('opac_js'), 'Test plugin can opac_js' );
269
ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' );
271
    ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' );
270
ok( $plugin->can('item_barcode_transform'), 'Test plugin can barcode_transform' );
272
    ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' );
271
ok( $plugin->can('configure'), 'Test plugin can configure' );
273
    ok( $plugin->can('item_barcode_transform'), 'Test plugin can barcode_transform' );
272
ok( $plugin->can('install'), 'Test plugin can install' );
274
    ok( $plugin->can('configure'), 'Test plugin can configure' );
273
ok( $plugin->can('upgrade'), 'Test plugin can upgrade' );
275
    ok( $plugin->can('install'), 'Test plugin can install' );
274
ok( $plugin->can('uninstall'), 'Test plugin can install' );
276
    ok( $plugin->can('upgrade'), 'Test plugin can upgrade' );
275
277
    ok( $plugin->can('uninstall'), 'Test plugin can install' );
276
is( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }), "Koha::Plugin::Test::report", 'Test run plugin report method' );
278
277
279
    is( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }), "Koha::Plugin::Test::report", 'Test run plugin report method' );
278
my $metadata = $plugin->get_metadata();
280
279
is( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' );
281
    my $metadata = $plugin->get_metadata();
280
282
    is( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' );
281
is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
283
282
is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
284
    is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
283
285
    is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
284
# test absolute path change in get_template with Koha::Plugin::Test
286
285
# using the mock set before
287
    # test absolute path change in get_template with Koha::Plugin::Test
286
# we also add tmpdir as an approved template dir
288
    # using the mock set before
287
t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context->temporary_directory ] );
289
    # we also add tmpdir as an approved template dir
288
my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context->temporary_directory );
290
    t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context->temporary_directory ] );
289
print $fh 'I am [% filename %]';
291
    my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context->temporary_directory );
290
close $fh;
292
    print $fh 'I am [% filename %]';
291
my $classname = ref($plugin);
293
    close $fh;
292
like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' );
294
    my $classname = ref($plugin);
293
295
    like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' );
294
my $result = $plugin->enable;
296
295
is( ref($result), 'Koha::Plugin::Test' );
297
    my $result = $plugin->enable;
296
298
    is( ref($result), 'Koha::Plugin::Test' );
297
# testing GetPlugins
299
298
my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
300
    # testing GetPlugins
299
    method => 'report'
301
    my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
300
});
302
        method => 'report'
301
303
    });
302
my @names = map { $_->get_metadata()->{'name'} } @plugins;
304
303
is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" );
305
    my @names = map { $_->get_metadata()->{'name'} } @plugins;
304
@plugins =  Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
306
    is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" );
305
    metadata => { my_example_tag  => 'find_me' },
307
    @plugins =  Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
306
});
308
        metadata => { my_example_tag  => 'find_me' },
307
309
    });
308
@names = map { $_->get_metadata()->{'name'} } @plugins;
310
309
is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" );
311
    @names = map { $_->get_metadata()->{'name'} } @plugins;
310
312
    is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" );
311
$result = $plugin->disable;
313
312
is( ref($result), 'Koha::Plugin::Test' );
314
    $result = $plugin->disable;
313
315
    is( ref($result), 'Koha::Plugin::Test' );
314
@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins();
316
315
@names = map { $_->get_metadata()->{'name'} } @plugins;
317
    @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins();
316
is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disabled Test Plugin" );
318
    @names = map { $_->get_metadata()->{'name'} } @plugins;
317
319
    is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disabled Test Plugin" );
318
@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ all => 1 });
320
319
@names = map { $_->get_metadata()->{'name'} } @plugins;
321
    @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ all => 1 });
320
is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" );
322
    @names = map { $_->get_metadata()->{'name'} } @plugins;
323
    is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" );
324
325
    $schema->storage->txn_rollback;
326
};
321
327
322
subtest 'output and output_html tests' => sub {
328
subtest 'output and output_html tests' => sub {
323
329
324
- 

Return to bug 35536