Bugzilla – Attachment 160044 Details for
Bug 28530
Allow configuration of floating limits by item type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28530: Add unit tests
Bug-28530-Add-unit-tests.patch (text/plain), 8.11 KB, created by
Kyle M Hall (khall)
on 2023-12-19 16:51:20 UTC
(
hide
)
Description:
Bug 28530: Add unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2023-12-19 16:51:20 UTC
Size:
8.11 KB
patch
obsolete
>From b35a47795a5dfd1bfe941b7ee9b1a9368de59d23 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Mon, 18 Dec 2023 14:23:25 -0500 >Subject: [PATCH] Bug 28530: Add unit tests > >--- > t/db_dependent/Circulation/Returns.t | 89 ++++++++++++++- > t/db_dependent/Koha/Library/FloatLimits.t | 133 ++++++++++++++++++++++ > 2 files changed, 221 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Koha/Library/FloatLimits.t > >diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t >index db25fda549f..48c19e9d9e8 100755 >--- a/t/db_dependent/Circulation/Returns.t >+++ b/t/db_dependent/Circulation/Returns.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > use Test::MockModule; > use Test::Warn; > >@@ -375,4 +375,91 @@ subtest 'Backdated returns should reduce fine if needed' => sub { > is( $fine, undef, "Fine was removed correctly with a backdated return" ); > }; > >+subtest 'Test library float limits' => sub { >+ plan tests => 2; >+ >+ my $library1 = $builder->build( { source => 'Branch' } ); >+ my $library2 = $builder->build( { source => 'Branch' } ); >+ my $library3 = $builder->build( { source => 'Branch' } ); >+ my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } ); >+ >+ my $biblio = $builder->build_sample_biblio(); >+ >+ for ( 1 .. 5 ) { >+ $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library1->{branchcode}, >+ holdingbranch => $library1->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+ } >+ >+ for ( 1 .. 10 ) { >+ $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library2->{branchcode}, >+ holdingbranch => $library2->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+ } >+ >+ for ( 1 .. 15 ) { >+ $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library3->{branchcode}, >+ holdingbranch => $library3->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+ } >+ >+ my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library1->{branchcode}, >+ holdingbranch => $library1->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+ >+ my $limit1 = Koha::Library::FloatLimit->new( >+ { >+ branchcode => $library1->{branchcode}, >+ itemtype => $itemtype->itemtype, >+ limit => 1, >+ } >+ )->store(); >+ >+ my $limit2 = Koha::Library::FloatLimit->new( >+ { >+ branchcode => $library2->{branchcode}, >+ itemtype => $itemtype->itemtype, >+ limit => 100, >+ } >+ )->store(); >+ >+ my $limit3 = Koha::Library::FloatLimit->new( >+ { >+ branchcode => $library3->{branchcode}, >+ itemtype => $itemtype->itemtype, >+ limit => 1000, >+ } >+ )->store(); >+ >+ t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '0' ); >+ >+ my ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch ); >+ is( $messages->{TransferTrigger}, undef, "Library float limit not triggered if syspref is not enabled" ); >+ >+ t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '1' ); >+ >+ ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch ); >+ is( $messages->{TransferTrigger}, 'LibraryFloatLimit', "Library float limit is triggered if syspref is enabled" ); >+}; >+ > $schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Library/FloatLimits.t b/t/db_dependent/Koha/Library/FloatLimits.t >new file mode 100755 >index 00000000000..fa8af003ae0 >--- /dev/null >+++ b/t/db_dependent/Koha/Library/FloatLimits.t >@@ -0,0 +1,133 @@ >+#!/usr/bin/perl >+ >+# Copyright 2023 ByWater Solutions >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 5; >+ >+use Koha::Database; >+use C4::Circulation qw(CreateBranchTransferLimit); >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+BEGIN { >+ use_ok('Koha::Library::FloatLimit'); >+ use_ok('Koha::Library::FloatLimits'); >+} >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+my $library1 = $builder->build( { source => 'Branch' } ); >+my $library2 = $builder->build( { source => 'Branch' } ); >+my $library3 = $builder->build( { source => 'Branch' } ); >+my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } ); >+ >+my $biblio = $builder->build_sample_biblio(); >+ >+for ( 1 .. 5 ) { >+ $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library1->{branchcode}, >+ holdingbranch => $library1->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+} >+ >+for ( 1 .. 10 ) { >+ $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library2->{branchcode}, >+ holdingbranch => $library2->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+} >+ >+for ( 1 .. 15 ) { >+ $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library3->{branchcode}, >+ holdingbranch => $library3->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+} >+ >+my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library1->{branchcode}, >+ holdingbranch => $library1->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+); >+ >+my $limit1 = Koha::Library::FloatLimit->new( >+ { >+ branchcode => $library1->{branchcode}, >+ itemtype => $itemtype->itemtype, >+ limit => 1, >+ } >+)->store(); >+ >+my $limit2 = Koha::Library::FloatLimit->new( >+ { >+ branchcode => $library2->{branchcode}, >+ itemtype => $itemtype->itemtype, >+ limit => 100, >+ } >+)->store(); >+ >+my $limit3 = Koha::Library::FloatLimit->new( >+ { >+ branchcode => $library3->{branchcode}, >+ itemtype => $itemtype->itemtype, >+ limit => 1000, >+ } >+)->store(); >+ >+is( >+ Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library3->{branchcode}, >+ "Correct library selected for float limit transfer" >+); >+ >+t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); >+t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); >+ >+my $to = $library3->{branchcode}; >+my $from = $item->holdingbranch; >+my $code = $itemtype->itemtype; >+CreateBranchTransferLimit( $to, $from, $code ); >+ >+is( C4::Circulation::IsBranchTransferAllowed( $to, $from, $code ), 0, "Transfer to best library is no longer allowed" ); >+say "C4::Circulation::IsBranchTransferAllowed( $to, $from, $code )"; >+ >+is( >+ Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library2->{branchcode}, >+ "Correct library selected for float limit transfer when best cannot be used" >+); >+ >+$schema->storage->txn_rollback; >-- >2.30.2
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 28530
:
160038
|
160039
|
160040
|
160041
|
160042
|
160043
|
160044
|
160045
|
160046
|
160047
|
160048
|
160049
|
160050
|
160053
|
160054
|
160055
|
160056
|
160057
|
160058
|
160061
|
160062
|
160063
|
160064
|
160065
|
160066
|
160067
|
160068
|
160071
|
160072
|
160073
|
160074
|
160075
|
160076
|
160077
|
160078
|
160079
|
160080
|
160081
|
160082
|
160083
|
160084
|
163919
|
168343
|
168344
|
168345
|
168346
|
168347
|
168348
|
168349
|
168350