From ecb95278b17c483f39bb43b376519fe5dc0ea3bb 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 --- t/db_dependent/Koha/Items.t | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index aa3e0d4a0a4..6f78d9f4cad 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; @@ -2345,3 +2345,38 @@ 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