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 <black23@gmail.com>
Rebased-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Ere Maijala 2020-11-09 14:28:16 +02:00 committed by Jonathan Druart
parent 2615ee1010
commit 4da161d05a
3 changed files with 74 additions and 3 deletions

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 14;
use Test::More tests => 15;
use C4::Biblio qw( AddBiblio ModBiblio );
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;
};

View File

@ -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;

View File

@ -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 => {