Bugzilla – Attachment 160881 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.76 KB, created by
Kyle M Hall (khall)
on 2024-01-11 16:53:21 UTC
(
hide
)
Description:
Bug 35536: Reorganize Plugins.t
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2024-01-11 16:53:21 UTC
Size:
10.76 KB
patch
obsolete
>From de0f8ee8937253f6383ed07d2c71401dc9c05d8f 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 > >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> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > 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 955712bfd03..71497a30363 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; >@@ -230,94 +230,100 @@ 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; >+}; >+ >+$schema->storage->txn_begin; # matching rollback at the very end > > 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