Bugzilla – Attachment 184823 Details for
Bug 34978
Add --include and --exclude options to install_plugins.pl to choose the plugins to install
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34978: Simplify tests logic
Bug-34978-Simplify-tests-logic.patch (text/plain), 5.00 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-07-29 15:18:25 UTC
(
hide
)
Description:
Bug 34978: Simplify tests logic
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-07-29 15:18:25 UTC
Size:
5.00 KB
patch
obsolete
>From 37066fc33712e2846fcc22d1e3471de54c683272 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 29 Jul 2025 12:13:12 -0300 >Subject: [PATCH] Bug 34978: Simplify tests logic > >Joining the plugin classes strings and then performing regex checks on >it might be a bit fragile. I had hard time understanding the ands the >conditions for truth. > >I rewrote it in a more intuitive way just using `none` and the tests are >easy to understand and pass. > >The failure is probably because new plugins were added that make the >resulting string not match the expected structure. > >The new new tests design is more readable anyway and not subject to this >errors in future additions. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/Plugins/Plugins.t | 51 +++++++++++++++------------ > 1 file changed, 28 insertions(+), 23 deletions(-) > >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index 90b1f482bd5..46a68d94f41 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -22,6 +22,7 @@ use File::Basename; > use File::Spec; > use File::Temp qw( tempdir tempfile ); > use FindBin qw($Bin); >+use List::MoreUtils qw(none); > use Module::Load::Conditional qw(can_load); > use Test::MockModule; > use Test::NoWarnings; >@@ -194,7 +195,7 @@ subtest 'GetPlugins() tests' => sub { > > subtest 'InstallPlugins() tests' => sub { > >- plan tests => 6; >+ plan tests => 8; > > $schema->storage->txn_begin; > >@@ -204,21 +205,25 @@ subtest 'InstallPlugins() tests' => sub { > > # Tests for the exclude parameter > # Test the returned plugins of the InstallPlugins subroutine >+ my $excluded_plugins = [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ]; > my $plugins = Koha::Plugins->new( { enable_plugins => 1 } ); >- my @installed_plugins = $plugins->InstallPlugins( { exclude => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); >- my $plugin_classes = join( " ", map { $_->{class} } @installed_plugins ); >+ my @installed_plugins = $plugins->InstallPlugins( { exclude => $excluded_plugins } ); > >- my $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ] >- && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; >- ok( $result, "Excluded plugins are not returned" ); >+ foreach my $excluded_plugin ( @{$excluded_plugins} ) { >+ ok( >+ none { $_ eq $excluded_plugin } ( map { $_->{class} } @installed_plugins ), >+ "Excluded plugin not returned ($excluded_plugin)" >+ ); >+ } > > # Test the plugins in the database > my @plugins = $plugins->GetPlugins( { all => 1, error => 1 } ); >- $plugin_classes = join( " ", map { $_->{class} } @plugins ); >- >- $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ] >- && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; >- ok( $result, "Excluded plugins are not installed" ); >+ foreach my $excluded_plugin ( @{$excluded_plugins} ) { >+ ok( >+ none { $_ eq $excluded_plugin } ( map { $_->{class} } @plugins ), >+ "Excluded plugin not installed ($excluded_plugin)" >+ ); >+ } > > # Remove installed plugins data > Koha::Plugins::Methods->delete; >@@ -226,9 +231,10 @@ subtest 'InstallPlugins() tests' => sub { > > # Tests for the include parameter > # Test the returned plugins of the InstallPlugins subroutine >- @installed_plugins = $plugins->InstallPlugins( { include => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); >+ @installed_plugins = >+ $plugins->InstallPlugins( { include => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); > >- $result = 1; >+ my $result = 1; > foreach my $plugin_class ( map { $_->{class} } @installed_plugins ) { > $result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" ); > } >@@ -244,17 +250,16 @@ subtest 'InstallPlugins() tests' => sub { > ok( $result, "Only included plugins are installed" ); > > # Tests when both include and exclude parameter are used simultaneously >- throws_ok >- { >- $plugins->InstallPlugins( { exclude => [ "Koha::Plugin::Test" ], include => [ "Koha::Plugin::Test" ] } ); >- } >- 'Koha::Exceptions::BadParameter'; >+ throws_ok { >+ $plugins->InstallPlugins( { exclude => ["Koha::Plugin::Test"], include => ["Koha::Plugin::Test"] } ); >+ } >+ 'Koha::Exceptions::BadParameter'; >+ > # Tests when the plugin to be installled is not found >- throws_ok >- { >- $plugins->InstallPlugins( { include => [ "Koha::Plugin::NotfoundPlugin" ] } ); >- } >- 'Koha::Exceptions::BadParameter'; >+ throws_ok { >+ $plugins->InstallPlugins( { include => ["Koha::Plugin::NotfoundPlugin"] } ); >+ } >+ 'Koha::Exceptions::BadParameter'; > > $schema->storage->txn_rollback; > }; >-- >2.50.1
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 34978
:
156539
|
156555
|
156557
|
160210
|
160239
|
160240
|
163800
|
163801
|
166560
|
166561
|
166562
|
166576
|
166736
|
166738
|
166739
|
166740
|
166741
|
166742
|
179887
|
179888
|
179889
|
179890
|
179891
|
180584
|
180585
|
180586
|
180587
|
180588
|
184818
|
184819
|
184820
|
184821
|
184822
| 184823