Bugzilla – Attachment 166004 Details for
Bug 22740
Automatically change lost status when item is paid for
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22740: Write unit tests for automatic lost status switching
Bug-22740-Write-unit-tests-for-automatic-lost-stat.patch (text/plain), 9.11 KB, created by
Martin Renvoize (ashimema)
on 2024-05-01 15:31:40 UTC
(
hide
)
Description:
Bug 22740: Write unit tests for automatic lost status switching
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-05-01 15:31:40 UTC
Size:
9.11 KB
patch
obsolete
>From 2be73e1bc3b856b85840ef5b9185ac95f2930366 Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <jacob.omara@ptfs-europe.com> >Date: Mon, 8 Apr 2024 09:50:37 +0100 >Subject: [PATCH] Bug 22740: Write unit tests for automatic lost status > switching > >This patch adds the unit tests for the new system preferences that will >automatically change an items lost status to an authorised value defined >in these preferences on payment or write off of outstanding balance. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com> >--- > t/db_dependent/Circulation.t | 229 ++++++++++++++++++++++++++++++++++- > 1 file changed, 228 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index 307db1d8a97..d17567d5899 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > use utf8; > >-use Test::More tests => 70; >+use Test::More tests => 73; > use Test::Exception; > use Test::MockModule; > use Test::Deep qw( cmp_deeply ); >@@ -5487,6 +5487,233 @@ subtest 'Do not return on renewal (LOST charge)' => sub { > ); > }; > >+subtest 'Lost status does not change when preferences are set to 0' => sub { >+ plan tests => 2; >+ >+ my $library = $builder->build_object( { class => "Koha::Libraries" } ); >+ my $manager = $builder->build_object( { class => "Koha::Patrons" } ); >+ t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ library => $library->branchcode, >+ replacementprice => 99, >+ itype => $itemtype, >+ itemlost => 1, >+ } >+ ); >+ >+ my $debitCharge = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ debit_type_code => 'LOST', >+ status => undef, >+ itemnumber => $item->itemnumber, >+ amount => 12, >+ amountoutstanding => 12, >+ interface => 'something', >+ } >+ )->store(); >+ >+ # Test for UpdateItemLostStatusWhenPaid >+ t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', 0 ); >+ >+ my $paymentLine = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ credit_type_code => 'CREDIT', >+ status => undef, >+ itemnumber => $item->itemnumber, >+ amountoutstanding => 0 - 12, >+ amount => 0 - 12, >+ interface => 'something', >+ } >+ )->store(); >+ >+ my $offset = Koha::Account::Offset->new( >+ { >+ credit_id => $paymentLine->id, >+ debit_id => $debitCharge->id, >+ type => 'APPLY', >+ amount => 0 >+ } >+ )->store(); >+ >+ $paymentLine->apply( { debits => [$debitCharge] } ); >+ >+ is( >+ Koha::Items->find( $item->itemnumber )->itemlost, 1, >+ "Payment should not change itemlost status when UpdateItemLostStatusWhenPaid is 0" >+ ); >+ >+ # Test for UpdateItemLostStatusWhenWriteOff >+ t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenWriteOff', 0 ); >+ >+ my $writeOffLine = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ credit_type_code => 'WRITEOFF', >+ status => undef, >+ itemnumber => $item->itemnumber, >+ amountoutstanding => 0 - 12, >+ amount => 0 - 12, >+ interface => 'something', >+ } >+ )->store(); >+ >+ $offset = Koha::Account::Offset->new( >+ { >+ credit_id => $writeOffLine->id, >+ debit_id => $debitCharge->id, >+ type => 'APPLY', >+ amount => 0 >+ } >+ )->store(); >+ >+ $writeOffLine->apply( { debits => [$debitCharge] } ); >+ >+ is( >+ Koha::Items->find( $item->itemnumber )->itemlost, 1, >+ "Write-off should not change itemlost status when UpdateItemLostStatusWhenWriteOff is 0" >+ ); >+}; >+ >+# Test for UpdateItemLostStatusWhenPaid >+subtest 'Update lost item to authorized value on payment of balance' => sub { >+ plan tests => 5; >+ >+ my $library = $builder->build_object( { class => "Koha::Libraries" } ); >+ my $manager = $builder->build_object( { class => "Koha::Patrons" } ); >+ t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ for my $status ( 2 .. 6 ) { >+ t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', $status ); >+ >+ my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ library => $library->branchcode, >+ replacementprice => 99, >+ itype => $itemtype, >+ itemlost => 1, >+ } >+ ); >+ >+ my $debitCharge = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ debit_type_code => 'LOST', >+ status => undef, >+ itemnumber => $item->itemnumber, >+ amount => 12, >+ amountoutstanding => 12, >+ interface => 'something', >+ } >+ )->store(); >+ >+ my $paymentLine = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ credit_type_code => 'CREDIT', >+ status => undef, >+ itemnumber => $item->itemnumber, >+ amountoutstanding => 0 - 12, >+ amount => 0 - 12, >+ interface => 'something', >+ } >+ )->store(); >+ >+ my $offset = Koha::Account::Offset->new( >+ { >+ credit_id => $paymentLine->id, >+ debit_id => $debitCharge->id, >+ type => 'APPLY', >+ amount => 0 >+ } >+ )->store(); >+ >+ $paymentLine->apply( { debits => [$debitCharge] } ); >+ >+ is( >+ Koha::Items->find( $item->itemnumber )->itemlost, $status, >+ "Payment should set itemlost to status $status" >+ ); >+ } >+}; >+ >+# Test for UpdateItemLostStatusWhenWriteOff >+subtest 'Update lost item to authorized value on write-off of balance' => sub { >+ plan tests => 5; >+ >+ my $library = $builder->build_object( { class => "Koha::Libraries" } ); >+ my $manager = $builder->build_object( { class => "Koha::Patrons" } ); >+ t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ for my $status ( 2 .. 6 ) { >+ t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenWriteOff', $status ); >+ >+ my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ library => $library->branchcode, >+ replacementprice => 99, >+ itype => $itemtype, >+ itemlost => 1, >+ } >+ ); >+ >+ my $debitCharge = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ debit_type_code => 'LOST', >+ status => undef, >+ itemnumber => $item->itemnumber, >+ amount => 12, >+ amountoutstanding => 12, >+ interface => 'something', >+ } >+ )->store(); >+ >+ my $writeOffLine = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ credit_type_code => 'WRITEOFF', >+ status => undef, >+ itemnumber => $item->itemnumber, >+ amountoutstanding => 0 - 12, >+ amount => 0 - 12, >+ interface => 'something', >+ } >+ )->store(); >+ >+ my $offset = Koha::Account::Offset->new( >+ { >+ credit_id => $writeOffLine->id, >+ debit_id => $debitCharge->id, >+ type => 'APPLY', >+ amount => 0 >+ } >+ )->store(); >+ >+ $writeOffLine->apply( { debits => [$debitCharge] } ); >+ >+ is( >+ Koha::Items->find( $item->itemnumber )->itemlost, $status, >+ "Write-off should set itemlost to status $status" >+ ); >+ } >+}; >+ > subtest 'Filling a hold should cancel existing transfer' => sub { > plan tests => 4; > >-- >2.44.0
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 22740
:
165906
|
165907
|
165932
|
165933
|
165973
|
165974
|
166003
|
166004
|
166010
|
166011