Browse Source

Bug 22690: (QA follow-up) Fix indexing for Items sets

This patch adds tests and handling for calling move_to_biblio on a
Koha::Items set that contains items from more than one source biblio.

Test plan
1/ Inspect the changes to t/db_dependent/Koha/SearchEngine/Indexer.t
2/ Run t/db_dependent/Koha/SearchEngine/Indexer.t and confirm it passes

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.11.x
Martin Renvoize 3 years ago
committed by Jonathan Druart
parent
commit
020b93bfc0
  1. 11
      Koha/Items.pm
  2. 22
      t/db_dependent/Koha/SearchEngine/Indexer.t

11
Koha/Items.pm

@ -121,12 +121,15 @@ Move items to a given biblio.
sub move_to_biblio {
my ( $self, $to_biblio ) = @_;
while (my $item = $self->next()) {
$item->move_to_biblio($to_biblio, { skip_record_index => 1 });
my $biblionumbers = { $to_biblio->biblionumber => 1 };
while ( my $item = $self->next() ) {
$biblionumbers->{ $item->biblionumber } = 1;
$item->move_to_biblio( $to_biblio, { skip_record_index => 1 } );
}
my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
$indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" );
$indexer->index_records( $to_biblio->biblionumber, "specialUpdate", "biblioserver" );
for my $biblionumber ( keys %{$biblionumbers} ) {
$indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
}
}

22
t/db_dependent/Koha/SearchEngine/Indexer.t

@ -61,7 +61,7 @@ subtest 'Test indexer object creation' => sub {
};
subtest 'Test indexer calls' => sub {
plan tests => 46;
plan tests => 48;
my @engines = ('Zebra');
eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; };
@ -105,11 +105,12 @@ subtest 'Test indexer calls' => sub {
my $biblio;
my $biblio2;
my $biblio3;
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)";
$biblio3 = $builder->build_sample_biblio();
} [$engine,'C4::Biblio',$engine,'C4::Biblio',$engine,'C4::Biblio'], "index_records is called for $engine when adding a biblio (ModBiblioMarc)";
my $item;
my $item2;
@ -132,8 +133,8 @@ subtest 'Test indexer calls' => sub {
});
$item3 = $builder->build_sample_item({biblionumber => $biblio->biblionumber});
$item4 = $builder->build_sample_item({biblionumber => $biblio->biblionumber});
$item5 = $builder->build_sample_item({biblionumber => $biblio->biblionumber});
$item6 = $builder->build_sample_item({biblionumber => $biblio->biblionumber});
$item5 = $builder->build_sample_item({biblionumber => $biblio3->biblionumber});
$item6 = $builder->build_sample_item({biblionumber => $biblio3->biblionumber});
} [$engine,"Koha::Item",
$engine,"Koha::Item",
$engine,"Koha::Item",
@ -185,7 +186,12 @@ subtest 'Test indexer calls' => sub {
warnings_are{
$biblio->items->move_to_biblio($biblio2);
} [$engine,"Koha::Biblio",$engine,"Koha::Biblio"], "index_records is called for both biblios for $engine when adopting items (Biblio->items->move_to_biblio(Biblio)";
} [$engine,"Koha::Items",$engine,"Koha::Items"], "index_records is called for from and to biblios for $engine when adopting items (Biblio->items->move_to_biblio(Biblio)";
my $items = Koha::Items->search({ itemnumber => [ $item2->itemnumber, $item5->itemnumber, $item6->itemnumber ] });
warnings_are{
$items->move_to_biblio($biblio);
} [$engine,"Koha::Items",$engine,"Koha::Items",$engine,"Koha::Items"], "index_records is called for all from and to biblios for $engine when adopting items (Items->move_to_biblio(Biblio)";
$builder->build({
source => 'Issue',
@ -231,10 +237,10 @@ subtest 'Test indexer calls' => sub {
} undef, "index_records is not called for $engine when adding an item (Item->store) if skip_record_index passed";
warnings_are{
DelBiblio( $biblio->biblionumber );
DelBiblio( $biblio3->biblionumber );
} [$engine, "C4::Biblio"], "index_records is called for $engine when calling DelBiblio";
warnings_are{
DelBiblio( $biblio->biblionumber, { skip_record_index =>1 });
DelBiblio( $biblio3->biblionumber, { skip_record_index =>1 });
} undef, "index_records is not called for $engine when calling DelBiblio if skip_record_index passed";
}

Loading…
Cancel
Save