Bugzilla – Attachment 159820 Details for
Bug 35536
Improve removal of Koha plugins in unit tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35536: Reorganize Plugins.t
Bug-35536-Reorganize-Pluginst.patch (text/plain), 10.85 KB, created by
Marcel de Rooy
on 2023-12-14 10:08:57 UTC
(
hide
)
Description:
Bug 35536: Reorganize Plugins.t
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-12-14 10:08:57 UTC
Size:
10.85 KB
patch
obsolete
>From 3db063bab60030896dac1bf4e9abc42df476a83a Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 13 Dec 2023 15:20:19 +0000 >Subject: [PATCH] Bug 35536: Reorganize Plugins.t >Content-Type: text/plain; charset=utf-8 > >Move stuff in the middle into new subtest. >Add transaction around second set of subtests. > >Test plan: >t/db_dependent/Koha/Plugins/Plugins.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/db_dependent/Koha/Plugins/Plugins.t | 184 +++++++++++++------------- > 1 file changed, 95 insertions(+), 89 deletions(-) > >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index 955712bfd0..704594eb7e 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -24,7 +24,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 => 50; >+use Test::More tests => 16; > use Test::Warn; > > use C4::Context; >@@ -130,6 +130,8 @@ subtest 'more call() tests' => sub { > $schema->storage->txn_rollback; > }; > >+$schema->storage->txn_begin; # matching rollback at the very end >+ > subtest 'feature_enabled tests' => sub { > plan tests => 4; > >@@ -230,94 +232,98 @@ subtest 'is_enabled() tests' => sub { > $schema->storage->txn_rollback; > }; > >-$schema->storage->txn_begin; >-Koha::Plugins::Methods->delete; >-$schema->resultset('PluginData')->delete; >- >-warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef; >- >-ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' ); >-is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' ); >- >-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; >-}); >- >-ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' ); >- >-my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new }); >- >-isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' ); >-isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' ); >- >-ok( $plugin->can('report'), 'Test plugin can report' ); >-ok( $plugin->can('tool'), 'Test plugin can tool' ); >-ok( $plugin->can('to_marc'), 'Test plugin can to_marc' ); >-ok( $plugin->can('intranet_catalog_biblio_enhancements'), 'Test plugin can intranet_catalog_biblio_enhancements'); >-ok( $plugin->can('intranet_catalog_biblio_enhancements_toolbar_button'), 'Test plugin can intranet_catalog_biblio_enhancements_toolbar_button' ); >-ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' ); >-ok( $plugin->can('after_hold_create'), 'Test plugin can after_hold_create' ); >-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('intranet_head'), 'Test plugin can intranet_head' ); >-ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' ); >-ok( $plugin->can('item_barcode_transform'), 'Test plugin can barcode_transform' ); >-ok( $plugin->can('configure'), 'Test plugin can configure' ); >-ok( $plugin->can('install'), 'Test plugin can install' ); >-ok( $plugin->can('upgrade'), 'Test plugin can upgrade' ); >-ok( $plugin->can('uninstall'), 'Test plugin can install' ); >- >-is( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }), "Koha::Plugin::Test::report", 'Test run plugin report method' ); >- >-my $metadata = $plugin->get_metadata(); >-is( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' ); >- >-is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' ); >-is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' ); >- >-# test absolute path change in get_template with Koha::Plugin::Test >-# using the mock set before >-# we also add tmpdir as an approved template dir >-t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context->temporary_directory ] ); >-my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context->temporary_directory ); >-print $fh 'I am [% filename %]'; >-close $fh; >-my $classname = ref($plugin); >-like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' ); >- >-my $result = $plugin->enable; >-is( ref($result), 'Koha::Plugin::Test' ); >- >-# testing GetPlugins >-my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ >- method => 'report' >-}); >- >-my @names = map { $_->get_metadata()->{'name'} } @plugins; >-is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" ); >-@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ >- metadata => { my_example_tag => 'find_me' }, >-}); >- >-@names = map { $_->get_metadata()->{'name'} } @plugins; >-is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" ); >- >-$result = $plugin->disable; >-is( ref($result), 'Koha::Plugin::Test' ); >- >-@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins(); >-@names = map { $_->get_metadata()->{'name'} } @plugins; >-is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disabled Test Plugin" ); >- >-@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ all => 1 }); >-@names = map { $_->get_metadata()->{'name'} } @plugins; >-is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" ); >+subtest 'Koha::Plugin::Test' => sub { >+ $schema->storage->txn_begin; >+ Koha::Plugins::Methods->delete; >+ $schema->resultset('PluginData')->delete; >+ >+ warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef; >+ >+ ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' ); >+ is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' ); >+ >+ 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; >+ }); >+ >+ ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' ); >+ >+ my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new }); >+ >+ isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' ); >+ isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' ); >+ >+ ok( $plugin->can('report'), 'Test plugin can report' ); >+ ok( $plugin->can('tool'), 'Test plugin can tool' ); >+ ok( $plugin->can('to_marc'), 'Test plugin can to_marc' ); >+ ok( $plugin->can('intranet_catalog_biblio_enhancements'), 'Test plugin can intranet_catalog_biblio_enhancements'); >+ ok( $plugin->can('intranet_catalog_biblio_enhancements_toolbar_button'), 'Test plugin can intranet_catalog_biblio_enhancements_toolbar_button' ); >+ ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' ); >+ ok( $plugin->can('after_hold_create'), 'Test plugin can after_hold_create' ); >+ 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('intranet_head'), 'Test plugin can intranet_head' ); >+ ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' ); >+ ok( $plugin->can('item_barcode_transform'), 'Test plugin can barcode_transform' ); >+ ok( $plugin->can('configure'), 'Test plugin can configure' ); >+ ok( $plugin->can('install'), 'Test plugin can install' ); >+ ok( $plugin->can('upgrade'), 'Test plugin can upgrade' ); >+ ok( $plugin->can('uninstall'), 'Test plugin can install' ); >+ >+ is( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }), "Koha::Plugin::Test::report", 'Test run plugin report method' ); >+ >+ my $metadata = $plugin->get_metadata(); >+ is( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' ); >+ >+ is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' ); >+ is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' ); >+ >+ # test absolute path change in get_template with Koha::Plugin::Test >+ # using the mock set before >+ # we also add tmpdir as an approved template dir >+ t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context->temporary_directory ] ); >+ my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context->temporary_directory ); >+ print $fh 'I am [% filename %]'; >+ close $fh; >+ my $classname = ref($plugin); >+ like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' ); >+ >+ my $result = $plugin->enable; >+ is( ref($result), 'Koha::Plugin::Test' ); >+ >+ # testing GetPlugins >+ my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ >+ method => 'report' >+ }); >+ >+ my @names = map { $_->get_metadata()->{'name'} } @plugins; >+ is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" ); >+ @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ >+ metadata => { my_example_tag => 'find_me' }, >+ }); >+ >+ @names = map { $_->get_metadata()->{'name'} } @plugins; >+ is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" ); >+ >+ $result = $plugin->disable; >+ is( ref($result), 'Koha::Plugin::Test' ); >+ >+ @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins(); >+ @names = map { $_->get_metadata()->{'name'} } @plugins; >+ is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disabled Test Plugin" ); >+ >+ @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ all => 1 }); >+ @names = map { $_->get_metadata()->{'name'} } @plugins; >+ is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" ); >+ >+ $schema->storage->txn_rollback; >+}; > > subtest 'output and output_html tests' => sub { > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35536
:
159804
|
159820
|
159821
|
159822
|
159823
|
159824
|
159825
|
159830
|
159839
|
159840
|
159841
|
159842
|
159843
|
159844
|
160024
|
160025
|
160026
|
160027
|
160028
|
160029
|
160030
|
160031
|
160032
|
160801
|
160802
|
160803
|
160804
|
160805
|
160806
|
160807
|
160808
|
160809
|
160817
|
160818
|
160819
|
160820
|
160821
|
160822
|
160823
|
160824
|
160825
|
160881
|
160882
|
160883
|
160884
|
160885
|
160886
|
160887
|
160888
|
160889
|
163701
|
163797