Bugzilla – Attachment 163325 Details for
Bug 34943
Add a pre-save plugin hook for biblios
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34943: Unit tests
Bug-34943-Unit-tests.patch (text/plain), 3.44 KB, created by
Martin Renvoize (ashimema)
on 2024-03-18 13:26:12 UTC
(
hide
)
Description:
Bug 34943: Unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-03-18 13:26:12 UTC
Size:
3.44 KB
patch
obsolete
>From 1a33754d58df3b2d14a9d10082ea2dcb6955147c Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 8 Dec 2023 17:23:44 -0300 >Subject: [PATCH] Bug 34943: Unit tests > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > .../Plugins/Biblio_and_Items_plugin_hooks.t | 53 ++++++++++++++++++- > t/lib/plugins/Koha/Plugin/Test.pm | 14 +++++ > 2 files changed, 66 insertions(+), 1 deletion(-) > >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 4f29aae60f5..cd4d61c530c 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 >@@ -16,11 +16,12 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; > use Test::Warn; > > use File::Basename; > >+use C4::Biblio qw(AddBiblio ModBiblio); > use C4::Items; > > use t::lib::Mocks; >@@ -86,3 +87,53 @@ subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { > $schema->storage->txn_rollback; > Koha::Plugins::Methods->delete; > }; >+ >+subtest 'before_biblio_metadata_store() hooks tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $plugins = Koha::Plugins->new; >+ $plugins->InstallPlugins; >+ >+ my $plugin = Koha::Plugin::Test->new->enable; >+ >+ my $subfield_contents = 'Arte club'; >+ >+ my $test_plugin = Test::MockModule->new('Koha::Plugin::Test'); >+ $test_plugin->mock( 'after_biblio_action', undef ); >+ >+ # Defaults to avoid noise >+ my $options = { >+ disable_autolink => 1, >+ skip_holds_queue => 1, >+ skip_record_index => 1, >+ }; >+ >+ # Add a record >+ my ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); >+ >+ my $record = Koha::Biblios->find($biblio_id)->metadata->record; >+ >+ my @fields_990 = $record->field('990'); >+ >+ is( scalar @fields_990, 1, 'One field added' ); >+ is( $fields_990[0]->subfield('a'), $subfield_contents ); >+ >+ # Simulate editing the record >+ ModBiblio( $record, $biblio_id, '', $options ); >+ >+ $record = Koha::Biblios->find($biblio_id)->record; >+ >+ @fields_990 = $record->field('990'); >+ # This is to highlight that is the plugin responsibility to choose what to do on the record >+ is( scalar @fields_990, 2, 'Two saves, two fields' ); >+ >+ foreach my $index (qw(0 1)) { >+ is( $fields_990[$index]->subfield('a'), $subfield_contents ); >+ } >+ >+ $schema->storage->txn_rollback; >+ Koha::Plugins::Methods->delete; >+}; >diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm >index 32f7dedb489..cb45dd6e5c5 100644 >--- a/t/lib/plugins/Koha/Plugin/Test.pm >+++ b/t/lib/plugins/Koha/Plugin/Test.pm >@@ -6,6 +6,7 @@ use Modern::Perl; > use Koha::Exception; > use Koha::Plugins::Tab; > >+use MARC::Field; > use Mojo::JSON qw( decode_json ); > > ## Required for all plugins >@@ -148,6 +149,19 @@ sub after_hold_create { > Koha::Exception->throw("after_hold_create called with parameter " . ref($param) ); > } > >+sub before_biblio_metadata_store { >+ my ( $self, $record ) = @_; >+ >+ $record->insert_fields_ordered( >+ MARC::Field->new( >+ '990', '', '', >+ 'a' => 'Arte club' >+ ) >+ ); >+ >+ return $record; >+} >+ > sub after_biblio_action { > my ( $self, $params ) = @_; > my $action = $params->{action} // ''; >-- >2.44.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 34943
:
159680
|
159681
|
159682
|
159683
|
159684
|
159685
|
159686
|
159687
|
159690
|
159691
|
161695
|
161696
|
163048
|
163325
|
163326
|
163327
|
163711
|
163712
|
163713