Bugzilla – Attachment 163943 Details for
Bug 36433
Plugin hook elasticsearch_to_document
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36433: UT
Bug-36433-UT.patch (text/plain), 3.27 KB, created by
Frédéric Demians
on 2024-03-26 17:24:23 UTC
(
hide
)
Description:
Bug 36433: UT
Filename:
MIME Type:
Creator:
Frédéric Demians
Created:
2024-03-26 17:24:23 UTC
Size:
3.27 KB
patch
obsolete
>From 76e8990d55e62efa118c40266990fba72e6b8a64 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= <f.demians@tamil.fr> >Date: Tue, 26 Mar 2024 18:12:45 +0100 >Subject: [PATCH] Bug 36433: UT > >--- > .../Plugins/Biblio_and_Items_plugin_hooks.t | 46 ++++++++++++++++++- > t/lib/plugins/Koha/Plugin/Test.pm | 9 ++++ > 2 files changed, 54 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 4464fb407a..10de3d8fa8 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,7 +16,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > use Test::Warn; > > use File::Basename; >@@ -137,3 +137,47 @@ subtest 'before_biblio_action() hooks tests' => sub { > $schema->storage->txn_rollback; > Koha::Plugins::Methods->delete; > }; >+ >+subtest 'elasticsearch_to_document() hooks tests' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $plugins = Koha::Plugins->new; >+ $plugins->InstallPlugins; >+ >+ my $plugin = Koha::Plugin::Test->new->enable; >+ >+ my $test_plugin1 = Test::MockModule->new('Koha::Plugin::Test'); >+ $test_plugin1->mock( 'after_biblio_action', undef ); >+ >+ # Create a record >+ my $record = MARC::Record->new(); >+ $record->append_fields( MARC::Field->new('009', '123456789') ); >+ >+ my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ my $documents; >+ warning_like { $documents = $indexer->marc_records_to_documents([$record]); } >+ qr/elasticsearch_to_document ref record: MARC::Record - ref document: HASH/, >+ 'ES marc_records_to_document calls the hook'; >+ >+ my $test_plugin2 = Test::MockModule->new('Koha::Plugin::Test'); >+ $test_plugin2->mock( 'after_biblio_action', undef ); >+ >+ # Create an ES search field 'ppn' and populate it with 009 field >+ $test_plugin2->mock( 'elasticsearch_to_document', sub { >+ my ($self, $params) = @_; >+ my $record = $params->{record}; >+ my $document = $params->{document}; >+ my $value = $record->field('009')->data; >+ $document->{ppn} = [$value]; >+ }); >+ $documents = $indexer->marc_records_to_documents([$record]); >+ ok(ref($documents) eq 'ARRAY', 'Indexer marc_records_to_documents returns an ARRAY'); >+ ok(scalar(@$documents) == 1, 'This array contains one (1) document'); >+ ok(ref($documents->[0]) eq 'HASH', 'The document is a HASH'); >+ ok(exists($documents->[0]->{ppn}), 'Generated field ppn exists'); >+ ok($documents->[0]->{ppn}->[0] eq '123456789', 'Field ppn contains 123456789'); >+}; >+ >diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm >index 4154994984..fc200c60ed 100644 >--- a/t/lib/plugins/Koha/Plugin/Test.pm >+++ b/t/lib/plugins/Koha/Plugin/Test.pm >@@ -414,4 +414,13 @@ sub _private_sub { > return ""; > } > >+sub elasticsearch_to_document { >+ my ( $self, $params ) = @_; >+ my $record =$params->{record}; >+ my $doc = $params->{document}; >+ >+ Koha::Exception->throw( >+ "elasticsearch_to_document ref record: " . ref($record) . " - ref document: " . ref($doc) ); >+} >+ > 1; >-- >2.34.1
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 36433
:
163943
|
163944
|
163962
|
163963
|
172062
|
172063
|
176749
|
176750
|
178685
|
178778