From e3f6fa45da2a5e8ce337be14bc6058780d41761e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 4 Dec 2019 18:38:22 +0000 Subject: [PATCH] Bug 24175: [19.05.x] Unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonathan Druart Signed-off-by: Joonas Kylmälä Signed-off-by: Martin Renvoize Bug 24175: Simplify tests Signed-off-by: Jonathan Druart Signed-off-by: Joonas Kylmälä Signed-off-by: Martin Renvoize Bug 24175: [19.05.x] Remove use of Koha::Item::Holds --- t/db_dependent/SIP/Transaction.t | 51 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index 076fb29c35..6a79a00767 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -4,7 +4,7 @@ # Current state is very rudimentary. Please help to extend it! use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Koha::Database; use t::lib::TestBuilder; @@ -12,6 +12,7 @@ use t::lib::Mocks; use C4::SIP::ILS::Patron; use C4::SIP::ILS::Transaction::RenewAll; use C4::SIP::ILS::Transaction::Checkout; +use C4::SIP::ILS::Transaction::Hold; use C4::Reserves; use Koha::IssuingRules; @@ -95,4 +96,52 @@ subtest fill_holds_at_checkout => sub { $transaction = C4::SIP::ILS::Transaction::Checkout->new(); is( $sip_item->{barcode}, $item1->{barcode}, "Item assigned to transaction" ); }; + +subtest cancel_hold => sub { + plan tests => 7; + + my $library = $builder->build_object ({ class => 'Koha::Libraries' }); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } + } + ); + t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 }); + + my $item = $builder->build_sample_item({ + library => $library->branchcode, + }); + + Koha::IssuingRule->new({ + categorycode => $patron->categorycode, + itemtype => $item->effective_itemtype, + branchcode => $library->branchcode, + onshelfholds => 1, + reservesallowed => 3, + holds_per_record => 3, + issuelength => 5, + lengthunit => 'days', + })->store; + + my $reserve1 = + AddReserve( $library->branchcode, $patron->borrowernumber, + $item->biblio->biblionumber, + undef, undef, undef, undef, undef, undef, $item->itemnumber ); + is( $item->biblio->holds->count(), 1, "Hold was placed on bib"); + is( Koha::Holds->search({itemnumber=>$item->itemnumber})->count() ,1,"Hold was placed on specific item"); + + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); + my $transaction = C4::SIP::ILS::Transaction::Hold->new(); + is( ref $transaction, "C4::SIP::ILS::Transaction::Hold", "New transaction created" ); + is( $transaction->patron( $sip_patron ), $sip_patron, "Patron assigned to transaction" ); + is( $transaction->item( $sip_item ), $sip_item, "Item assigned to transaction" ); + my $hold = $transaction->drop_hold(); + is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining"); + is( Koha::Holds->search({itemnumber=>$item->itemnumber})->count(), 0, "Item has 0 holds remaining"); +}; + $schema->storage->txn_rollback; -- 2.11.0