Bug 41728: (QA follow-up) Move Availability::Result to Result::Availability

Consolidate result base classes under the Koha::Result::* namespace
alongside the existing Koha::Result::Boolean. This keeps return-value
wrappers discoverable in one place and avoids a lone Koha::Availability::
namespace that would otherwise host a single base class.

Renames:
  Koha::Availability::Result -> Koha::Result::Availability
  Koha/Availability/Result.pm -> Koha/Result/Availability.pm
  t/Koha/Availability/Result.t -> t/Koha/Result/Availability.t

Call sites in Koha::Item, Koha::Item::Checkin::Availability, and the
test files are updated accordingly.

Test plan:
  prove t/Koha/Result/Availability.t
  prove t/db_dependent/Koha/Item/Checkin/Availability.t

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-04-17 14:44:48 +01:00 committed by Pedro Amorim
parent dece71cb3e
commit be74523028
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
5 changed files with 23 additions and 23 deletions

View File

@ -874,7 +874,7 @@ Parameters:
to_library => branchcode where the item should be sent after return to_library => branchcode where the item should be sent after return
(optional, for transfer limit validation) (optional, for transfer limit validation)
Returns a Koha::Availability::Result object with methods: Returns a Koha::Result::Availability object with methods:
available() # Boolean: true if check-in allowed available() # Boolean: true if check-in allowed
needs_confirmation()# Boolean: true if confirmation required needs_confirmation()# Boolean: true if confirmation required
blockers() # Hashref of blocking conditions blockers() # Hashref of blocking conditions

View File

@ -20,7 +20,7 @@ package Koha::Item::Checkin::Availability;
use Modern::Perl; use Modern::Perl;
use C4::Context; use C4::Context;
use Koha::Availability::Result; use Koha::Result::Availability;
=head1 NAME =head1 NAME
@ -89,7 +89,7 @@ Parameters:
on first blocker). This follows the same pattern on first blocker). This follows the same pattern
as Koha::Patron->can_place_holds. as Koha::Patron->can_place_holds.
Returns a Koha::Availability::Result object with: Returns a Koha::Result::Availability object with:
blockers => {} # Conditions that prevent check-in blockers => {} # Conditions that prevent check-in
confirmations => {} # Conditions requiring confirmation confirmations => {} # Conditions requiring confirmation
warnings => {} # Informational messages warnings => {} # Informational messages
@ -107,7 +107,7 @@ sub check {
my $to_library = $params->{to_library}; my $to_library = $params->{to_library};
my $no_short_circuit = $params->{no_short_circuit} // 0; my $no_short_circuit = $params->{no_short_circuit} // 0;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
# Always check checkout status first so context is available to callers # Always check checkout status first so context is available to callers
# even when blockers prevent the check-in # even when blockers prevent the check-in

View File

@ -1,4 +1,4 @@
package Koha::Availability::Result; package Koha::Result::Availability;
# Copyright 2026 Koha Development Team # Copyright 2026 Koha Development Team
# #
@ -21,11 +21,11 @@ use Modern::Perl;
=head1 NAME =head1 NAME
Koha::Availability::Result - Base class for availability check results Koha::Result::Availability - Base class for availability check results
=head1 SYNOPSIS =head1 SYNOPSIS
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
$result->add_blocker( BadBarcode => $barcode ); $result->add_blocker( BadBarcode => $barcode );
$result->add_confirmation( NotIssued => $barcode ); $result->add_confirmation( NotIssued => $barcode );
@ -51,7 +51,7 @@ Results are categorized into:
=head3 new =head3 new
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
Constructor. Creates a new result object with empty blockers, confirmations, Constructor. Creates a new result object with empty blockers, confirmations,
and warnings. and warnings.

View File

@ -22,15 +22,15 @@ use Modern::Perl;
use Test::More tests => 9; use Test::More tests => 9;
use Test::NoWarnings; use Test::NoWarnings;
use Koha::Availability::Result; use Koha::Result::Availability;
subtest 'new() creates empty result' => sub { subtest 'new() creates empty result' => sub {
plan tests => 5; plan tests => 5;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
isa_ok( $result, 'Koha::Availability::Result', 'new() returns Result object' ); isa_ok( $result, 'Koha::Result::Availability', 'new() returns Result object' );
is( ref( $result->blockers ), 'HASH', 'blockers is a hashref' ); is( ref( $result->blockers ), 'HASH', 'blockers is a hashref' );
is( ref( $result->confirmations ), 'HASH', 'confirmations is a hashref' ); is( ref( $result->confirmations ), 'HASH', 'confirmations is a hashref' );
is( ref( $result->warnings ), 'HASH', 'warnings is a hashref' ); is( ref( $result->warnings ), 'HASH', 'warnings is a hashref' );
@ -41,53 +41,53 @@ subtest 'add_blocker()' => sub {
plan tests => 3; plan tests => 3;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
$result->add_blocker( test_blocker => 'value' ); $result->add_blocker( test_blocker => 'value' );
is( $result->blockers->{test_blocker}, 'value', 'blocker added' ); is( $result->blockers->{test_blocker}, 'value', 'blocker added' );
is( keys %{ $result->blockers }, 1, 'one blocker present' ); is( keys %{ $result->blockers }, 1, 'one blocker present' );
isa_ok( $result->add_blocker( another => 1 ), 'Koha::Availability::Result', 'returns self for chaining' ); isa_ok( $result->add_blocker( another => 1 ), 'Koha::Result::Availability', 'returns self for chaining' );
}; };
subtest 'add_confirmation()' => sub { subtest 'add_confirmation()' => sub {
plan tests => 3; plan tests => 3;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
$result->add_confirmation( test_confirm => 'value' ); $result->add_confirmation( test_confirm => 'value' );
is( $result->confirmations->{test_confirm}, 'value', 'confirmation added' ); is( $result->confirmations->{test_confirm}, 'value', 'confirmation added' );
is( keys %{ $result->confirmations }, 1, 'one confirmation present' ); is( keys %{ $result->confirmations }, 1, 'one confirmation present' );
isa_ok( $result->add_confirmation( another => 1 ), 'Koha::Availability::Result', 'returns self for chaining' ); isa_ok( $result->add_confirmation( another => 1 ), 'Koha::Result::Availability', 'returns self for chaining' );
}; };
subtest 'add_warning()' => sub { subtest 'add_warning()' => sub {
plan tests => 3; plan tests => 3;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
$result->add_warning( test_warning => 'value' ); $result->add_warning( test_warning => 'value' );
is( $result->warnings->{test_warning}, 'value', 'warning added' ); is( $result->warnings->{test_warning}, 'value', 'warning added' );
is( keys %{ $result->warnings }, 1, 'one warning present' ); is( keys %{ $result->warnings }, 1, 'one warning present' );
isa_ok( $result->add_warning( another => 1 ), 'Koha::Availability::Result', 'returns self for chaining' ); isa_ok( $result->add_warning( another => 1 ), 'Koha::Result::Availability', 'returns self for chaining' );
}; };
subtest 'set_context()' => sub { subtest 'set_context()' => sub {
plan tests => 3; plan tests => 3;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
$result->set_context( item => 'test_item' ); $result->set_context( item => 'test_item' );
is( $result->context->{item}, 'test_item', 'context value set' ); is( $result->context->{item}, 'test_item', 'context value set' );
is( keys %{ $result->context }, 1, 'one context value present' ); is( keys %{ $result->context }, 1, 'one context value present' );
isa_ok( isa_ok(
$result->set_context( patron => 'test_patron' ), 'Koha::Availability::Result', $result->set_context( patron => 'test_patron' ), 'Koha::Result::Availability',
'returns self for chaining' 'returns self for chaining'
); );
}; };
@ -96,7 +96,7 @@ subtest 'available()' => sub {
plan tests => 2; plan tests => 2;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
ok( $result->available, 'available when no blockers' ); ok( $result->available, 'available when no blockers' );
@ -109,7 +109,7 @@ subtest 'needs_confirmation()' => sub {
plan tests => 2; plan tests => 2;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
ok( !$result->needs_confirmation, 'no confirmation needed when empty' ); ok( !$result->needs_confirmation, 'no confirmation needed when empty' );
@ -122,7 +122,7 @@ subtest 'to_hashref()' => sub {
plan tests => 6; plan tests => 6;
my $result = Koha::Availability::Result->new(); my $result = Koha::Result::Availability->new();
$result->add_blocker( blocker1 => 'b1' ); $result->add_blocker( blocker1 => 'b1' );
$result->add_confirmation( confirm1 => 'c1' ); $result->add_confirmation( confirm1 => 'c1' );

View File

@ -47,7 +47,7 @@ subtest 'check() - item exists' => sub {
my $result = $item->checkin_availability( { library => $library->branchcode } ); my $result = $item->checkin_availability( { library => $library->branchcode } );
isa_ok( $result, 'Koha::Availability::Result', 'Returns Result object' ); isa_ok( $result, 'Koha::Result::Availability', 'Returns Result object' );
ok( $result->available, 'Item is available for check-in' ); ok( $result->available, 'Item is available for check-in' );
$schema->storage->txn_rollback; $schema->storage->txn_rollback;