Bugzilla – Attachment 117868 Details for
Bug 27066
Implement hooks for patrons updates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27066: Unit tests for after_patron_action hook
Bug-27066-Unit-tests-for-afterpatronaction-hook.patch (text/plain), 3.35 KB, created by
Fridolin Somers
on 2021-03-05 15:44:17 UTC
(
hide
)
Description:
Bug 27066: Unit tests for after_patron_action hook
Filename:
MIME Type:
Creator:
Fridolin Somers
Created:
2021-03-05 15:44:17 UTC
Size:
3.35 KB
patch
obsolete
>From c68f0f5208a9329cd6d8f5ad29d173d423d12ca4 Mon Sep 17 00:00:00 2001 >From: Maryse Simard <maryse.simard@inlibro.com> >Date: Fri, 29 Jan 2021 01:21:15 -0500 >Subject: [PATCH] Bug 27066: Unit tests for after_patron_action hook > >Adds unit tests for the new hook. > >To test: > prove -v t/db_dependent/Koha/Plugins/Patron.t > >Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> >--- > t/db_dependent/Koha/Plugins/Patron.t | 42 +++++++++++++++++++++++++++- > t/lib/Koha/Plugin/Test.pm | 17 +++++++++++ > 2 files changed, 58 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Plugins/Patron.t b/t/db_dependent/Koha/Plugins/Patron.t >index c8b2e86f25..fa619e93be 100755 >--- a/t/db_dependent/Koha/Plugins/Patron.t >+++ b/t/db_dependent/Koha/Plugins/Patron.t >@@ -16,8 +16,9 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > use Test::Exception; >+use Test::Warn; > > use File::Basename; > >@@ -91,4 +92,43 @@ subtest 'check_password hook tests' => sub { > Koha::Plugins::Methods->delete; > }; > >+subtest 'after_patron_action hook tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $plugins = Koha::Plugins->new; >+ $plugins->InstallPlugins; >+ >+ my $plugin = Koha::Plugin::Test->new->enable; >+ >+ ok( $plugin->can('after_patron_action'), 'Test plugin can after_patron_action' ); >+ >+ my $library = $builder->build( { source => 'Branch' } ); >+ my $category = $builder->build( { source => 'Category' } ); >+ my $patron = Koha::Patron->new( >+ { >+ cardnumber => 'test_cn_after_patron_action', # Only this cardnumber is set to react to after_patron_action hook >+ branchcode => $library->{branchcode}, >+ categorycode => $category->{categorycode}, >+ } >+ ); >+ >+ warning_like { $patron->store->discard_changes; } >+ qr/after_patron_action called with action: create, ref: Koha::Patron/, >+ 'Koha::Patron->store calls the hook with action=create'; >+ >+ warning_like { $patron->store; } >+ qr/after_patron_action called with action: modify, ref: Koha::Patron/, >+ 'If patron exists, Koha::Patron->store calls the hook with action=modify'; >+ >+ warning_like { $patron->delete; } >+ qr/after_patron_action called with action: delete/, >+ 'Koha::Patron->delete calls the hook with action=delete'; >+ >+ $schema->storage->txn_rollback; >+ Koha::Plugins::Methods->delete; >+}; >+ > 1; >diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm >index 0a92967738..52d465bc1e 100644 >--- a/t/lib/Koha/Plugin/Test.pm >+++ b/t/lib/Koha/Plugin/Test.pm >@@ -164,6 +164,23 @@ sub after_item_action { > } > } > >+sub after_patron_action { >+ my ( $self, $params ) = @_; >+ my $action = $params->{action} // ''; >+ my $patron = $params->{patron}; >+ my $patron_id = $params->{patron_id}; >+ >+ # Continue only when testing after_patron_action hook >+ return unless (defined $patron->cardnumber && $patron->cardnumber eq "test_cn_after_patron_action"); >+ >+ if ( $action ne 'delete' ) { >+ Koha::Exceptions::Exception->throw("after_patron_action called with action: $action, ref: " . ref($patron) ); >+ } >+ else { >+ Koha::Exceptions::Exception->throw("after_patron_action called with action: $action") if $patron_id; >+ } >+} >+ > sub after_circ_action { > my ( $self, $params ) = @_; > >-- >2.30.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 27066
:
116007
|
116008
|
117867
| 117868