From 489b281c17eb6a4ab0bd32130b5b4ff9c41de89d Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Mon, 13 Jan 2025 21:32:42 +0000 Subject: [PATCH] Bug 37334: filter_by_in_bundle tests Signed-off-by: Emmi Takkinen --- t/db_dependent/Koha/Items.t | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index bb672e04eab..691f8265070 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 23; +use Test::More tests => 24; use Test::MockModule; use Test::Exception; @@ -2546,3 +2546,35 @@ subtest 'filter_by_has_holds' => sub { $schema->storage->txn_rollback; }; + +subtest 'filter_by_in_bundle' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $library = $builder->build( { source => 'Branch' } ); + my $biblio = $builder->build_sample_biblio(); + + my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, } ); + my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, } ); + my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, } ); + + is( $biblio->items->filter_by_in_bundle->count, 0, "0 items in a bundle for this record" ); + + my $in_bundle = $item_1->in_bundle; + + my $host_item = $builder->build_sample_item(); + $schema->resultset('ItemBundle')->create( { host => $host_item->itemnumber, item => $item_1->itemnumber } ); + + $in_bundle = $item_1->in_bundle; + + is( $biblio->items->filter_by_in_bundle->count, 1, "1 item in a bundle for this record" ); + $schema->resultset('ItemBundle')->create( { host => $host_item->itemnumber, item => $item_2->itemnumber } ); + + $in_bundle = $item_2->in_bundle; + + is( $biblio->items->filter_by_in_bundle->count, 2, "2 items in a bundle for this record" ); + + $schema->storage->txn_rollback; + +}; -- 2.39.5