Bugzilla – Attachment 126497 Details for
Bug 28211
Replace use of call_recursive() with call()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28211: (QA follow-up) Test for hook calls properly
Bug-28211-QA-follow-up-Test-for-hook-calls-properl.patch (text/plain), 5.05 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-10-19 12:49:31 UTC
(
hide
)
Description:
Bug 28211: (QA follow-up) Test for hook calls properly
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-10-19 12:49:31 UTC
Size:
5.05 KB
patch
obsolete
>From f2768580ffec0d245b38943a4ce205f404b2f229 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 19 Oct 2021 09:46:32 -0300 >Subject: [PATCH] Bug 28211: (QA follow-up) Test for hook calls properly > >Some warnings, that mean a hook has been called were not tested. >This patch adds those tests, and does some tidy also. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > .../Koha/Plugins/Barcode_transform_hooks.t | 34 ++++++++++++------- > t/db_dependent/Koha/Plugins/Plugins.t | 21 +++++++++--- > 2 files changed, 38 insertions(+), 17 deletions(-) > >diff --git a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t b/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t >index 889dcf500b..86f8c31e13 100755 >--- a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t >+++ b/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t >@@ -40,14 +40,24 @@ my $builder = t::lib::TestBuilder->new; > > t::lib::Mocks::mock_config( 'enable_plugins', 1 ); > >-subtest '() hook tests' => sub { >+subtest 'patron_barcode_transform() and item_barcode_transform() hook tests' => sub { > >- plan tests => 4; >+ plan tests => 6; > > $schema->storage->txn_begin; > >+ # Avoid testing useless warnings >+ my $test_plugin = Test::MockModule->new('Koha::Plugin::Test'); >+ $test_plugin->mock( 'after_item_action', undef ); >+ $test_plugin->mock( 'after_biblio_action', undef ); >+ > my $plugins = Koha::Plugins->new; >- $plugins->InstallPlugins; >+ >+ warnings_are >+ { $plugins->InstallPlugins; } >+ [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", >+ "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; >+ > C4::Context->dbh->do("DELETE FROM plugin_methods WHERE plugin_class LIKE '%TestBarcodes%'"); > > my $plugin = Koha::Plugin::Test->new->enable; >@@ -81,18 +91,16 @@ subtest '() hook tests' => sub { > } > ); > >- # Avoid testing useless warnings >- my $test_plugin = Test::MockModule->new('Koha::Plugin::Test'); >- $test_plugin->mock( 'after_item_action', undef ); >- $test_plugin->mock( 'after_biblio_action', undef ); >+ my $item; >+ warning_like { $item = $builder->build_sample_item(); } >+ qr/Plugin error \(Test Plugin\): item_barcode_transform called with parameter: /, >+ 'Koha::Item->store calls the item_barcode_transform hook'; > >- my $biblio = $builder->build_sample_biblio(); >- my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); >- $item_1->barcode('THISISATEST'); >+ $item->barcode('THISISATEST'); > >- warning_like { $item_1->store(); } >- qr/item_barcode_transform called with parameter: THISISATEST/, >- 'AddReserve calls the after_hold_create hook'; >+ warning_is { $item->store(); } >+ 'Plugin error (Test Plugin): item_barcode_transform called with parameter: THISISATEST', >+ 'Koha::Item->store calls the item_barcode_transform hook'; > > $schema->storage->txn_rollback; > Koha::Plugins::Methods->delete; >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index f3d04d21bb..418311b062 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -88,7 +88,8 @@ subtest 'call() tests' => sub { > }; > > subtest 'more call() tests' => sub { >- plan tests => 3; >+ >+ plan tests => 6; > > $schema->storage->txn_begin; > # Temporarily remove any installed plugins data >@@ -96,7 +97,13 @@ subtest 'more call() tests' => sub { > > t::lib::Mocks::mock_config('enable_plugins', 1); > my $plugins = Koha::Plugins->new({ enable_plugins => 1 }); >- my @plugins = $plugins->InstallPlugins; >+ my @plugins; >+ >+ warnings_are >+ { @plugins = $plugins->InstallPlugins; } >+ [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall", >+ "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ]; >+ > foreach my $plugin (@plugins) { > $plugin->enable(); > } >@@ -104,11 +111,17 @@ subtest 'more call() tests' => sub { > # Barcode is multiplied by 2 by Koha::Plugin::Test, and again by 4 by Koha::Plugin::TestItemBarcodeTransform > # showing that call has passed the same ref to multiple plugins to operate on > my $bc = 1; >- Koha::Plugins->call('item_barcode_transform', \$bc); >+ warnings_are >+ { Koha::Plugins->call('item_barcode_transform', \$bc); } >+ [ 'Plugin error (Test Plugin): item_barcode_transform called with parameter: 1', >+ 'Plugin error (Test Plugin for item_barcode_transform): item_barcode_transform called with parameter: 2' ]; > is( $bc, 8, "Got expected response" ); > > my $cn = 'abcd'; >- Koha::Plugins->call('item_barcode_transform', \$cn); >+ warnings_are >+ { Koha::Plugins->call('item_barcode_transform', \$bc); } >+ [ 'Plugin error (Test Plugin): item_barcode_transform called with parameter: 8', >+ 'Plugin error (Test Plugin for item_barcode_transform): item_barcode_transform called with parameter: 16' ]; > is( $cn, 'abcd', "Got expected response" ); > > t::lib::Mocks::mock_config('enable_plugins', 0); >-- >2.32.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 28211
:
120120
|
120875
|
120882
|
120883
|
122425
|
122426
|
122427
|
125892
|
125926
|
125927
|
125928
|
126274
|
126471
| 126497