Bugzilla – Attachment 129405 Details for
Bug 29869
Add Koha::Hold->fill
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29869: Unit tests
Bug-29869-Unit-tests.patch (text/plain), 4.93 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-01-13 14:51:04 UTC
(
hide
)
Description:
Bug 29869: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-01-13 14:51:04 UTC
Size:
4.93 KB
patch
obsolete
>From 2b49534903a5ef7e84c266669b5809fdbe566e08 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 13 Jan 2022 09:03:04 -0300 >Subject: [PATCH] Bug 29869: Unit tests > >--- > t/db_dependent/Koha/Hold.t | 135 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 134 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 5f6a9016c8..01901f6cb9 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -19,18 +19,151 @@ > > use Modern::Perl; > >-use Test::More tests => 3; >+use Test::More tests => 4; > > use Test::Exception; > use Test::MockModule; > > use t::lib::TestBuilder; > >+use Koha::ActionLogs; >+use Koha::Holds; > use Koha::Libraries; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >+subtest 'fill() tests' => sub { >+ >+ plan tests => 11; >+ >+ $schema->storage->txn_begin; >+ >+ my $fee = 15; >+ >+ my $category = $builder->build_object( >+ { >+ class => 'Koha::Patron::Categories', >+ value => { reservefee => $fee } >+ } >+ ); >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $category->id } >+ } >+ ); >+ my $manager = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ my $title = 'Do what you want'; >+ my $biblio = $builder->build_sample_biblio( { title => $title } ); >+ my $item = $builder->build_sample_item( { biblionumber => $biblio->id } ); >+ my $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ borrowernumber => $patron->id, >+ itemnumber => $item->id, >+ priority => 10, >+ } >+ } >+ ); >+ >+ t::lib::Mocks::mock_preference( 'HoldFeeMode', 'any_time_is_collected' ); >+ t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); >+ t::lib::Mocks::mock_userenv( >+ { patron => $manager, branchcode => $manager->branchcode } ); >+ >+ my $interface = 'api'; >+ C4::Context->interface($interface); >+ >+ my $ret = $hold->fill; >+ >+ is( ref($ret), 'Koha::Hold', '->fill returns the object type' ); >+ is( $ret->id, $hold->id, '->fill returns the object' ); >+ >+ is( Koha::Holds->find($hold->id), undef, 'Hold no longer current' ); >+ my $old_hold = Koha::Old::Holds->find( $hold->id ); >+ >+ is( $old_hold->id, $hold->id, 'reserve_id retained' ); >+ is( $old_hold->priority, 0, 'priority set to 0' ); >+ is( $old_hold->found, 'F', 'found set to F' ); >+ >+ subtest 'fee applied tests' => sub { >+ >+ plan tests => 9; >+ >+ my $account = $patron->account; >+ is( $account->balance, $fee, 'Charge applied correctly' ); >+ >+ my $debits = $account->outstanding_debits; >+ is( $debits->count, 1, 'Only one fee charged' ); >+ >+ my $fee_debit = $debits->next; >+ is( $fee_debit->amount * 1, $fee, 'Fee amount stored correctly' ); >+ is( $fee_debit->description, $title, >+ 'Fee description stored correctly' ); >+ is( $fee_debit->manager_id, $manager->id, >+ 'Fee manager_id stored correctly' ); >+ is( $fee_debit->branchcode, $manager->branchcode, >+ 'Fee branchcode stored correctly' ); >+ is( $fee_debit->interface, $interface, >+ 'Fee interface stored correctly' ); >+ is( $fee_debit->debit_type_code, >+ 'RESERVE', 'Fee debit_type_code stored correctly' ); >+ is( $fee_debit->itemnumber, $item->id, >+ 'Fee itemnumber stored correctly' ); >+ }; >+ >+ my $logs = Koha::ActionLogs->search( >+ { >+ action => 'FILL', >+ module => 'HOLDS', >+ object => $hold->id >+ } >+ ); >+ >+ is( $logs->count, 1, '1 log line added' ); >+ >+ # Set HoldFeeMode to something other than any_time_is_collected >+ t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' ); >+ # Disable logging >+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); >+ >+ $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ borrowernumber => $patron->id, >+ itemnumber => $item->id, >+ priority => 10, >+ } >+ } >+ ); >+ >+ $hold->fill; >+ >+ my $account = $patron->account; >+ is( $account->balance, $fee, 'No new charge applied' ); >+ >+ my $debits = $account->outstanding_debits; >+ is( $debits->count, 1, 'Only one fee charged, because of HoldFeeMode' ); >+ >+ $logs = Koha::ActionLogs->search( >+ { >+ action => 'FILL', >+ module => 'HOLDS', >+ object => $hold->id >+ } >+ ); >+ >+ is( $logs->count, 0, 'HoldsLog disabled, no logs added' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'patron() tests' => sub { > > plan tests => 2; >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29869
:
129395
|
129396
|
129397
|
129398
|
129400
|
129405
|
129406
|
129407
|
129408
|
129409
|
129417
|
129418
|
129419
|
129420
|
129421
|
129502
|
129503
|
129504
|
129505
|
129506
|
129507