Bugzilla – Attachment 159818 Details for
Bug 35507
Fix handling plugins in unit tests causing random failures on Jenkins
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35507: Add Plugins::Method->delete
Bug-35507-Add-PluginsMethod-delete.patch (text/plain), 5.18 KB, created by
Jonathan Druart
on 2023-12-14 07:43:29 UTC
(
hide
)
Description:
Bug 35507: Add Plugins::Method->delete
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-12-14 07:43:29 UTC
Size:
5.18 KB
patch
obsolete
>From 4e7e9435432374687842e2014e1b571b18ff13c0 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 11 Dec 2023 10:43:04 +0000 >Subject: [PATCH] Bug 35507: Add Plugins::Method->delete > >Delete record in plugin_data too and clear cache. > >Note: Adding the singular delete, makes the plural loop and >call the singular in Koha::Objects. > >Test plan: >Run prove prove $(git grep -l Koha::Plugin | grep -P "^t\/db") > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Plugins/Method.pm | 21 +++++++- > t/db_dependent/Koha/Plugins/Method.t | 73 ++++++++++++++++++++++++++++ > 2 files changed, 93 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Koha/Plugins/Method.t > >diff --git a/Koha/Plugins/Method.pm b/Koha/Plugins/Method.pm >index b6e2e750b8d..0d66712708a 100644 >--- a/Koha/Plugins/Method.pm >+++ b/Koha/Plugins/Method.pm >@@ -17,8 +17,9 @@ package Koha::Plugins::Method; > > use Modern::Perl; > >- > use Koha::Database; >+use Koha::Cache::Memory::Lite; >+use Koha::Plugins; > > use base qw(Koha::Object); > >@@ -30,8 +31,26 @@ Koha::Plugin::Method - Koha Plugin Method Object class > > =head2 Class Methods > >+=head3 delete >+ >+ Delete method record. >+ But also delete associated plugin_data records. >+ Clear cache key. >+ > =cut > >+sub delete { >+ my ($self) = @_; >+ >+ # Remove corresponding records from plugin_data. Clear cache. >+ my $cond = { plugin_class => $self->plugin_class }; >+ Koha::Database->new->schema->resultset('PluginData')->search($cond)->delete; >+ Koha::Cache::Memory::Lite->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ); >+ >+ # Now do the actual delete >+ return $self->SUPER::delete; >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Plugins/Method.t b/t/db_dependent/Koha/Plugins/Method.t >new file mode 100755 >index 00000000000..65599265181 >--- /dev/null >+++ b/t/db_dependent/Koha/Plugins/Method.t >@@ -0,0 +1,73 @@ >+#!/usr/bin/perl >+ >+# Copyright 2023 Rijksmuseum, Koha development team >+# >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Test::MockModule; >+use Test::More tests => 1; >+ >+use t::lib::TestBuilder; >+ >+use Koha::Database; >+use Koha::Cache::Memory::Lite; >+use Koha::Plugins; >+use Koha::Plugins::Methods; >+ >+my $builder = t::lib::TestBuilder->new; >+my $schema = Koha::Database->new->schema; >+ >+$schema->storage->txn_begin; >+ >+# We need to mock can_load from Module::Load::Conditional in Koha/Plugins >+my $mock = Test::MockModule->new('Koha::Plugins')->mock( can_load => 1 ); >+ >+subtest 'delete' => sub { >+ plan tests => 7; >+ >+ my $count_m = Koha::Plugins::Methods->count; >+ my $count_d = $schema->resultset('PluginData')->count; >+ Koha::Cache::Memory::Lite->get_instance->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ); >+ my @enabled_plugins = Koha::Plugins->get_enabled_plugins; >+ >+ # Mock creation of new plugin >+ my $method = $builder->build_object( { class => 'Koha::Plugins::Methods' } ); >+ my $values = { plugin_class => $method->plugin_class, plugin_key => '__ENABLED__', plugin_value => 1 }; >+ my $data = $builder->build( { source => 'PluginData', value => $values } ); >+ >+ # Note: no_auto => 1 in next call prevent loading of a not-existing module >+ my $plugin_mock = Test::MockModule->new( $method->plugin_class, no_auto => 1 ) >+ ->mock( new => bless( { mocked => 1 }, $method->plugin_class ) ); >+ >+ # Check for new method and if get_enabled_plugins sees it too >+ is( Koha::Plugins::Methods->count, $count_m + 1, 'Expect a new method' ); >+ is( $schema->resultset('PluginData')->count, $count_d + 1, 'Expect entry in plugin_data' ); >+ Koha::Cache::Memory::Lite->get_instance->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ); >+ is( scalar Koha::Plugins->get_enabled_plugins, 1 + @enabled_plugins, 'Recheck get_enabled_plugins' ); >+ >+ # Delete the method from plugin_methods, check table and cache >+ Koha::Plugins::Methods->search( { plugin_class => $method->plugin_class } )->delete; >+ is( >+ Koha::Cache::Memory::Lite->get_instance->get_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ), >+ undef, 'Cache has been cleared by delete method' >+ ); >+ is( Koha::Plugins::Methods->count, $count_m, 'Original number of methods' ); >+ is( $schema->resultset('PluginData')->count, $count_d, 'Original count in plugin_data' ); >+ is( scalar Koha::Plugins->get_enabled_plugins, scalar @enabled_plugins, 'Original number of enabled plugins' ); >+}; >+ >+$schema->storage->txn_rollback; >-- >2.34.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 35507
:
159670
|
159739
|
159744
|
159745
|
159801
|
159802
|
159803
|
159817
|
159818
|
159846
|
159847
|
159848
|
159849
|
159850
|
159860
|
159861
|
159862