From be74523028da2d1f931878c5c477daee4c405cfa Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 17 Apr 2026 14:44:48 +0100 Subject: [PATCH] Bug 41728: (QA follow-up) Move Availability::Result to Result::Availability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Tomás Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Pedro Amorim --- Koha/Item.pm | 2 +- Koha/Item/Checkin/Availability.pm | 6 ++-- .../Result.pm => Result/Availability.pm} | 8 +++--- .../Result.t => Result/Availability.t} | 28 +++++++++---------- .../Koha/Item/Checkin/Availability.t | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) rename Koha/{Availability/Result.pm => Result/Availability.pm} (95%) rename t/Koha/{Availability/Result.t => Result/Availability.t} (81%) diff --git a/Koha/Item.pm b/Koha/Item.pm index df6c18c2f3..4e89098b88 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -874,7 +874,7 @@ Parameters: to_library => branchcode where the item should be sent after return (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 needs_confirmation()# Boolean: true if confirmation required blockers() # Hashref of blocking conditions diff --git a/Koha/Item/Checkin/Availability.pm b/Koha/Item/Checkin/Availability.pm index 0768435946..1b314b433a 100644 --- a/Koha/Item/Checkin/Availability.pm +++ b/Koha/Item/Checkin/Availability.pm @@ -20,7 +20,7 @@ package Koha::Item::Checkin::Availability; use Modern::Perl; use C4::Context; -use Koha::Availability::Result; +use Koha::Result::Availability; =head1 NAME @@ -89,7 +89,7 @@ Parameters: on first blocker). This follows the same pattern 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 confirmations => {} # Conditions requiring confirmation warnings => {} # Informational messages @@ -107,7 +107,7 @@ sub check { my $to_library = $params->{to_library}; 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 # even when blockers prevent the check-in diff --git a/Koha/Availability/Result.pm b/Koha/Result/Availability.pm similarity index 95% rename from Koha/Availability/Result.pm rename to Koha/Result/Availability.pm index 8c48049a3c..d2a13f0609 100644 --- a/Koha/Availability/Result.pm +++ b/Koha/Result/Availability.pm @@ -1,4 +1,4 @@ -package Koha::Availability::Result; +package Koha::Result::Availability; # Copyright 2026 Koha Development Team # @@ -21,11 +21,11 @@ use Modern::Perl; =head1 NAME -Koha::Availability::Result - Base class for availability check results +Koha::Result::Availability - Base class for availability check results =head1 SYNOPSIS - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); $result->add_blocker( BadBarcode => $barcode ); $result->add_confirmation( NotIssued => $barcode ); @@ -51,7 +51,7 @@ Results are categorized into: =head3 new - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); Constructor. Creates a new result object with empty blockers, confirmations, and warnings. diff --git a/t/Koha/Availability/Result.t b/t/Koha/Result/Availability.t similarity index 81% rename from t/Koha/Availability/Result.t rename to t/Koha/Result/Availability.t index 2d3059f356..51a8b7d502 100755 --- a/t/Koha/Availability/Result.t +++ b/t/Koha/Result/Availability.t @@ -22,15 +22,15 @@ use Modern::Perl; use Test::More tests => 9; use Test::NoWarnings; -use Koha::Availability::Result; +use Koha::Result::Availability; subtest 'new() creates empty result' => sub { 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->confirmations ), 'HASH', 'confirmations is a hashref' ); is( ref( $result->warnings ), 'HASH', 'warnings is a hashref' ); @@ -41,53 +41,53 @@ subtest 'add_blocker()' => sub { plan tests => 3; - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); $result->add_blocker( test_blocker => 'value' ); is( $result->blockers->{test_blocker}, 'value', 'blocker added' ); 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 { plan tests => 3; - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); $result->add_confirmation( test_confirm => 'value' ); is( $result->confirmations->{test_confirm}, 'value', 'confirmation added' ); 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 { plan tests => 3; - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); $result->add_warning( test_warning => 'value' ); is( $result->warnings->{test_warning}, 'value', 'warning added' ); 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 { plan tests => 3; - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); $result->set_context( item => 'test_item' ); is( $result->context->{item}, 'test_item', 'context value set' ); is( keys %{ $result->context }, 1, 'one context value present' ); isa_ok( - $result->set_context( patron => 'test_patron' ), 'Koha::Availability::Result', + $result->set_context( patron => 'test_patron' ), 'Koha::Result::Availability', 'returns self for chaining' ); }; @@ -96,7 +96,7 @@ subtest 'available()' => sub { plan tests => 2; - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); ok( $result->available, 'available when no blockers' ); @@ -109,7 +109,7 @@ subtest 'needs_confirmation()' => sub { plan tests => 2; - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); ok( !$result->needs_confirmation, 'no confirmation needed when empty' ); @@ -122,7 +122,7 @@ subtest 'to_hashref()' => sub { plan tests => 6; - my $result = Koha::Availability::Result->new(); + my $result = Koha::Result::Availability->new(); $result->add_blocker( blocker1 => 'b1' ); $result->add_confirmation( confirm1 => 'c1' ); diff --git a/t/db_dependent/Koha/Item/Checkin/Availability.t b/t/db_dependent/Koha/Item/Checkin/Availability.t index fdb3996e50..03d0c4feef 100755 --- a/t/db_dependent/Koha/Item/Checkin/Availability.t +++ b/t/db_dependent/Koha/Item/Checkin/Availability.t @@ -47,7 +47,7 @@ subtest 'check() - item exists' => sub { 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' ); $schema->storage->txn_rollback;