Bugzilla – Attachment 140056 Details for
Bug 25375
Elasticsearch: Limit on available items does not work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25375: Add tests for the "available" ES field
Bug-25375-Add-tests-for-the-available-ES-field.patch (text/plain), 5.62 KB, created by
Joonas Kylmälä
on 2022-09-01 18:00:42 UTC
(
hide
)
Description:
Bug 25375: Add tests for the "available" ES field
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2022-09-01 18:00:42 UTC
Size:
5.62 KB
patch
obsolete
>From 4234be3e8fd4ed10a42e7592a74d2767e7c3b030 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 3 Mar 2022 11:18:25 +0100 >Subject: [PATCH] Bug 25375: Add tests for the "available" ES field >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> > >Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> >--- > Koha/SearchEngine/Elasticsearch.pm | 24 ++++---- > .../Koha/SearchEngine/Elasticsearch.t | 61 ++++++++++++++++++- > 2 files changed, 73 insertions(+), 12 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index 20462ccd03..b2273c5ace 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -776,17 +776,19 @@ sub marc_records_to_documents { > if ($self->index eq $BIBLIOS_INDEX) { > my ($tag, $code) = C4::Biblio::GetMarcFromKohaField('biblio.biblionumber'); > my $field = $record->field($tag); >- my $biblionumber = $field->is_control_field ? $field->data : $field->subfield($code); >- my $avail_items = Koha::Items->search({ >- biblionumber => $biblionumber, >- onloan => undef, >- notforloan => 0, >- withdrawn => 0, >- itemlost => 0, >- damaged => 0 >- })->count; >- >- $record_document->{available} = $avail_items ? \1 : \0; >+ if ($field) { >+ my $biblionumber = $field->is_control_field ? $field->data : $field->subfield($code); >+ my $avail_items = Koha::Items->search({ >+ biblionumber => $biblionumber, >+ onloan => undef, >+ notforloan => 0, >+ withdrawn => 0, >+ itemlost => 0, >+ damaged => 0 >+ })->count; >+ >+ $record_document->{available} = $avail_items ? \1 : \0; >+ } > } > > push @record_documents, $record_document; >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t >index 0509328135..d0a11d924d 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > use Test::Exception; > > use t::lib::Mocks; >@@ -30,6 +30,7 @@ use Try::Tiny; > use List::Util qw( any ); > > use C4::AuthoritiesMarc qw( AddAuthority ); >+use C4::Biblio; > > use Koha::SearchEngine::Elasticsearch; > use Koha::SearchEngine::Elasticsearch::Search; >@@ -972,4 +973,62 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents with Inclu > is_deeply($docs->[0]->{subject__sort}, ['Foo'], 'subject__sort should not include "See from"'); > }; > >+subtest 'marc_records_to_documents should set the "available" field' => sub { >+ plan tests => 8; >+ >+ t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); >+ my $dbh = C4::Context->dbh; >+ >+ my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); >+ $se->noop('_foreach_mapping'); >+ >+ my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); >+ >+ # sort_fields will call this and use the actual db values unless we call it first >+ $see->get_elasticsearch_mappings(); >+ >+ my $marc_record_1 = MARC::Record->new(); >+ $marc_record_1->leader(' cam 22 a 4500'); >+ $marc_record_1->append_fields( >+ MARC::Field->new('245', '', '', a => 'Title'), >+ ); >+ my ($biblionumber) = C4::Biblio::AddBiblio($marc_record_1, '', { defer_marc_save => 1 }); >+ >+ my $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \0, 'a biblio without items is not available'); >+ >+ my $item = Koha::Item->new({ >+ biblionumber => $biblionumber, >+ })->store(); >+ >+ $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \1, 'a biblio with one item that has no particular status is available'); >+ >+ $item->notforloan(1)->store(); >+ $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is "notforloan" is not available'); >+ >+ $item->set({ notforloan => 0, onloan => '2022-03-03' })->store(); >+ $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is on loan is not available'); >+ >+ $item->set({ onloan => undef, withdrawn => 1 })->store(); >+ $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is withdrawn is not available'); >+ >+ $item->set({ withdrawn => 0, itemlost => 1 })->store(); >+ $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is lost is not available'); >+ >+ $item->set({ itemlost => 0, damaged => 1 })->store(); >+ $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is damaged is not available'); >+ >+ my $item2 = Koha::Item->new({ >+ biblionumber => $biblionumber, >+ })->store(); >+ $docs = $see->marc_records_to_documents([$marc_record_1]); >+ is_deeply($docs->[0]->{available}, \1, 'a biblio with at least one item that has no particular status is available'); >+}; >+ > $schema->storage->txn_rollback; >-- >2.30.2
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 25375
:
104356
|
109647
|
109659
|
109660
|
109951
|
109952
|
109953
|
109954
|
131310
|
131311
|
131312
|
131313
|
132327
|
132328
|
132329
|
132330
|
138800
|
138802
|
138803
|
140053
|
140054
|
140055
| 140056 |
140057
|
140572
|
140899
|
140900
|
140979