From 29128c77e6e28d1e042caaee0ba045800a0cbbb7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Dec 2023 10:00:25 +0100 Subject: [PATCH] Bug 33036: Improve merge_with tests Signed-off-by: Jonathan Druart --- t/db_dependent/Koha/Biblio.t | 39 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index b338c86fee8..f95ffc5525d 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -487,38 +487,33 @@ subtest 'to_api() tests' => sub { }; subtest 'merge of records' => sub { - plan tests => 3; + plan tests => 9; $schema->storage->txn_begin; - #Three biblio - my $biblio1 = $builder->build_sample_biblio( { title => 'Title number 1' } ); - my $biblio2 = $builder->build_sample_biblio( { title => 'Title number 2' } ); - my $biblio3 = $builder->build_sample_biblio( { title => 'Title number 3' } ); + # 3 items from 3 different biblio records + my $item1 = $builder->build_sample_item; + my $item2 = $builder->build_sample_item; + my $item3 = $builder->build_sample_item; - # One items each - my $item1_1 = $builder->build_sample_item( { biblionumber => $biblio1->biblionumber, barcode => 'bar11' } ); - my $item2_1 = $builder->build_sample_item( { biblionumber => $biblio2->biblionumber, barcode => 'bar22' } ); - my $item3_1 = $builder->build_sample_item( { biblionumber => $biblio3->biblionumber, barcode => 'bar33' } ); - my $results = ''; - my @to_merge = ( $biblio2->biblionumber, $biblio3->biblionumber ); + my $biblio1 = $item1->biblio; + my $biblio2 = $item2->biblio; + my $biblio3 = $item3->biblio; my $pre_merged_rs = Koha::Biblios->search( { biblionumber => [ $biblio1->biblionumber, $biblio2->biblionumber, $biblio3->biblionumber ] } ); is( $pre_merged_rs->count, 3, '3 biblios exist' ); - eval { $results = $biblio1->merge_with( \@to_merge ); }; - if ($@) { - is( 0, 1, "Not working. Error: " . $@ ); - } else { - my $items = $biblio1->items; - is( $items->count, 3, "After merge we have 3 items on first record" ); + warning_like { $biblio1->merge_with( [ $biblio2->biblionumber, $biblio3->biblionumber ] ) } q{}; + is( $biblio1->items->count, 3, "After merge we have 3 items on first record" ); - my $merged_rs = Koha::Biblios->search( - { biblionumber => [ $biblio1->biblionumber, $biblio2->biblionumber, $biblio3->biblionumber ] } ); - is( $merged_rs->count, 1, 'only 1 biblio left, the merged ones are gone' ); - } + is( ref( $biblio1->get_from_storage ), 'Koha::Biblio', 'biblio record 1 still exists' ); + is( $biblio2->get_from_storage, undef, 'biblio record 2 no longer exists' ); + is( $biblio3->get_from_storage, undef, 'biblio record 3 no longer exists' ); + + is( $item1->get_from_storage->biblionumber, $biblio1->biblionumber ); + is( $item2->get_from_storage->biblionumber, $biblio1->biblionumber ); + is( $item3->get_from_storage->biblionumber, $biblio1->biblionumber ); - #End work $schema->storage->txn_rollback; }; -- 2.34.1