From 99a640fd75118475f5443093a3b815e3ce148b8f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 15 Sep 2020 16:21:33 -0300 Subject: [PATCH] Bug 26470: Regression tests This patch tweaks the test plugin so it composes an exception based on the fact that the hook was called with the item and item_id parameters defined. It then makes the tests expect a specific exception message with information about this. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t => FAIL: Tests fail! Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart --- t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t | 4 ++-- t/lib/Koha/Plugin/Test.pm | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 bfc83b3f16..44f68ee87f 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 @@ -64,11 +64,11 @@ subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { my $item; warning_like { $item = $builder->build_sample_item({ biblionumber => $biblio_id }); } - qr/after_item_action called with action: create, ref: Koha::Item/, + qr/after_item_action called with action: create, ref: Koha::Item item_id defined: yes itemnumber defined: yes/, 'AddItem calls the hook with action=create'; warning_like { $item->location('shelves')->store; } - qr/after_item_action called with action: modify, ref: Koha::Item/, + qr/after_item_action called with action: modify, ref: Koha::Item item_id defined: yes itemnumber defined: yes/, 'ModItem calls the hook with action=modify'; warning_like { $item->delete; } diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm index 06b24d619a..0a92967738 100644 --- a/t/lib/Koha/Plugin/Test.pm +++ b/t/lib/Koha/Plugin/Test.pm @@ -153,7 +153,11 @@ sub after_item_action { my $item_id = $params->{item_id}; if ( $action ne 'delete' ) { - Koha::Exceptions::Exception->throw("after_item_action called with action: $action, ref: " . ref($item) ); + my $itemnumber_defined = (defined $item->itemnumber) ? 'yes' : 'no'; + my $item_id_defined = (defined $item_id) ? 'yes' : 'no'; + Koha::Exceptions::Exception->throw("after_item_action called with action: $action, ref: " . ref($item) . " ". + "item_id defined: $item_id_defined ". + "itemnumber defined: $itemnumber_defined" ); } else { Koha::Exceptions::Exception->throw("after_item_action called with action: $action" ) if $item_id; -- 2.39.5