Bugzilla – Attachment 110262 Details for
Bug 25265
Elasticsearch - Batch editing items on a biblio can lead to incorrect index
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25265: Unit tests
Bug-25265-Unit-tests.patch (text/plain), 6.53 KB, created by
Nick Clemens (kidclamp)
on 2020-09-17 12:56:47 UTC
(
hide
)
Description:
Bug 25265: Unit tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2020-09-17 12:56:47 UTC
Size:
6.53 KB
patch
obsolete
>From 225ac8388a2088a9104fa06c4c5139556f188143 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 17 Sep 2020 11:43:44 +0000 >Subject: [PATCH] Bug 25265: Unit tests > >These cover Koha::SearchEngine::Indexer and ensure that all calls in the code >are routed correctly to the expected search engine >--- > t/db_dependent/Koha/SearchEngine/Indexer.t | 139 +++++++++++++++++++++++++++++ > 1 file changed, 139 insertions(+) > create mode 100755 t/db_dependent/Koha/SearchEngine/Indexer.t > >diff --git a/t/db_dependent/Koha/SearchEngine/Indexer.t b/t/db_dependent/Koha/SearchEngine/Indexer.t >new file mode 100755 >index 0000000000..fa245f8880 >--- /dev/null >+++ b/t/db_dependent/Koha/SearchEngine/Indexer.t >@@ -0,0 +1,139 @@ >+#!/usr/bin/perl >+ >+# Tests for Koha/SearchEngine/Search >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::Warn; >+ >+use MARC::Field; >+use MARC::Record; >+use Test::MockModule; >+use Test::MockObject; >+ >+use t::lib::Mocks; >+ >+#use C4::Biblio qw//; >+use C4::AuthoritiesMarc; >+use C4::Biblio; >+use C4::Circulation; >+use Koha::Database; >+use Koha::SearchEngine::Indexer; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+# t::lib::Mocks::mock_preference('IndependentBranches', 1); >+# my $module = Test::MockModule->new('C4::Items'); >+# $module->mock( GetAnalyticsCount => sub { return 1 } ); >+# my $biblio = $builder->build_sample_biblio; >+ >+$schema->storage->txn_begin; >+ >+subtest 'Test indexer object creation' => sub { >+ plan tests => 6; >+ >+ t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); >+ my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Zebra::Indexer', 'We get the correct class for Zebra biblios'); >+ $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Zebra::Indexer', 'We get the correct class for Zebra authorities'); >+ >+ t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); >+ $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Elasticsearch::Indexer', 'We get the correct class for Elasticsearch biblios'); >+ ok( $indexer->index_name =~ /biblios$/, "The index is set correctly for biblios"); >+ $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Elasticsearch::Indexer', 'We get the correct class for Elasticsearch authorities'); >+ ok( $indexer->index_name =~ /authorities$/, "The index is set correctly for authorities"); >+}; >+ >+subtest 'Test indexer calls' => sub { >+ plan tests => 22; >+ >+ for my $engine ( ('Zebra','Elasticsearch') ){ >+ t::lib::Mocks::mock_preference( 'SearchEngine', $engine ); >+ my $mock_index = Test::MockModule->new("Koha::SearchEngine::".$engine."::Indexer"); >+ >+ my $biblionumber1 = $builder->build_sample_biblio()->biblionumber; >+ my $biblionumber2 = $builder->build_sample_biblio()->biblionumber; >+ >+ my $mock_zebra = Test::MockModule->new("Koha::SearchEngine::Zebra::Indexer"); >+ $mock_zebra->mock( ModZebra => sub { warn "ModZebra"; } ); >+ my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ warnings_are{ >+ $indexer->index_records([$biblionumber1,$biblionumber1],"specialUpdate","biblioserver",undef); >+ } ["ModZebra","ModZebra"],"ModZebra called for each record being indexed for $engine"; >+ >+ $mock_index->mock( index_records => sub { >+ warn $engine; >+ my ($package, undef, undef) = caller; >+ warn $package; >+ }); >+ >+ my $auth = MARC::Record->new; >+ my $authid; >+ warnings_are{ >+ $authid = AddAuthority( $auth, undef, 'TOPIC_TERM' ); >+ } [$engine,"C4::AuthoritiesMarc"], "index_records is called for $engine is called when adding authority"; >+ >+ warnings_are{ >+ $authid = DelAuthority({ authid => $authid }); >+ } [$engine,"C4::AuthoritiesMarc"], "index_records is called for $engine is called when adding authority"; >+ >+ my $biblio; >+ my $biblio2; >+ warnings_are{ >+ $biblio = $builder->build_sample_biblio(); >+ $biblio2 = $builder->build_sample_biblio(); >+ } [$engine,'C4::Biblio',$engine,'C4::Biblio'], "index_records is called for $engine when adding a biblio (ModBiblioMarc)"; >+ >+ >+ my $item; >+ my $item2; >+ warnings_are{ >+ $item = $builder->build_sample_item({biblionumber => $biblio->biblionumber}); >+ $item2 = $builder->build_sample_item({biblionumber => $biblio->biblionumber}); >+ } [$engine,"Koha::Item",$engine,"Koha::Item"], "index_records is called for $engine when adding an item (Item->store)"; >+ warnings_are{ >+ $item->store({ skip_modzebra_update => 1 }); >+ } undef, "index_records is not called for $engine when adding an item (Item->store) if skip_modzebra_update passed"; >+ >+ $builder->build({ >+ source => 'Branchtransfer', >+ value => { >+ itemnumber => $item->itemnumber, >+ datearrived => undef} >+ }); >+ warnings_are{ >+ LostItem( $item->itemnumber, "tests"); >+ } [$engine,"Koha::Item"], "index_records is called for $engine when calling LostItem and transfer exists"; >+ $builder->build({ >+ source => 'Branchtransfer', >+ value => { >+ itemnumber => $item2->itemnumber, >+ datearrived => undef} >+ }); >+ warnings_are{ >+ LostItem( $item->itemnumber, "tests", undef, { skip_modzebra_update => 1 }); >+ } undef, "index_records is not called for $engine when calling LostItem and transfer exists if skip_modzebra_update"; >+ >+ warnings_are{ >+ $item->delete(); >+ } [$engine,"Koha::Item"], "index_records is called for $engine when deleting an item (Item->delete)"; >+ warnings_are{ >+ $item2->delete({ skip_modzebra_update => 1 }); >+ } undef, "index_records is not called for $engine when adding an item (Item->store) if skip_modzebra_update passed"; >+ >+ warnings_are{ >+ DelBiblio( $biblio->biblionumber ); >+ } [$engine, "C4::Biblio"], "index_records is called for $engine when callind DelBiblio"; >+ >+ } >+ >+}; >+ >+$schema->storage->txn_rollback; >-- >2.11.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 25265
:
107832
|
107855
|
107867
|
109538
|
109556
|
110262
|
110263
|
110264
|
110380
|
110381
|
110382
|
110457
|
110458
|
110459
|
110560
|
110561
|
110562
|
110565
|
110594
|
110595
|
110596
|
110597
|
110615
|
110618
|
110729
|
110730
|
110731
|
110732
|
110733
|
110734
|
110736
|
110737
|
110882
|
110883
|
110937