X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=t%2Fdb_dependent%2FKoha%2FItem.t;h=6f9d7cefd77b9d99403678518e67559d5c14f4c9;hb=de362442661cc5c2e66bd090a2eda474c19b2efb;hp=d9252ef3d8f2f0aadf16aea390ef56c7bfee09fe;hpb=f781fdb4a231e074b36099d0a724fad576518921;p=srvgit diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index d9252ef3d8..6f9d7cefd7 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -213,12 +213,17 @@ subtest 'bundle_host tests' => sub { }; subtest 'add_to_bundle tests' => sub { - plan tests => 6; + plan tests => 7; $schema->storage->txn_begin; t::lib::Mocks::mock_preference( 'BundleNotLoanValue', 1 ); + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + t::lib::Mocks::mock_userenv({ + branchcode => $library->branchcode + }); + my $host_item = $builder->build_sample_item(); my $bundle_item1 = $builder->build_sample_item(); my $bundle_item2 = $builder->build_sample_item(); @@ -242,6 +247,26 @@ subtest 'add_to_bundle tests' => sub { 'Koha::Exceptions::Item::Bundle::IsBundle', 'Exception thrown if you try to add a bundle host to a bundle item'; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + C4::Circulation::AddIssue( $patron->unblessed, $bundle_item2->barcode ); + throws_ok { $host_item->add_to_bundle($bundle_item2) } + 'Koha::Exceptions::Item::Bundle::ItemIsCheckedOut', + 'Exception thrown if you try to add a checked out item'; + + $bundle_item2->withdrawn(1)->store; + t::lib::Mocks::mock_preference( 'BlockReturnOfWithdrawnItems', 1 ); + throws_ok { $host_item->add_to_bundle( $bundle_item2, { force_checkin => 1 } ) } + 'Koha::Exceptions::Checkin::FailedCheckin', + 'Exception thrown if you try to add a checked out item using + "force_checkin" and the return is not possible'; + + $bundle_item2->withdrawn(0)->store; + lives_ok { $host_item->add_to_bundle( $bundle_item2, { force_checkin => 1 } ) } + 'No exception if you try to add a checked out item using "force_checkin" and the return is possible'; + + $bundle_item2->discard_changes; + ok( !$bundle_item2->checkout, 'Item is not checked out after being added to a bundle' ); + $schema->storage->txn_rollback; };