Bugzilla – Attachment 160826 Details for
Bug 35548
Move KitchenSink test on its own and control table creation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35548: Test KitchenSink plugin
Bug-35548-Test-KitchenSink-plugin.patch (text/plain), 4.50 KB, created by
Martin Renvoize (ashimema)
on 2024-01-11 09:55:12 UTC
(
hide
)
Description:
Bug 35548: Test KitchenSink plugin
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-01-11 09:55:12 UTC
Size:
4.50 KB
patch
obsolete
>From 4957d062976e746c2f39a4c11a325484294a0b3a Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 14 Dec 2023 12:25:23 +0000 >Subject: [PATCH] Bug 35548: Test KitchenSink plugin > >Removed from Plugins.t on bug 35507. >Restoring it here on its own. >Simplified a bit. > >NOTE: The CREATE IF NOT EXISTS seems to commit even when the >table already exists. Therefore mocking install too. > >Test plan: >Check number of records in plugin_data/methods. >Run t/db_dependent/Koha/Plugins/KitchenSink.t >Check again number of records in plugin_data/methods. Same? > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Plugins/KitchenSink.t | 83 +++++++++++++++++++++++ > 1 file changed, 83 insertions(+) > create mode 100755 t/db_dependent/Koha/Plugins/KitchenSink.t > >diff --git a/t/db_dependent/Koha/Plugins/KitchenSink.t b/t/db_dependent/Koha/Plugins/KitchenSink.t >new file mode 100755 >index 00000000000..d3c2c088916 >--- /dev/null >+++ b/t/db_dependent/Koha/Plugins/KitchenSink.t >@@ -0,0 +1,83 @@ >+#!/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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Archive::Extract; >+use File::Temp qw/tempdir/; >+use FindBin qw($Bin); >+use Test::MockModule; >+use Test::More tests => 1; >+use Test::Warn; >+ >+use t::lib::Mocks; >+ >+use C4::Context; >+use Koha::Database; >+use Koha::Plugins; >+use Koha::Plugins::Datas; >+use Koha::Plugins::Handler; >+use Koha::Plugins::Methods; >+ >+my $schema = Koha::Database->new->schema; >+ >+subtest 'Fun with KitchenSink, Handler->delete' => sub { >+ plan tests => 7; >+ >+ create_mytable(); # IMPORTANT: before transaction start (prevent implicit commit) >+ $schema->storage->txn_begin; >+ t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); >+ t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ >+ my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink'; >+ my $pm_path = 'Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm'; >+ Koha::Plugins->RemovePlugins( { plugin_class => $module_name, destructive => 1 } ); # just to be safe >+ Koha::Plugins->new->InstallPlugins; # install without KitchenSink >+ my ( $count_d, $count_m ) = ( Koha::Plugins::Datas->count, Koha::Plugins::Methods->count ); >+ >+ # Install KitchenSink, mock install and uninstall >+ my $plugins_dir = tempdir( CLEANUP => 1 ); >+ t::lib::Mocks::mock_config( 'pluginsdir', $plugins_dir ); >+ push @INC, $plugins_dir; >+ my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' ); >+ $ae->extract( to => $plugins_dir ) or warn "ERROR: " . $ae->error; >+ my $mock = Test::MockModule->new($module_name)->mock( install => 1 )->mock( uninstall => 1 ); >+ warning_is { Koha::Plugins->new->InstallPlugins; } undef, 'No warnings from InstallPlugins'; >+ ok( Koha::Plugins::Datas->count > $count_d, 'More records in plugin_data' ); >+ ok( Koha::Plugins::Methods->count > $count_m, 'More records in plugin_methods' ); >+ ok( -f "$plugins_dir/$pm_path", "KitchenSink module found" ); >+ >+ # Delete via Handler->delete, uninstall has been mocked to prevent implicit commit (DROP TABLE) >+ Koha::Plugins::Handler->delete( { class => $module_name } ); >+ >+ # Final checks >+ ok( !-f "$plugins_dir/$pm_path", "Module file no longer found" ); >+ is( Koha::Plugins::Datas->count, $count_d, 'Original count in plugin_data' ); >+ is( Koha::Plugins::Methods->count, $count_m, 'Original count in plugin_methods' ); >+ >+ $schema->storage->txn_rollback; >+ drop_mytable(); # Created before txn, remove after rollback >+}; >+ >+sub create_mytable { >+ >+ # This create mimics what KitchenSink would do. >+ # The columns are not relevant here. >+ C4::Context->dbh->do("CREATE TABLE IF NOT EXISTS mytable ( test int )"); >+} >+ >+sub drop_mytable { >+ C4::Context->dbh->do("DROP TABLE mytable"); >+} >-- >2.43.0
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 35548
:
160115
|
160826
|
160990
|
163765