From 5037af4301bed6d7658cb56a86903756ef60e3df 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Rebased-by: Joonas Kylmälä Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Biblio.t | 24 +++++++++++- t/db_dependent/Koha/Item.t | 43 +++++++++++++++++++++- t/db_dependent/Koha/SearchEngine/Indexer.t | 10 ++++- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index e7ecb4f3f5..6e999c961f 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; @@ -637,3 +637,25 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { $schema->storage->txn_rollback; }; + +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 737f78e544..b4fbc5341f 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -817,8 +817,49 @@ subtest 'get_transfers' => 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 afb465964d..47c3910864 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"); @@ -170,6 +172,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 => 'Issue', value => { -- 2.20.1