From a996585ef677b7f7b943fcbde6bb248274427df5 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 9 Nov 2020 14:28:16 +0200 Subject: [PATCH] Bug 22690: Add more tests - Tests for adopt_items_from_biblio - Tests for the relationship between items and acquisition orders - Tests for indexer calls in adopt_items_from_biblio Signed-off-by: Michal Denar --- t/db_dependent/Koha/Biblio.t | 22 ++++++++++- t/db_dependent/Koha/Item.t | 43 +++++++++++++++++++++- t/db_dependent/Koha/SearchEngine/Indexer.t | 10 ++++- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index c96f5c2d41..c789dcc3a7 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 14; +use Test::More tests => 15; use C4::Biblio; use Koha::Database; @@ -607,6 +607,26 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); is( @$notes, 2, 'No more notes' ); +}; + +subtest 'adopt_items_from_biblio() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $biblio1 = $builder->build_sample_biblio; + my $biblio2 = $builder->build_sample_biblio; + my $item1 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber }); + my $item2 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber }); + + $biblio2->adopt_items_from_biblio($biblio1); + + $item1->discard_changes; + $item2->discard_changes; + + is($item1->biblionumber, $biblio2->biblionumber, "Item 1 moved"); + is($item2->biblionumber, $biblio2->biblionumber, "Item 2 moved"); $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 59fa4ddcde..dd7939ff53 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -692,8 +692,49 @@ subtest 'Tests for itemtype' => sub { $schema->storage->txn_rollback; }; -subtest 'move_to_biblio() tests' => sub { +subtest 'Tests for relationship between item and item_orders via aqorders_item' => sub { + plan tests => 2; + + my $biblio = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); + my $aq_budget = $builder->build({ + source => 'Aqbudget', + value => { + budget_notes => 'test', + }, + }); + + my $order_note = 'Order for ' . $item->itemnumber; + + my $aq_order1 = $builder->build_object({ + class => 'Koha::Acquisition::Orders', + value => { + biblionumber => $biblio->biblionumber, + budget_id => $aq_budget->{budget_id}, + order_internalnote => $order_note, + }, + }); + my $aq_order2 = $builder->build_object({ + class => 'Koha::Acquisition::Orders', + value => { + biblionumber => $biblio->biblionumber, + budget_id => $aq_budget->{budget_id}, + }, + }); + my $aq_order_item1 = $builder->build({ + source => 'AqordersItem', + value => { + ordernumber => $aq_order1->ordernumber, + itemnumber => $item->itemnumber, + }, + }); + + my $orders = $item->item_orders; + is ($orders->count, 1, 'One order found by item with the relationship'); + is ($orders->next->order_internalnote, $order_note, 'Correct order found by item with the relationship'); +}; +subtest 'move_to_biblio() tests' => sub { plan tests => 16; $schema->storage->txn_begin; diff --git a/t/db_dependent/Koha/SearchEngine/Indexer.t b/t/db_dependent/Koha/SearchEngine/Indexer.t index 85489c068c..68a64465d9 100755 --- a/t/db_dependent/Koha/SearchEngine/Indexer.t +++ b/t/db_dependent/Koha/SearchEngine/Indexer.t @@ -61,7 +61,7 @@ subtest 'Test indexer object creation' => sub { }; subtest 'Test indexer calls' => sub { - plan tests => 44; + plan tests => 46; my @engines = ('Zebra'); eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; }; @@ -71,6 +71,8 @@ subtest 'Test indexer calls' => sub { if scalar @engines == 1; } + t::lib::Mocks::mock_preference( 'BiblioAddsAuthorities', 0 ); + for my $engine ( @engines ){ t::lib::Mocks::mock_preference( 'SearchEngine', $engine ); my $mock_index = Test::MockModule->new("Koha::SearchEngine::".$engine."::Indexer"); @@ -168,6 +170,12 @@ subtest 'Test indexer calls' => sub { $item4->move_to_biblio($biblio2, { skip_record_index => 1 }); } undef, "index_records is not called for $engine when moving an item to another biblio (Item->move_to_biblio) if skip_record_index passed"; + my $item5 = $builder->build_sample_item({biblionumber => $biblio->biblionumber}); + my $item6 = $builder->build_sample_item({biblionumber => $biblio->biblionumber}); + warnings_are{ + $biblio2->adopt_items_from_biblio($biblio); + } [$engine,"Koha::Biblio",$engine,"Koha::Biblio"], "index_records is called for both biblios for $engine when adopting items (Biblio->adopt_items_from_biblio)"; + $builder->build( { source => 'Branchtransfer', -- 2.25.1