From 763781431541bf99fc185d5f2583915494bd7ddf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 19 Oct 2021 15:58:25 +0200 Subject: [PATCH] Bug 29273: Remove warnings from plugin tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch is suggesting to move the broken test plugins into a separate directory. t/lib/plugins and t/lib/bad_plugins Signed-off-by: David Nind JK: Add executable bit to Broken.t Signed-off-by: Joonas Kylmälä --- .../Koha/Plugins/Barcode_transform_hooks.t | 7 +-- .../Plugins/Biblio_and_Items_plugin_hooks.t | 2 +- t/db_dependent/Koha/Plugins/Broken.t | 47 +++++++++++++++++++ .../Koha/Plugins/Circulation_hooks.t | 2 +- t/db_dependent/Koha/Plugins/Holds_hooks.t | 2 +- t/db_dependent/Koha/Plugins/Patron.t | 2 +- t/db_dependent/Koha/Plugins/Plugins.t | 23 +++------ .../Koha/Plugin/BrokenInstall.pm | 0 .../Koha/Plugin/BrokenUpgrade.pm | 0 .../{ => plugins}/Koha/Plugin/BadAPIRoute.pm | 0 .../Koha/Plugin/MarcFieldValues.pm | 0 t/lib/{ => plugins}/Koha/Plugin/Test.pm | 0 .../Koha/Plugin/Test/Controller.pm | 0 .../Koha/Plugin/TestItemBarcodeTransform.pm | 0 14 files changed, 60 insertions(+), 25 deletions(-) create mode 100755 t/db_dependent/Koha/Plugins/Broken.t rename t/lib/{ => bad_plugins}/Koha/Plugin/BrokenInstall.pm (100%) rename t/lib/{ => bad_plugins}/Koha/Plugin/BrokenUpgrade.pm (100%) rename t/lib/{ => plugins}/Koha/Plugin/BadAPIRoute.pm (100%) rename t/lib/{ => plugins}/Koha/Plugin/MarcFieldValues.pm (100%) rename t/lib/{ => plugins}/Koha/Plugin/Test.pm (100%) rename t/lib/{ => plugins}/Koha/Plugin/Test/Controller.pm (100%) rename t/lib/{ => plugins}/Koha/Plugin/TestItemBarcodeTransform.pm (100%) diff --git a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t b/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t index 86f8c31e13..2fba2fb744 100755 --- a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t +++ b/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t @@ -27,7 +27,7 @@ use t::lib::TestBuilder; BEGIN { # Mock pluginsdir before loading Plugins module - my $path = dirname(__FILE__) . '/../../../lib'; + my $path = dirname(__FILE__) . '/../../../lib/plugins'; t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); @@ -53,10 +53,7 @@ subtest 'patron_barcode_transform() and item_barcode_transform() hook tests' => my $plugins = Koha::Plugins->new; - warnings_are - { $plugins->InstallPlugins; } - [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", - "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; + warning_is { $plugins->InstallPlugins; } undef; C4::Context->dbh->do("DELETE FROM plugin_methods WHERE plugin_class LIKE '%TestBarcodes%'"); diff --git a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t b/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t index fda58e013d..4f29aae60f 100755 --- a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t +++ b/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t @@ -28,7 +28,7 @@ use t::lib::TestBuilder; BEGIN { # Mock pluginsdir before loading Plugins module - my $path = dirname(__FILE__) . '/../../../lib'; + my $path = dirname(__FILE__) . '/../../../lib/plugins'; t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); diff --git a/t/db_dependent/Koha/Plugins/Broken.t b/t/db_dependent/Koha/Plugins/Broken.t new file mode 100755 index 0000000000..d6e58fda1e --- /dev/null +++ b/t/db_dependent/Koha/Plugins/Broken.t @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 3; +use Test::MockModule; +use Test::Warn; + +use File::Basename; + +use t::lib::Mocks; +use t::lib::TestBuilder; + +BEGIN { + # Mock pluginsdir before loading Plugins module + my $path = dirname(__FILE__) . '/../../../lib/bad_plugins'; + t::lib::Mocks::mock_config( 'pluginsdir', $path ); + + use_ok('Koha::Plugins'); + use_ok('Koha::Plugins::Handler'); +} + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +t::lib::Mocks::mock_config( 'enable_plugins', 1 ); + +my $plugins = Koha::Plugins->new; + +warnings_are + { $plugins->InstallPlugins; } + [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", + "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; diff --git a/t/db_dependent/Koha/Plugins/Circulation_hooks.t b/t/db_dependent/Koha/Plugins/Circulation_hooks.t index 7d038bb4db..e667f17971 100755 --- a/t/db_dependent/Koha/Plugins/Circulation_hooks.t +++ b/t/db_dependent/Koha/Plugins/Circulation_hooks.t @@ -29,7 +29,7 @@ use t::lib::TestBuilder; BEGIN { # Mock pluginsdir before loading Plugins module - my $path = dirname(__FILE__) . '/../../../lib'; + my $path = dirname(__FILE__) . '/../../../lib/plugins'; t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); diff --git a/t/db_dependent/Koha/Plugins/Holds_hooks.t b/t/db_dependent/Koha/Plugins/Holds_hooks.t index 07aa4f7344..2e40b9d939 100755 --- a/t/db_dependent/Koha/Plugins/Holds_hooks.t +++ b/t/db_dependent/Koha/Plugins/Holds_hooks.t @@ -29,7 +29,7 @@ use t::lib::TestBuilder; BEGIN { # Mock pluginsdir before loading Plugins module - my $path = dirname(__FILE__) . '/../../../lib'; + my $path = dirname(__FILE__) . '/../../../lib/plugins'; t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); diff --git a/t/db_dependent/Koha/Plugins/Patron.t b/t/db_dependent/Koha/Plugins/Patron.t index c8b2e86f25..a818cdeb45 100755 --- a/t/db_dependent/Koha/Plugins/Patron.t +++ b/t/db_dependent/Koha/Plugins/Patron.t @@ -28,7 +28,7 @@ use t::lib::TestBuilder; BEGIN { # Mock pluginsdir before loading Plugins module - my $path = dirname(__FILE__) . '/../../../lib'; + my $path = dirname(__FILE__) . '/../../../lib/plugins'; t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t index 418311b062..14990ad09a 100755 --- a/t/db_dependent/Koha/Plugins/Plugins.t +++ b/t/db_dependent/Koha/Plugins/Plugins.t @@ -36,7 +36,7 @@ use t::lib::Mocks; BEGIN { # Mock pluginsdir before loading Plugins module - my $path = dirname(__FILE__) . '/../../../lib'; + my $path = dirname(__FILE__) . '/../../../lib/plugins'; t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); @@ -61,9 +61,7 @@ subtest 'call() tests' => sub { my @plugins; - warnings_are - { @plugins = $plugins->InstallPlugins; } - [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; + warning_is { @plugins = $plugins->InstallPlugins; } undef; foreach my $plugin (@plugins) { $plugin->enable(); @@ -99,10 +97,7 @@ subtest 'more call() tests' => sub { my $plugins = Koha::Plugins->new({ enable_plugins => 1 }); my @plugins; - warnings_are - { @plugins = $plugins->InstallPlugins; } - [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", - "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; + warning_is { @plugins = $plugins->InstallPlugins; } undef; foreach my $plugin (@plugins) { $plugin->enable(); @@ -142,8 +137,7 @@ subtest 'GetPlugins() tests' => sub { my $plugins = Koha::Plugins->new({ enable_plugins => 1 }); - warnings_are { $plugins->InstallPlugins; } - [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; + warning_is { $plugins->InstallPlugins; } undef; my @plugins = $plugins->GetPlugins({ method => 'report', all => 1 }); @@ -204,8 +198,7 @@ subtest 'is_enabled() tests' => sub { $schema->storage->txn_begin; Koha::Plugins::Methods->delete; -warnings_are { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } -[ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; +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' ); @@ -320,9 +313,7 @@ for my $pass ( 1 .. 2 ) { ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" ); $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" - warnings_are - { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } - [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; + warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef; ok( -f $full_pm_path, "Koha::Plugins::Handler::delete works correctly (pass $pass)" ); Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink", enable_plugins => 1 }); my $sth = C4::Context->dbh->table_info( undef, undef, $table, 'TABLE' ); @@ -400,7 +391,7 @@ subtest 'bundle_path() tests' => sub { my $plugin = Koha::Plugin::Test->new; - is( $plugin->bundle_path, File::Spec->catdir(@current_dir) . '/lib/Koha/Plugin/Test' ); + is( $plugin->bundle_path, File::Spec->catdir(@current_dir) . '/lib/plugins/Koha/Plugin/Test' ); }; diff --git a/t/lib/Koha/Plugin/BrokenInstall.pm b/t/lib/bad_plugins/Koha/Plugin/BrokenInstall.pm similarity index 100% rename from t/lib/Koha/Plugin/BrokenInstall.pm rename to t/lib/bad_plugins/Koha/Plugin/BrokenInstall.pm diff --git a/t/lib/Koha/Plugin/BrokenUpgrade.pm b/t/lib/bad_plugins/Koha/Plugin/BrokenUpgrade.pm similarity index 100% rename from t/lib/Koha/Plugin/BrokenUpgrade.pm rename to t/lib/bad_plugins/Koha/Plugin/BrokenUpgrade.pm diff --git a/t/lib/Koha/Plugin/BadAPIRoute.pm b/t/lib/plugins/Koha/Plugin/BadAPIRoute.pm similarity index 100% rename from t/lib/Koha/Plugin/BadAPIRoute.pm rename to t/lib/plugins/Koha/Plugin/BadAPIRoute.pm diff --git a/t/lib/Koha/Plugin/MarcFieldValues.pm b/t/lib/plugins/Koha/Plugin/MarcFieldValues.pm similarity index 100% rename from t/lib/Koha/Plugin/MarcFieldValues.pm rename to t/lib/plugins/Koha/Plugin/MarcFieldValues.pm diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm similarity index 100% rename from t/lib/Koha/Plugin/Test.pm rename to t/lib/plugins/Koha/Plugin/Test.pm diff --git a/t/lib/Koha/Plugin/Test/Controller.pm b/t/lib/plugins/Koha/Plugin/Test/Controller.pm similarity index 100% rename from t/lib/Koha/Plugin/Test/Controller.pm rename to t/lib/plugins/Koha/Plugin/Test/Controller.pm diff --git a/t/lib/Koha/Plugin/TestItemBarcodeTransform.pm b/t/lib/plugins/Koha/Plugin/TestItemBarcodeTransform.pm similarity index 100% rename from t/lib/Koha/Plugin/TestItemBarcodeTransform.pm rename to t/lib/plugins/Koha/Plugin/TestItemBarcodeTransform.pm -- 2.20.1